Shell script to calculate daily point totals from CSV

pc

Hello. I made a shell script that takes the Topstep Tradovate Performance CSV report and uses that data to calculate point totals. It’s made on macOS but I imagine it will also work on other Un*x systems.

#!/bin/bash
#pointcalc, Chris Tucker & Myke H., April 2024.
#This program calculates daily points total using a TopStep Tradovate "Performance" account report in comma-seperate values (CSV) file as the data source.

	total=0
	tradeCount=0

#Read column data (f1-13)
	while IFS=',' read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13
	do
		((tradeCount+=1))
		echo "Trade No. $tradeCount: $f8 / $f9"
	delta=$(echo "$f9 - $f8" | bc)
	echo "Delta: $delta"
		total=$(echo "$total + $delta" | bc)
	echo "Running total: $total"
	echo ""

#Use tail command to ignore first line of CSV data, which are just labels.
	done < <(tail -n +2 $1)

If you’re familiar with scripts like this you probably know how to use it. But if you’re not familiar with scripts, here’s instructions. I’ll assume you’re on a Mac for this example.

Select the code above and copy it.
Open Terminal.app. You’ll probably be in your home directory. Let’s switch to the desktop.
Type “cd Desktop” and press return.
Type “vi pointcalc” and return to create and edit a file called pointcalc.
Type “i” (no return)
Press command-v to paste the code into the vi editor.
Press the escape key followed by “:wq” (colon w q) and press return to write the file and quit.
Now you have a file but it is not executable. To make it executable type:
“chmod +x pointcalc” and press return.

You’ll only need to do the above steps one time.

On Tradovate, go to the performance report section and download a “Performance” report in CSV format.

Move this file to the same folder as the executable (the Desktop in this example).

In Terminal.app, type “./pointcalc filename.csv” (period slash pointcalc), where “filename.csv” is whatever your performance csv happens to be named, and press return to run the script.

If all goes well, the script will parse the csv file and print out a running total of points.