How do I rebalance my portfolio once a year?

Back

I want my algorithm to

  1. screen for securities
  2. buy those securities
  3. hold them for a year
  4. liquidate them
  5. 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.

Update Backtest








 
0

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.


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

0

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.


Hi Shile,

Thank you so much for your suggestions, but I think there are a few quirks to your algorithm.

  1. The algorithm starts by buying 158 different securities on 1 Jan 2015. So far so good.
  2. The algorithm sells only 96 securities on 1 Jan 2016. I think the reason why the whole portfolio was not liquidated is because there are some overlapping securities in the 2015 and 2016 batch. At least I hope this is the reason.
  3. Also on 1 Jan 2016, 118 securities were bought.
  4. On 15 Jun 2016, 85 securities were sold. I think this is because you set the alpha insights to expire in 365 days, and it counts in trading days, not calendar days. The insights must have expired on this day and then were sold.
  5. Also on 15 Jun 2016, 94 securities were bought. This part is baffling to me. No new insights are being emitted, why are purchases being made?

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?

0

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
 

0

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.


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
 

0

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.


Update Backtest





0

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.


Loading...

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!