Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
HELP - Why do quantopian.research.returns() and quantopian.pipeline.factors.Returns() give different output?

The title says it all.

Both are supposed to return daily returns of an asset, so why do quantopian.research.returns() and quantopian.pipeline.factors.Returns(window_length = 2) give slightly different numbers?

I just started learning Quantopian, so your help would be greatly appreciated!

1 response

First off, welcome to Quantopian!

The returns values fetched using pipeline are identical to those fetched via the notebook returns function. They may appear at first glance to be 'off' but the pipeline returns are really just 'shifted' by a day from the notebook returns. However, this isn't really a 'shift' but rather the different interpretation of what date is being implied in pipelines verses notebooks.

This illustrates an important difference between pipeline data and notebook price/returns data. Pipeline data is always 'as of' before markets open on the pipeline date. It is the data a trader would have known to begin making trades on that date. For pricing and returns it is the previous days data. The use case for pipeline data is to analyze how trading strategies would have worked in the past. Therefore, to eliminate lookahead bias, the pipeline data available to a strategy will always be 'as of' before market open and not the current days data (ie the markets haven't opened yet).

However, the returns, get_pricing, and other notebook functions return values as of the dates specified. The returns for a given date are for that date. Their use case is most often historical analysis and plotting and makes sense to be for that date.

See the attached notebook showing this. Hope that helped.

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.