Once a week I’m going to post a backtest of my attempt to implement a trading strategy based off of a research paper, so that others can critique my code and I can learn at an expedited pace.
BUY RULE
The system invests in the top X sectors. For Top 1, the system is 100% invested in the top ranked sector. ForTop 2, the system is 50% invested in each of the top two sectors. For Top 3, the system is 33% invested in eachof the top three sectors.
SELL RULE
Since the system is a simple ranking, the top X sectors are held and if a sector falls out of the top X sectors it issold at the monthly rebalance and replaced with the sector in the top X.
**note**
Whenever the s&p is below the 200 day sma I go 100% into bonds.
There are only 6 sectors to choose so I couldn’t imitate the paper exactly(missing biotech, Technology etc).
I also did a monthly rebalance as oppose to an end of month rebalance(Every 25 days). Other than that the strategy is basically the same as the paper probably minus some inaccuracy in my coding and the fact that I’ve decided to sort my universe based off of dollar volume.
Anyways I will be posting again a week from now. Cheers !
Leigham Springer Sutton
Here is the paper >>>https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1585517
Petter Hansson
Do you think this would be work better with more granular sectors? The we have here at QC just have 5 or 6 IIRC.
Leigham Springer Sutton
Petter Hansson , Yes, I think so both; biotech and technology are sectors that have offered some sizeable opportunities to capture volatile swings. Being able to partake in those would more than likely generate more alpha(I think anyways)
DEVON
sorry, when I clone the strategy then do the backtest, I got following error:
[ERROR] FATAL UNHANDLED EXCEPTION:SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 20, Initial Margin: 4938.5439370400000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 21, Initial Margin: 4981.2308701960000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 22, Initial Margin: 5007.6730507500000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 23, Initial Margin: 4897.6618478560000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 24, Initial Margin: 4972.5525167460000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 25, Initial Margin: 4938.5439370400000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 26, Initial Margin: 4981.2308701960000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 27, Initial Margin: 5007.6730507500000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 28, Initial Margin: 4897.6618478560000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 29, Initial Margin: 4972.5525167460000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 30, Initial Margin: 4938.5439370400000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 31, Initial Margin: 4981.2308701960000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 32, Initial Margin: 5007.6730507500000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 33, Initial Margin: 4897.6618478560000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 34, Initial Margin: 4972.5525167460000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 35, Initial Margin: 4938.5439370400000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 36, Initial Margin: 4981.2308701960000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 37, Initial Margin: 5007.6730507500000, Free Margin: 3201.364278826000,SecurityTransactionManager.GetSufficientCapitalForOrder(): Id: 38, Initial Margin: 4897.6618478560000, Free Margin: 3201.364278826000,Error: Garbage collector could not allocate 16384 bytes of memory for major heap section.
Leigham Springer Sutton
Garbage collector could not allocate 16384 bytes of memory for major heap section. <<< I'm not 100 % sure but I think maybe too much memory is being used, try running the strategy with less securities.
Leigham Springer Sutton
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!