Back to Community
Definition of Returns on Quantopian

Could someone enlighten me on how returns on Q are computed (i.e. the returns that are created with compute_clean_forward_returns)? That is, close to close, of what date? The API documentation does not mention (or at least I could not find it).

So for instance, if I am looking at a Return on April 3rd, is that defined as the return buying on the close on April 3rd to close on April 4th?

2 responses

Hi Niccola,

The answer to your question actually depends on the context in which you are working. By the sounds of it, you are asking specifically about get_clean_factor_and_forward_returns in Alphalens. If that's the case, you can find the definition of this function in the Alphalens repository in GitHub. Note that the function takes pricing data as input, so you can choose whether to provide close prices or something else (open prices are recommended in the Alphalens Tutorial on Q).

There is also a built-in Returns factor in the Pipeline API. The Returns factor is defined in the API reference as follows: "Calculates the percent change in close price over the given window_length."

Generally speaking, a return on day N should not include any information from day N+1 to avoid lookahead bias. In the case of the Returns factor in the Pipeline API, a Returns(window_length=2) will actually get you the relative difference between the previous close and the close before that. This is because pipelines are expected to be run before market open, so those are the two most recently known close prices.

Again - the answer very much depends on the context in which you are answering. Let me know if this answer is helpful or if there's another context you are wondering about.

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.

That makes sense, thank you so much for the detailed response Jamie.