I am using the algorithm framework to backtest custom rebalancing periods on a portfolio that will have assigned weights using the InsightWeightingPortfolioConstructionModel. Ideally, I would configure the rebalancing period from the SetPortfolioConstruction line of code, but the self.DateRules is limited to every day, day of week, weekly, and monthly rebalancing periods. I have tried to use self.DateRules.Every(timedelta(90)) but this results in an error.
self.SetPortfolioConstruction(MyInsightWeightingPortfolioConstructionModel(self.DateRules.MonthEnd()))I would like to modify the code to backtest quarterly rebalancing or biweekly rebalancing. I was thinking of modifying the InsightWeightingPortfolioConstructionModel by creating a condition to check if 3 months/2 weeks has passed within the ShouldCreateTargetForInsight method.
Would appreciate any solutions to solve this.
Shile Wen
Hi CapoCapital,
To rebalance every two weeks, our rebalance should be set to timedelta(weeks=2), and for every quarter, we should set rebalance to timedelta(weeks=14), 14 is calculated by 52 weeks / 4 = 14 weeks. I’ve attached a backtest on how to rebalance bi-weekly.
However, if these timedeltas are not what you are looking for, please see this to see how to create a custom rebalance function.
Best,
Shile Wen
CAPOCAPITAL
Thank you Shile, I was using the wrong sytnax with timedelta but your correction works for me.
I started working on a custom rebalance function similar to the link you provided, much appreciated!
CAPOCAPITAL
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!