Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Questions about MA on stock split

Hi everyone,

I am new to Quantopian and got some questions while testing simple MA crossover. Though I have searched similar questions for a while, not sure if there are solutions out there. I would appreciate your help.

  1. The mavg function deals only with the price process rather than total return process. Therefore, after the stock split in May as the example shows, the algorithm did not work correctly. Is there any solution other than importing total return process?

  2. About parameter optimization, I am thinking about implementing it together with the trading algorithm. However it slows down the speed of back testing or live trading greatly. Is doing the optimization outside a better option?

Thank you.

Hikaru

3 responses

Hikaru,
I am going to try and get some more info on this, but in the meantime, I changed your algo some to adjust the prices it uses for the stock split.

When an N to 1 split happens the price is divided by N, but there are N times more shares, so the market value is unchanged. That means we can divide the prices before the split by N to smooth out the curve for trading signals. Quantopian data is supposed to be split adjusted though, so I will continue to look into this.

David provided a great overview of how splits are generally handled in the backtester. This case is unique because it was the first corporate action of its kind. Google issued stock dividend in April 2014, as noted in the chart. Our historical data is adjusted for splits and mergers, but the price is not adjusted for dividends.

sid(26578) refers to the original Google Stock of class A shares that were trading since the company IPO'd. At the time of the dividend, if you held 1 share of class A stock, you were rewarded with 1 share of the newly created Class C stock and the stock price was cut in half. The chart correctly displays this change if you record the stock price. And you had an extra stock in your portfolio of a Class C share. However, since we don't adjust the stock price before the dividend, the returns are interpreted as negative values.

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.

It seems only this special split and all dividend events need to be handled.
Thank you all so much!