I would like to use insight weighted potfolio construction model with rebalancing disabled. I am using a 30 day rebalancing period, am am still seeting daily rebalancing:
One insight was generated: 2019-07-01 09:31:00 >> PACB 2019-07-01 09:31:00 -0.001 -0.025 19.38 False
After a fill:
2019-07-01 09:31:00 2019-07-01 09:31:00: 0: Time: 07/01/2019 13:31:00 OrderID: 1 Symbol: PACB Status: Filled Quantity: 410 FillPrice: 6.07 USD OrderFee: 2.05 USD
Quantity was reduced when the market opened next (possibly due to price increase?):
2019-07-02 09:31:00 2019-07-02 09:31:00: 0: Time: 07/02/2019 13:31:00 OrderID: 2 Symbol: PACB Status: Filled Quantity: -1 FillPrice: 6.1 USD OrderFee: 1 USD
2019-07-05 09:31:00 2019-07-05 09:31:00: 0: Time: 07/05/2019 13:31:00 OrderID: 3 Symbol: PACB Status: Filled Quantity: -2 FillPrice: 6.14 USD OrderFee: 1 USD
# I have tried using timedelta and rebalance period of 30days
rebalance_period = Time.Multiply(Extensions.ToTimeSpan(Resolution.Daily), 30)
self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel(
#rebalancingParam = timedelta(days = 30),
rebalancingParam = rebalance_period,
portfolioBias = PortfolioBias.Long))
Seersquant
Want to update this with a few other things I tried:
rebalancingParam = None # rebalances every minute, as expected from default resolution
# 300 days
rebalancingParam = timedelta(60*24*300) # I still see rebalancing after 2 days or so
rebalancingParam = timedelta(days = 30) # similar to above
Martin Molinero
Hey Seersquant,
We have also added two new algorithm settings to give the PortfolioConstructionModel more control over rebalancing, try using the following in the algorithm initialization:
self.Settings.RebalancePortfolioOnInsightChanges = False; self.Settings.RebalancePortfolioOnSecurityChanges = False;
RebalancePortfolioOnInsightChanges: True if should rebalance portfolio on new insights or expiration of insights. True by default
RebalancePortfolioOnSecurityChanges: True if should rebalance portfolio on security changes. True by default
Can see an example at PortfolioRebalanceOnCustomFuncRegressionAlgorithm, this algorithm defines a custom rebalancing method that triggers rebalancing when the portfolio deviation from the target is above 2%.
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.
Seersquant
Thanks Martin for the insights, that really helps. Just to carify a few things:
Rebalance when there are any new active insights, on a symbol with existing investment or any other symbol in the universe (have tested this)
Rebalance, when ANY new securities are added to the universe?
Here is what I am trying to achive: Need a way to use insights just once, without rebalancing in the future. However, I do want to go flat when the insight expires.
Jan 1st: UP for AAPL for 30 days, at 10% portfolio
Jan 15th: UP for AMZN for 30 days, at 10% portfolio
Expectation:
Don't buy/sell any AAPL on Jan15th (its allocation might be higher/lowere than 10%, that's OK)
Sell APPL on Feb 15th (after expiration of the Alpha signal, ~30 trading days)
I want this was a 3-10 day swing strategy, and rebalancing is triggering a lot of spurious orders I didn't expect.
Rahul Chowdhury
Hey Seersquant,
1. Setting RebalancePortfolioOnInsightChanges to True will rebalance on new insights or expiration of insights. This means if you set this to False, no new portfolio targets will be created for AMZN and for your AAPL position, and the latter will not be rebalanced.
2. Setting RebalancePortfolioOnSecurityChanges to True will rebalance on security changes, meaning addition or removal of securities from universe. If set to True, your portfolio would be rebalanced every time that OnSecuritiesChanged is also called. For your purposes you should set this to False.
Seersquant
Hi Rahul,
With the suggested settings AAPL is still rebalanced on Jan 15th (when AMZN is bought). If I have 50+ holdings, and adding one more insight triggers a rebalance in all of them that creates and issue.
Date TimeSymbolOperationTypePriceQuantityStatusTag2019-01-01 00:00:00AAPLBuyMarket On Open$152.23611474 USD64Filled 2019-01-15 00:00:00AMZNBuyMarket On Open$1,632.82 USD6Filled 2019-01-15 00:00:00AAPLBuyMarket On Open$147.69527382 USD3Filled 2019-02-14 00:00:00AAPLSellMarket On Open$167.5667008 USD-67Filled 2019-03-01 00:00:00AMZNSellMarket On Open$1,653.80 USD-6FilledPierre Vidal
Hi all,
Following up on that thread, I have the same need: I too would like to use insight weighted potfolio construction model with rebalancing disabled.
Having tried all the syntactic possibilities (I think) to instruct InsightWeightingPortfolioConstructionModel to not rebalance (or rebalance only in a very very long time), I still see small rebalancing orders at least on a daily basis.
Now that may be because it rebalances on Insights expiries... My algo emits weighted insights which frequently overlap, so there are insights expiring on many days - but I would not want any additional action taken on insights expiries.
I have tried:
self.Settings.RebalancePortfolioOnInsightChanges = False but then that resulted in no trades being placed at all. Any further advice on this topic would be helpful. Thanks!Jared Broad
Hey Piere! For people who desire complete control over the rebalancing, we've abstracted this out to a function. With the function, you can control the precise moment it triggers a rebalance and even do cool things like rebalancing when your portfolio deviation reaches a specific error from what you want it to be.
You can see a full example of this in this demonstration algorithm:
https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/PortfolioRebalanceOnCustomFuncRegressionAlgorithm.pyThe 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.
Pierre Vidal
Hi Jared,
Thanks for the precision. I am coming back late on this thread because I wanted to include an example backtest illustrating my concern.
- My illustrative strategy repeatedly emits on each month start an up insight for SPY with weight 60%, and an up insight for TLT with weight 40%. I set a 35-day period for both.
- I use InsightWeightingPortfolioConstructionModel passing a rebalance function that just returns None.
The backtest results show that there are more trades than emitted insights, which is not what we would expect in that case. Indeed we can see additional trades taking place around the 20th of each month (presumably rebalancing on expiries of previous insights). My expectation would be no action taken on insight expiry, if that insight has already been overridden by a new insight on the same security. BestJared Broad
Using the properties Rahul mentioned above to prevent rebalancing on your 35-day insight expiries.
self.Settings.RebalancePortfolioOnInsightChanges = False self.Settings.RebalancePortfolioOnSecurityChanges = True
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.
Pierre Vidal
Thank you Jared, I have now finally got this!
I had tried the Settings before, but missed the trick with that "trigger" boolean workflow in the rebalance function...
My enlightment was to realize that in that use case the portfolio model never acts on new insights, but instead we trigger a rebalance between all the then active insights at the time of insight emission...
I have tried this on my "real" strategy. It reduced the number of trades as expected, saving almost 10% in fees... Brillant!
Li Mike
I wonder if using self.Schedule.On(self.DateRules.MonthStart(self.spy), self.TimeRules.AfterMarketOpen(self.spy, 5), self.emitNewInsights) to emit insight is a recommended method?
Louis Szeto
Hi Li Mike
You may also set up an AlphaModel:
Best
Louis
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.
Seersquant
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!