Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why is there a day 1 difference between this algorithm and the benchmark?

I'm trying to make an algorithm identical to the benchmark for aapl. Why are they different?

3 responses

Maybe try zeroing out slippage and commission?

It is not due to the commissions or slippage. I cloned the algo, and calculated the average fill price, and then computed the cumulative return myself (see the attached notebook). I compared this to what is shown in the backtest performance chart. It looks like the backtest performance chart dates are offset by -1 day for some reason. Basically, it is showing the 8/1/11 algo return as occurring on 7/31/11. It might be a bug.

The benchmark and algo dates on the algo returns graph are both shifted one day. This is in my mind a bug but the only place it shows up is on the graph so it's of little real consequence. The returns listed for day n are really the returns for day n+1. This is perhaps obvious since the dates on the graph are from Sunday to Thursday while the data should be from Monday to Friday.

This is also the behavior in the old algo graph so it's been around awhile.

I wasn't able to follow the notebook, however, a portfolio will rarely match exactly with a benchmark. The benchmark compares all the gains with the close from the previous day. So in the case of AAPL starting on Monday 8-1-2011, the benchmark returns would look like this (the second column is the close price and the last column is the total gain from 7-29)

2011-07-29 00:00:00+00:00   390.692 0.000000  
2011-08-01 00:00:00+00:00   396.740 0.015480  
2011-08-02 00:00:00+00:00   388.920 -0.004536  
2011-08-03 00:00:00+00:00   392.570 0.004807  
2011-08-04 00:00:00+00:00   377.350 -0.034150

Here's the same data for the algo. (the second column is the portfolio value and the last column is the total gain from the initial portfolio value of $1,000,000)

2011-07-29 00:00:00+00:00   1000000  
2011-08-01 00:00:00+00:00   995670.411  -0.004330  
2011-08-02 00:00:00+00:00   976065.671  -0.023934  
2011-08-03 00:00:00+00:00   985216.221  -0.014784  
2011-08-04 00:00:00+00:00   947059.681  -0.052940  
2011-08-05 00:00:00+00:00   938034.481  -0.061966

Unless one can open a position at the close price of the previous day the benchmark and the algo will forever be off. In this case, the algo bought in at $398.47. The previous close was less than that and therefore the initial loss (whereas the benchmark showed an initial gain)