Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Prices in Pipeline, or data.history different than prices in Yahoo Finance

I have read other posts of many people with this issue, and the main "problem" seems to be that all other platforms (like Yahoo Finance) record the historical close price including the split of dividends of current day, while Quantopian simply records the close price of that day.

Is there a way, via Pipeline, to get exactly the close price I would get if I looked at Yahoo Finance?

3 responses

It's not possible to have pipeline output close prices to match what you would fetch from Yahoo. The issue lies at the heart of what pipeline is designed to do (and not do). Pipeline is designed to surface data to match what an individual would have seen on each pipeline date. The intent is to never allow any lookahead bias in the data. This is true of pricing data by never including future price adjustments, and true of fundamental data by never making it available until when it was actually released to the public.

Yahoo prices are adjusted for splits and, oddly, not dividends as of the actual current day. Only the 'Adj Close' field is adjusted for both. If pipeline were to output prices to match Yahoo then it would need to account for potential 'future' splits and dividends. This lookahead bias is not allowed.

If one wanted to get prices similar to the Yahoo 'Adj Close' prices, use the get_pricing method in a notebook. Simply set the 'end' date to the current 'today' date. Something like this to get close prices for SPY from 1-1-2008.

today = datetime.now()  
spy_prices = get_pricing('SPY', start_date='1-1-2008', end_date=today, fields='close_price')

There still may be a discrepancy in prices however. Quantopian uses the last traded price as the close price for a security. Yahoo uses end-of-day (EOD) prices which include the final auction orders. These auction orders are not technically 'market' orders and are not included in Quantopian's prices. There is a little more info about this in the FAQ and in this post

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.

Dan you answer makes a lot of sense, thank you for the details!

I just noticed that when I run the below code on a notebook and compare the results in Yahoo Finance
the close price on May 5th (in Pipeline) is equal to the close price on May 4th (in yahoo Finance)
and
the close price on May 4th (in Pipeline) is equal to the close price on May 1st (in yahoo Finance)

Why is this happening?
I am guessing it is because it checks the price at hour 0 of the day, is there way to set a specific time of the day in Pipeline?

MY_STOCK = symbols('AAPL')

my_pipe=make_pipeline()  
results=run_pipeline(my_pipe, '2020-05-04', '2020-05-05')  

def make_pipeline():  
    # Selecting universe to screen  
    universe = Filters.StaticAssets( [MY_STOCK] )  
    obj = {}  

    obj['close_price'] = USEquityPricing.close.latest  
    # create Pipeline  
    pipe = Pipeline(  
        columns=obj,  
        screen=universe  
    )  
    return pipe