Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Different data in pipeline and data.history

I noticed some differences between data fetched in pipeline and data from data.history.
The attached backtest plots the daily closing price for SPY as USEquityPricing.close.latest and as data.history(symbol('SPY'), 'close', 252, '1d').
Most notably in this period is August 10, 2011 - 113.49 vs 117.47
That's quite a gap, can someone explain where these discrepancies come from?
Sometimes it looks like pipeline is one day behind history. If that's the case, is there a way to get more recent data in pipeline?

2 responses

Both pipeline and data.history get their values from the same data source on Quantopian. They will always be the same. The discrepancy you are seeing is because of how the data.history method works.

Pipeline will always return data as of the current day before markets open. The close price will always be the previous day's close price. There is no way to change that and get more recent data via pipeline.

The data.history and similar methods include the current days open, high, low, close and cumulative volume. The last values for these (eg high[-1] ) are the current days values as of the minute the method was called. So what does this mean?

open: this is the days open price and will be constant throughout the day
high: the days high as of the last minute
low: the days low as of the last minute
close: the close price as of the last minute. This will update every minute and is the same as the data.current close price
volume: cumulative volume for the day

The second from the last values, when fetching daily data, (eg high[-2] ) will be yesterday's values and will match pipeline.

Attached is the same algo but instead of referencing data.history(symbol('SPY'), 'close', 252, '1d').iloc[-1] it references data.history(symbol('SPY'), 'close', 252, '1d').iloc[-2]. It now matches the pipeline data.

Disclaimer

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.

Thanks for clarifying!