Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Backtest results showing a pricing problem?

Hi everyone,

I can't manage to understand why profits & losses are not correlated with stock's price (VXX ETF). The rule of the algo is very basic and for learning purpose (actually learning python) :

Enter LONG when VXX price < $13
Sell all of our shares if VXX price > $35

The thing is, VXX is making some huge up spikes and the algo is designed to profit from them. But, while the algo BUYs relatively low and SELL just after spikes, results are only showing losses. The issue may be a pricing error of the ETF because when looking at the VXX price on Yahoo, the chart is really different from the recorded VXX chart (record function that using VXX current price as data). Also, when testing the same logic with AAPL, the algo works perfectly.

Would be nice to hear your thoughts.

2 responses

It's generally a bad idea to put absolute price (or volume) data in ones algorithm. Not always bad, but your algorithm highlights a major reason not to - stock splits. VXX is a textbook case.

The algorithm chooses absolute price points to open ($13) and close ($35) a position of VXX. The algorithm runs between 9/20/2011 - 1/28/2018. The problem is there were four 1:4 reverse splits during that time (10/05/2012, 11/08/2013, 08/09/2016, 08/23/2017). Those splits show up on the custom data chart in the algorithm as 4x 'spikes' in the price. However, those 'spikes' also correspond to a 1/4 adjustment to shares held. When the algorithm sells at $35 (believing a big profit) its really selling at a loss because the shares got reduced by 1/4 in the reverse split.

This can be seen in the algorithm 'Transactions Detail' tab. On 7/17/2012 there were 15 shares bought at $12.72. After the stock split on 10/5/2012, there were 3 shares (15 / 4 = 3 because one can't trade fractional shares). Those 3 shares were sold a few days later on 10/9/2012 for $35.96. While it seems like selling above $35 would result in a gain, the shares were actually sold at a loss. The initial value was $190.80 (15 x $12.72) but then sold for $107.88 (3 x $35.96) for a loss of $82.92 (excluding commission costs). This is a little misleading because of the rounding down of the shares but it illustrates the point.

The reason Yahoo prices look so different is that they are 'adjusted' to todays dollars. The prices being displayed in the custom data are actual (unadjusted) prices that one would have seen on a specific trading day. Hope that helps.

Hi Dan,

Thank you very much for this clarification, it definitely helps. What I can learn from this is to always check if custom data is adjusted to the asset's real situation and avoid to put the absolute price in my algorithms.