Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Daily returns don't match with prices?

I am just getting started with Quantopian Research and having trouble understanding what the returns function is doing exactly..

In the notebook, I have SPY open, close, daily_return and close2 column.

open, close, daily_return is calculated using the API prices() and returns functions

close2 is calculated as open * (1 + daily_return) -- it should theoretically match up with the close price reported by Quantopian, but you can see it doe not. In some days the daily_return is negative even though the price moves up.

What is the quantopian.research.returns function is doing, and why doesn't it match up?

2 responses

The returns method fetches the percent gain (or loss) of a specific data field. The default field is price. So, the method in the above notebook will fetch the one day gain of the 'price'. The 'price' field is simply the last 'close' price. So, the default returns method will fetch the gain from the previous close to the current close price. It doesn't reflect the gain from the open to the close.

The returns method has a number of parameters to change. For instance, the data field (eg fetch previous open to current open gain), the period of the gain (eg get monthly 20 trading returns), or change the frequency and get minutely, rather than the default, daily returns. See the docs here https://www.quantopian.com/docs/api-reference/research-api-reference#quantopian.research.returns

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 that clears things up!