Hi all,
I recently read the book “Unholy Grails” by Nick Radge and found it was brilliant. It had some great discussion on developing momentum strategies and some examples.
I decided to backtest one of the strategies in the book on the S&P500 and share the results on this forum. I am quite new to coding and quantitative finance and hope this discussion helps people in similar situations to me.
The basis of the strategy is to buy stocks on the open of the next day when the stock makes a new high in the last year (250 trading days). Then we sell the stock once it falls below the lowest price in the last year, which is hopefully higher than the entry price. We hold 20 positions at a time and set a stop loss at 20% below the entry price. This way, we only lose 1% of our account size on each wrong trade.
The S&P500 universe (Quantconnect equivalent) is used and the stocks are sorted by Market Cap.
As I mentioned I am fairly new to this and I am sure there are some improvements to be made in the script. I do appreciate any feedback.
Varad Kabade
Hi Jeremy,
Thank you for sharing the algorithm with the community.
In the above, the max indicator will not be ready for 250 days therefore, we cannot use it. We recommend warming up the indicator inside the SelectionData class:
Note that as the above algorithm is using raw data, if a stock undergoes a reverse split, it would result in the wrong calculation of the yearly minimum
Best,
Varad Kabade
Jeremy Buttel
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!