Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline showing wrong day's close price

For some reason my pipeline is showing the previous day's close price. For example, for AAPL the pipeline shoes close for 3/11 shows close price for 3/10. Any ideas?

# Build pipeline

# Pipeline class  
from quantopian.pipeline import Pipeline

# Import Pipeline class and USEquityPricing dataset  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline.data import USEquityPricing  
from quantopian.pipeline.filters import StaticSids  
from quantopian.pipeline.experimental import QTradableStocksUS

# Import built-in calculations  
from quantopian.pipeline.factors import SimpleMovingAverage, AnnualizedVolatility, Returns

# Pipeline definition  
def make_pipeline():  
    # Create reference to tradeable universe  
    base_universe = StaticSids([24])  
    # Get latest closing price  
    close_price = USEquityPricing.close.latest  
    # Get latest returns  
    returns = Returns(window_length=2)  
    # Calculate 20 day average closing price  
    sma_20 = SimpleMovingAverage(  
        inputs=[returns],  
        window_length=20)  
    # Calculate upper and lower bands  
    ann_vol = AnnualizedVolatility(  
        inputs=[returns],  
        window_length=20)  
    std_20 = ann_vol ** (1/2)  
    # Calculate Z-Score  
    z_score = (returns - sma_20) / std_20  
    return Pipeline(  
    columns={  
        'close_price': close_price,  
        'returns': returns},  
        screen = base_universe)

# Import run_pipeline method  
from quantopian.research import run_pipeline

# Execute pipeline created by make_pipeline  
# between start_date and end_date  
pipeline_output = run_pipeline(  
    make_pipeline(),  
    start_date='2020-01-01',  
    end_date='2020-03-11'  
)

# Display last 10 rows  
pipeline_output.tail(5)  
1 response

You may be interpreting the output of the pipeline incorrectly? Specifically, pipeline data is as of before the market opens on the day the pipeline is run. For example, if a pipeline output row (ie the level 0 index value) has a date of 2019-10-22, then the 'close' values will be the 'close of the previous trading day 2019-10-21. Is that what you are seeing?

There is a little better explanation of this in this post https://www.quantopian.com/posts/date-is-not-correct-in-the-prices-i-get.

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.