I want my algorithm to
- screen for securities
- buy those securities
- hold them for a year
- liquidate them
- repeat
Unfortunately I'm running into problems at the hold them for a year part. My solution was to emit insights with an expiration of 254 days, which is about a year's worth of trading days. It seemed to be working fine when I was doing short tests, but once I tried to backtest from 2000, I started running into problems.
I thought that once my insights expired, the securities would be liquidated, but it looks like there might be some stragglers that don't get liquidated. I am using
if not self.Portfolio.Invested:
to trigger my universe selection and insight emission to happen, so if there are stragglers in the portfolio then it won't fire for years, which looks like what is happening in my attached backtest.
What is the easiest way to make my algorithm work the way I want it to? I was hoping to have to do universe selection only once a year to make my backtest faster and more efficient.
Shile Wen
Hi Victor,
The best way to approach this would be to use a ConstantAlphaModel and return a new Universe of securities once per year, while returning Universe.Unchanged on other days. I've shown these changes in the attached backtest.
Best,
Shile Wen
Victor Lin
Hi Shile,
Thank you so much for your suggestions, but I think there are a few quirks to your algorithm.
As you can see, this isn't the behavior that I was going for. Is there a way in the algorithm framework to just liquidate everything on 31 Dec of each year?
Shile Wen
Hi Victor,
We can make some changes to the ConstantAlphaModel to return Flat Insights to liquidate the position near the end of the year. I've shown this in the attached backtest.
Best,
Shile Wen
Â
Shile Wen
Hi Victor,
We can make some changes to the ConstantAlphaModel to return Flat Insights to liquidate the position near the end of the year. I've shown this in the attached backtest.
Best,
Shile Wen
Â
Victor Lin
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!