Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why are the prices from prices() and USEquityPricing.close.latest different?

Can anyone help me understand why these prices are different? is prices() not returning closing price?

from quantopian.research import prices

print prices(  
    assets=symbols('ARNC'),  
    start='2015-04-15',  
    end='2015-05-11',  
)

2015-04-15 00:00:00+00:00    13.311  
2015-04-16 00:00:00+00:00    13.431  
2015-04-17 00:00:00+00:00    13.441  
2015-04-20 00:00:00+00:00    13.550  
2015-04-21 00:00:00+00:00    13.490  
2015-04-22 00:00:00+00:00    13.530  
2015-04-23 00:00:00+00:00    13.151  
2015-04-24 00:00:00+00:00    13.181  
2015-04-27 00:00:00+00:00    13.421  
2015-04-28 00:00:00+00:00    13.451  
2015-04-29 00:00:00+00:00    13.580  
2015-04-30 00:00:00+00:00    13.391  
2015-05-01 00:00:00+00:00    14.119  
2015-05-04 00:00:00+00:00    13.984  
2015-05-05 00:00:00+00:00    13.800  
2015-05-06 00:00:00+00:00    13.680  
2015-05-07 00:00:00+00:00    13.705  
2015-05-08 00:00:00+00:00    13.820  
2015-05-11 00:00:00+00:00    13.650  
Freq: C, Name: Equity(2 [ARNC]), dtype: float64  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline.data import USEquityPricing  
from quantopian.pipeline.experimental import QTradableStocksUS  
from quantopian.research import run_pipeline

def make_pipeline():  
    uni = QTradableStocksUS()

    close_price = USEquityPricing.close.latest

    return Pipeline(  
        columns={  
            'close_price': close_price,  
        },  
        screen=uni  
    )

data = run_pipeline(  
    make_pipeline(),  
    '2015-04-15',  
    '2015-05-10',  
)

data.xs(  
    symbols('ARNC'),  
    level=1  
)

    close_price  
2015-04-15 00:00:00+00:00   13.375  
2015-04-16 00:00:00+00:00   13.340  
2015-04-17 00:00:00+00:00   13.460  
2015-04-20 00:00:00+00:00   13.470  
2015-04-21 00:00:00+00:00   13.580  
2015-04-22 00:00:00+00:00   13.520  
2015-04-23 00:00:00+00:00   13.560  
2015-04-24 00:00:00+00:00   13.180  
2015-04-27 00:00:00+00:00   13.210  
2015-04-28 00:00:00+00:00   13.450  
2015-04-29 00:00:00+00:00   13.480  
2015-04-30 00:00:00+00:00   13.610  
2015-05-01 00:00:00+00:00   13.420  
2015-05-04 00:00:00+00:00   14.150  
2015-05-05 00:00:00+00:00   14.015  
2015-05-06 00:00:00+00:00   13.830  
2015-05-07 00:00:00+00:00   13.680  
2015-05-08 00:00:00+00:00   13.705  
2015-05-11 00:00:00+00:00   13.820  
4 responses

Stanley,

Fortunately my test in IDE did not prove any significant difference in USEquityPricing.close.latest and data.current(symbol('ARNC'), 'close')

# Test pipe_prices and  data_prices

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline.data.builtin import USEquityPricing  
from quantopian.pipeline import Pipeline, filters

def initialize(context):  
    set_symbol_lookup_date('2018-04-15')  
    price = USEquityPricing.close.latest  
    my_stock = filters.StaticAssets(symbols('ARNC'))  
    attach_pipeline(Pipeline(columns = {'price': price}, screen = my_stock), 'my_pipeline')         

def before_trading_start(context, data):  
    yest_pipe_price = pipeline_output('my_pipeline').price  
    yest_data_price = data.current(symbol('ARNC'), 'close')

    print(yest_pipe_price, yest_data_price)  

2015-04-15 05:45 PRINT (Equity(2 [ARNC]) 13.375
Name: price, dtype: float64, 13.375)
2015-04-16 05:45 PRINT (Equity(2 [ARNC]) 13.34
Name: price, dtype: float64, 13.34)
2015-04-17 05:45 PRINT (Equity(2 [ARNC]) 13.46
Name: price, dtype: float64, 13.46)
2015-04-20 05:45 PRINT (Equity(2 [ARNC]) 13.47
Name: price, dtype: float64, 13.47)
2015-04-21 05:45 PRINT (Equity(2 [ARNC]) 13.58
Name: price, dtype: float64, 13.58)
2015-04-22 05:45 PRINT (Equity(2 [ARNC]) 13.52
Name: price, dtype: float64, 13.52)
2015-04-23 05:45 PRINT (Equity(2 [ARNC]) 13.56
Name: price, dtype: float64, 13.56)
2015-04-24 05:45 PRINT (Equity(2 [ARNC]) 13.18
Name: price, dtype: float64, 13.18)
2015-04-27 05:45 PRINT (Equity(2 [ARNC]) 13.21
Name: price, dtype: float64, 13.21)
2015-04-28 05:45 PRINT (Equity(2 [ARNC]) 13.45
Name: price, dtype: float64, 13.450000000000001)
2015-04-29 05:45 PRINT (Equity(2 [ARNC]) 13.48
Name: price, dtype: float64, 13.48)
2015-04-30 05:45 PRINT (Equity(2 [ARNC]) 13.61
Name: price, dtype: float64, 13.61)
2015-05-01 05:45 PRINT (Equity(2 [ARNC]) 13.42
Name: price, dtype: float64, 13.42)
2015-05-04 05:45 PRINT (Equity(2 [ARNC]) 14.15
Name: price, dtype: float64, 14.15)
2015-05-05 05:45 PRINT (Equity(2 [ARNC]) 14.015
Name: price, dtype: float64, 14.015)
2015-05-06 05:45 PRINT (Equity(2 [ARNC]) 13.83
Name: price, dtype: float64, 13.83)
2015-05-07 05:45 PRINT (Equity(2 [ARNC]) 13.68
Name: price, dtype: float64, 13.680000000000001)
2015-05-08 05:45 PRINT (Equity(2 [ARNC]) 13.705
Name: price, dtype: float64, 13.705)
2015-05-11 05:45 PRINT (Equity(2 [ARNC]) 13.82
Name: price, dtype: float64, 13.82)

thanks, hmmm so is data.current(symbol('ARNC'), 'close') fetching from a different source than prices(assets=symbols('ARNC'))?

or is this bug perhaps only a problem on research notebooks, and is not a concern for the IDE?

I was struggling with getting returns for Alphalens that are not polluted by splits.

My impression is (but please correct me):

Prices retrieved through pipeline are what you were seeing at that point in time. This is what your algo should use.

As opposed to prices returned by the price function which are corporate action adjusted. This should be used for evaluation.

Maybe there's also a difference how the research and the algo evironment work for these two things.

Attila,

You are right that pricing data retrieved with Pipeline is adjusted point in time, while pricing data retrieved with get_pricing() is adjusted as of the end_date argument that you pass to it. The reason that get_pricing() is preferable for research / evaluation of alpha factors is that it is less computationally expensive, and thus you can iterate over ideas more quickly.

When you adjust prices to the present day, you introduce subtle lookahead bias. The workflow we encourage is to use Alphalens to quickly iterate over ideas, throw away alpha factors that clearly aren't worth anything, and use our more thorough (and slower) backtester once you settle on a set of alpha factors that you think is worthy of the full backtest.

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.