0
$\begingroup$

Quick question, I'm having a brain freeze. I've done a simple system to practice array based backtesting. I was able to calculate my PnL by subtracting the "close" from the "buyPrice" and multiplying by 50 (point multiplier for ES) and Number of Contacts (1). Now if I want to add a column and calculate the daily account value starting with say an account of $25,000, what's the best way to do that? I assume I would then add another column using "df.pct_change()" go get the daily returns.

Here is some sample data:

date    open    high    low     close   buyPrice  goLong  long_pnl
                            
9/25/97 1132.2  1135.95 1123.95 1124.95 1144.28   FALSE     0
9/26/97 1124.7  1134.95 1124.7  1131.7  1136.21   FALSE     0
9/29/97 1131.7  1142.95 1128.7  1140.2  1142.26   TRUE     -103
9/30/97 1139.45 1143.7  1131.2  1132.95 1150.27   FALSE     0
10/1/97 1133.95 1144.95 1132.95 1141.95 1143.48   FALSE     0
10/2/97 1141.7  1147.95 1139.45 1147.45 1151.3    FALSE     0
10/3/97 1147.7  1163.95 1140.2  1153.95 1156.76   TRUE     -140.5

And the account value column would look like:

date    open    high    low     close   buyPrice  goLong  long_pnl  **account**
                            
9/25/97 1132.2  1135.95 1123.95 1124.95 1144.28   FALSE     0       25000
9/26/97 1124.7  1134.95 1124.7  1131.7  1136.21   FALSE     0       25000
9/29/97 1131.7  1142.95 1128.7  1140.2  1142.26   TRUE     -103     24897
9/30/97 1139.45 1143.7  1131.2  1132.95 1150.27   FALSE     0       24897
10/1/97 1133.95 1144.95 1132.95 1141.95 1143.48   FALSE     0       24897
10/2/97 1141.7  1147.95 1139.45 1147.45 1151.3    FALSE     0       24897
10/3/97 1147.7  1163.95 1140.2  1153.95 1156.76   TRUE     -140.5   24756.5
$\endgroup$
  • $\begingroup$ If this is for ES, how do you get OHLC prices that aren't multiples of the minimum tick size? $\endgroup$ – user42108 Nov 22 '20 at 23:05
  • $\begingroup$ @user42108 : It's back-adjusted continuous contract data from Pinnacle Data Corp. $\endgroup$ – sslack88 Nov 22 '20 at 23:16
  • $\begingroup$ Prices looked surprisingly neat for back-adjusted - perhaps they're rounded. For your change in account balance, I use the change in futures price and multiplier rather than calculating the % change. $\endgroup$ – user42108 Nov 23 '20 at 1:12
0
$\begingroup$

For anyone who finds this post, I figured out the answer myself. Very easy to do this way. Hope this helps someone else with a brain freeze :)

#Account Value Calculation
df['account'] = start_acct_value + df['long_pnl'].cumsum()

#Calculate Daily Returns
df['returns'] = df['account'].pct_change()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.