Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Difference between SPY and benchmark

I tried to mimic the benchmark algorithm by executing a simple buy and hold strategy of SPY. The same algorithm is used in this thread: https://www.quantopian.com/posts/backtester-change-updated-benchmark

As explained in the post of the link, there can be differences between both algorithms because it is not possible to buy partial shares of SPY and thereby use up all cash and because the benchmark is fully invested at market open, whereas SPY needs to be bought. So, in the following plot I understand that there is a discrepancy at the start of both algorithms. However, why is the difference suddenly increasing on 12/15/2016?


6 responses

There is no disparagement between the graphs on day one. If there were, literally the first plot on the chart would be different. Here, the benchmark is purchasing the same amount as you at the same time as you are. I believe the issue is that the benchmark only uses intraday equity pricing and the order that you coded for the SPY long includes afterhours changes in value. I bet the graphs would match up if you open your position every morning at the open and exit your position right before the market closes. Quantopian does not include afterhours pricing and volume data, but it seems like, for some reason it dynamical calculates afterhours value change for your investments, but not for the benchmark. Now, I may be wrong about this, but ThinkOrSwim seems to suggest otherwise:
(The grey bars at the bottom of the chart are volume and when the volume bars drop to almost nill, that's when afterhours trading starts.)

-afterhours price increases between the 12th and 13th (accounting your your increase on datapoint #2)
-similar close and open on 14th, 15th and 19th
-significant price drop between 15th and 16th (accounting for your dip in price on the 16th)

Actually, if this is true, then it's a pretty significant issue and Quantopian support need to know about it.

Thanks for the quick response, James. You are absolutely right that this particular example does not show a difference between SPY and benchmark on the first data point. However, when choosing different time spans, you can observe a difference, e.g., when selecting 12/14/2016 to 12/16/2016.

I like your analysis that the difference might stem from different treatment of afterhours changes. However, I implemented your suggestion of opening the position in the morning and closing it in the evening. Every day, it purchases at 9.32am and sells at 4.00pm. Unfortunately, the graphs still don't match up (see below). I am wondering what I miss here.

The discrepancy is all about dividends and when they are recognized. SPY had a $1.329 4th qtr dividend with an ex/eff date of 12/16/2016. The payment date was 1/31/2017. (See https://www.nasdaq.com/symbol/spy/dividend-history)

The benchmark attributes those dividends on the ex date (12/16/2016) while the backtest more realistically doesn't add the cash into ones account until the payment date. Take a look at this same backtest run through 2/02/2017. Notice that the two show a difference after 12/16/2016 but then match up after 1/31/2017.

This was a rather old post but thought it may still be relevant to the community. Hope it helps.


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thank you! I just deleted my reply to this topic as I found another topic describing the difference is in the reinvestment of the dividends. Thanks anyway!

Dividends visible in the custom chart.
Starts out at -1000 though, commissions surely. Or $45 at .999.
Buying just once.