Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Discrepancy in price data between backtest and research

Hi,

I was looking more closely at the details of the transactions of one of my algorithms, and I seem to find some discrepancies between the prices in the backtest and the prices obtained via the function get_prices() in the research environment. I take as an example the security 20208 (NASDAQ:FFIV). The algorithm whose backtest is attached just buys the stock at the open and sells it at the close, so that we can see what prices the backtest is using. In the attached notebook below, we see that the prices in the backtest transactions are around 60$, but the prices obtained from the get_prices() function are around 30$.

Comparing with the publicly available data, for instance Google Finance:
https://www.google.com/finance?chdnp=1&chdd=1&chds=1&chdv=1&chvs=maximized&chdeh=0&chfdeh=0&chdet=1481922000000&chddm=1464282&chls=IntervalBasedLine&q=NASDAQ:FFIV&ntsp=0&ei=9_VaWNHEGIqYsAHr3b_wAQ
we see that for the period of interest, at the beginning of 2006, the price of this stock was around 30$ (adjusted for splits), consistent with the data returned by the get_price function.

  • So why is the backtest using a price of around 60?
  • I can imagine that this is due to some adjustment for stock splitting, as there was indeed a 2 for 1 split in 2007:
    https://www.splithistory.com/ffiv/
  • But then is it intended that the backtest and research data are not consistent?
  • How can I get price data consistent with the backtest data in the research environment?

Thanks and best regards,

Samuel Monnier

5 responses

And here is the notebook.

Prices and volume are adjusted for stock splits AS OF A SPECIFIC DATE. When backtesting they are adjusted as of the backtest date. When getting history from research it's the current date. When getting historical prices from Yahoo etc the 'as of' date is also the current date. The 'as of' date determines which stock splits to include. The prices will all agree if the 'as of' dates are the same (though sometimes the close prices are off because Quantopian takes the last minute trade prices while other sources may do it differently).

One NEVER wants to include a split that hasn't happened yet to eliminate lookahead bias in a backtest. In research the focus is to ensure one is comparing apples-to-apples. That is probably the main rational for the two being different at times. Take a look through this post for some better clarification https://www.quantopian.com/posts/help-notebook-vs-algorithm . @Jamie McCorriston has a good post towards the end.

If you want to ensure the same prices in both research and an algorithm use pipeline in both (rather than get_pricing in research).

I have found the price and volume data in Quantopian are very reliable as long as the 'as of' date is observed.

Thanks this makes sense.

However, I still have a minor problem. I'm studying the transactions of my algorithm on some day. Is there a way of accessing the open price on this day? From my understanding, the pipeline is run before trading starts, so doesn't have access to the open of the current day. I could run it the next day and ask for the latest open, but then the data would probably not be consistently adjusted on the day before a stock split.

Pipeline only has previous day data (as you noted). Use either the get_current or get_history methods in a scheduled function or in the handle_data function. Those functions have access to current day data.

Sorry, my question wasn't clear. I'm importing transaction data from the backtest into research, and am trying to compare with the open price there. From what you told me so far, it doesn't look like there is a way to get the current day open price without adjustment for future splits. But I guess I could record it in the algorithm and import it along with the transaction data.

Thanks again for your help!