You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the PortfolioConstructionModel class, the CreateTargets method should only create a flatten target for securities that are removed from the universe when we want to liquidate removed securities, i.g., their insights expired.
Actual Behavior
If rebalance is required (for whatever reason), CreateTargets always creates a flatten target for securities that are removed from the universe (even if the insights are still active on those securities).
The issue is that inside the CreateTargets method, once IsRebalanceDue[source] returns true for whatever reason, rebalance will set in and these lines [source] will always be executed to liquidate removed securities, even if RebalanceOnSecurityChanges is False.
Potential Solution
My solution is to add RebalanceOnSecurityChanges as a condition to this line. Please refer to my fork here:
# if RebalanceOnSecurityChanges is False, we can continue rebalance and let the insight
# period on those removed securities to determine whether they should be liquidated or not
if (_removedSymbols != null && RebalanceOnSecurityChanges)
{
var universeDeselectionTargets = _removedSymbols.Select(symbol => new PortfolioTarget(symbol, 0));
targets.AddRange(universeDeselectionTargets);
_removedSymbols = null;
}
RebalanceOnSecurityChanges is True by default, so a position will be liquidated by default if the security is removed from the universe. With this solution, if RebalanceOnSecurityChanges is set to False, the rebalance process is no longer liquidating a position just because the security is removed from the universe (liquidation might still happen later during the rebalance process, if insight expires).
SPY and AMZN is taking turns to be included in the universe, so securities are being added and removed.
insight lasts for 2 days
RebalancePortfolioOnSecurityChanges is set to False and daily automatic rebalance is turned off by lambda time: None to make sure we are rebalancing only because there is a new insight on every other day and NOT because one of the securities is removed from the universe.
Nevertheless, the arrival of a new insight for AMZN triggers rebalance on the second day, so SPY was liquidated [source] even if its 2-day insight is still active.
System Information
Checklist
I have completely filled out this template
I have confirmed that this issue exists on the current master branch
I have confirmed that this is not a duplicate issue by searching issues
I have provided detailed steps to reproduce the issue
The text was updated successfully, but these errors were encountered:
Moreover, the comment in this thread suggests that we need to do the following to make sure positions are not liquidates on removed securities:
self.Settings.RebalancePortfolioOnSecurityChanges = False
self.SetPortfolioConstruction( EqualWeightingPortfolioConstructionModel(lambda time: None) ) # not good
The fact that we need to turn off rebalance (second line) is not desirable because we may still want to rebalance daily to achieve an ideal portfolio weight.
With this issue fixed, only self.Settings.RebalancePortfolioOnSecurityChanges = False is needed and we can still rebalance our portfolio however we want.
Expected Behavior
In the
PortfolioConstructionModel
class, theCreateTargets
method should only create a flatten target for securities that are removed from the universe when we want to liquidate removed securities, i.g., their insights expired.Actual Behavior
If rebalance is required (for whatever reason),
CreateTargets
always creates a flatten target for securities that are removed from the universe (even if the insights are still active on those securities).The issue is that inside the
CreateTargets
method, onceIsRebalanceDue
[source] returnstrue
for whatever reason, rebalance will set in and these lines [source] will always be executed to liquidate removed securities, even ifRebalanceOnSecurityChanges
isFalse
.Potential Solution
My solution is to add
RebalanceOnSecurityChanges
as a condition to this line. Please refer to my fork here:RebalanceOnSecurityChanges
isTrue
by default, so a position will be liquidated by default if the security is removed from the universe. With this solution, ifRebalanceOnSecurityChanges
is set toFalse
, the rebalance process is no longer liquidating a position just because the security is removed from the universe (liquidation might still happen later during the rebalance process, if insight expires).Reproducing the Problem
The following algorithm reproduces the issue:
In the algorithm,
RebalancePortfolioOnSecurityChanges
is set toFalse
and daily automatic rebalance is turned off bylambda time: None
to make sure we are rebalancing only because there is a new insight on every other day and NOT because one of the securities is removed from the universe.System Information
Checklist
master
branchThe text was updated successfully, but these errors were encountered: