Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Historical stock (ETF) price not accurate for longer time frames

My algorithm was working fine for periods of up to 6 months, but when I expanded the timeframe to 2 years it started getting erroneous stock values. (I would paste an image to illustrate, but apparently this isn't supported.)
Here's google drive share of the image showing the problem:
https://drive.google.com/open?id=1XWGHne-HB2Oc2Yhs90iCWjOLviGfF8U7

For reference, this is what the real stock values are on Yahoo.
Stock values for 6/20/2019 are ~63.64
Stock values for 8/20/2017 are ~34.82

Relevant bits of code:

    context.stocks = [sid(39214)]

    price_history = data.history(context.stocks, fields="price", bar_count=7, frequency="1d")  
    for s in context.stocks:  
        current_price = price_history[s][-1]  
        #for testing stock values  
        log.info("CURRENT STOCK PRICE %s: %.2f HIST_HIGH: %.2f" % (s.symbol, current_price, prev_high_point))  

Log output:
NEWER:
1969-12-31 16:00 initialize:48 INFO Original investment capital: 20000.0
2019-06-20 06:31 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 64.41 HIST_HIGH: 72.64
2019-06-20 06:32 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 64.28 HIST_HIGH: 72.64

OLDER: (incorrect values)
1969-12-31 16:00 initialize:48 INFO Original investment capital: 20000.0
2017-08-21 06:31 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 104.73 HIST_HIGH: 116.35
2017-08-21 06:32 handle_data:74 INFO CURRENT STOCK PRICE TQQQ: 104.70 HIST_HIGH: 116.35

Why would the older stock data be so different? The code is exactly the same, only the date range in the Build Algorithm panel is different. The ETF was operating at that time. Could it possible have doubled at some point?

2 responses

@Jeff Axup I'm going to correct one statement you made...

For reference, this is what the real stock values are on Yahoo.
Stock values for 6/20/2019 are ~63.64
Stock values for 8/20/2017 are ~34.82

That should really be stated...

For reference, this is what the ADJUSTED as of 8-22-2019 stock values are on Yahoo.
Stock values for 6/20/2019 are ~63.64
Stock values for 8/20/2017 are ~34.82

Believe it or not, one would have had to shell out about $104 for a share of TQQQ on 2017-08-21. The reason Yahoo looks different is that they display adjusted prices and factored in the 05/24/2018 3:1 stock split for TQQQ (see https://www.splithistory.com/tqqq/). This is why the adjusted price for dates before 05/24/2018 are 1/3 of the unadjusted price on that day.

There are a number of posts here which may explain this better. Check out https://www.quantopian.com/posts/help-diferent-close-price-for-the-same-date-2 There are also some links there to a few other posts.

Use caution with Yahoo data. Since it's constantly being re-adjusted as of the current date, historical data downloaded six months ago may be different than what is downloaded today. It all depends upon if any relevant corporate actions occurred in the past 6 months. This is one aspect of Quantopian data which is important in research. It can be replicated by specifying the as-of date.

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 Dan, you’re the one-man-answering-machine!
I thought that was a bug, but it seems like it’s normal behavior.
So it sounds like as long as I’m using a pipeline it will auto-adjust for splits, even when doing long hold periods.
Does either the pipeline or the yahoo adjustment account for inflation as well?