Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
window_length bug

Hi there!

Attached is a notebook where I get stock prices for the current day through USEquityPrices and again through a window_length. I noticed that when the window_length was small (50), I noticed the prices no longer match, even though no other parameters have been adjusted.

In the provided notebook in cell 6, the first row of 'Latest Close' matches the fifth row of 'Offset_close' because the window_length was adjusted to 5. However, when attempting the same example with a window length of 50 in cell 10, the 50th row of 'Offset_close' does not match the first row of 'Latest Close'. Interestingly, the trend of the stock remains the same, but the values are slightly lower than what is expected.

Is this a bug or is this intended behaviour? If it is intentional, how can I adjust these prices so that they match?

Thanks,
Sunny

2 responses

This isn't a bug. What's happening is the close price is being adjusted for dividends. All pipeline outputs are adjusted for splits and dividends as of each day in the pipeline. There are a couple of good posts on this in the forums. Here's one (https://www.quantopian.com/posts/get-lagged-output-of-pipeline-custom-factor )

To answer your question "how can I adjust these prices so that they match?" one first needs to understand what the goal is. Typically, prices and volumes are split and dividend adjusted to make for accurate comparisons. If there was a 2:1 split one wouldn't want to interpret the resulting change in price as a price drop. However, there may be instances where unadjusted data is useful. Perhaps one wanted to see if a stocks price ever dropped below $1/share. Here the unadjusted price would be desired.

So, if one really want's the unadjusted price, one needs to write a custom factor which returns the price and (here's the secret) one needs to specify the factor is window_safe. This is the trigger to the offset method (defined in the notebook above) which tells it to NOT adjust the inputs.

Attached is a notebook which steps through the options.

Hope that helps.

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.

Thank you for your quick response, I really appreciate the detail and time took to write it!