Back

Rebalancing Monthly using PortfolioConstructionModel? - Algorithm Framework

Hi There,

I've found other forum posts describing how to use SetHoldings for rebalancing a portfolio on a given date, weekly, monthly, etc. However, I am having trouble finding an example using the Algorithm Framework, only executing trades/rebalancing on a monthly basis when implementing a custom PortfolioConstructionModel. Do I need to keep track of the timespan somehow in my main algorithm file in Initialize()? Is there someway to add this logic to the PortfolioConstructionModel itself? Thank you!

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.


The PortfolioConstructionModel is meant to receive Insight objects from the alpha model and create PortfolioTargets. If the algorithm needs to trade/rebalance on a monthly basis, try emitting insights once a month and then the PortfolioConstructionModel will create the targets/rebalance on a monthly basis. One possibility could be using a boolean that stops any trading decisions from being made and change the boolean to True once a month,

0

What triggers the Update method in Alpha Model? And why isn't it possible to user-define the frequency with which it is called? 

0

Hi Filib,

The Update method gets called as frequently as the smallest resolution data in your Universe (i.e. Hour, Minute, etc.). You can force it to ignore data slices and only run the code within at certain times, and I've added an example of this to your post here.

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.


Jack Simonson Could you please post your code/backtest here?

0

Hello Grimreaper,

Thanks for your support! You could find Jack's code and backtest, the accepted answer, in this link by clicking buttons of the chart, statistics, and code  

If there's a problem, please let me know. Hope it helps!

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 There,

i am facing the same issues.

In the w/o framework environment the frequency of the universe construction can be easily controlled by boolean variables combined with the time object. 

Accordingly, the rebalancing can be easily controlled within the OnSecirityChanged method and is automatically synchronized with the universe construction. 

Now, within the framework 

  • UniverseSelectionModel
  • AlphaModel
  • PortfolioConstructionModel

are called in the resolution of the algorithm indipendently from each other.

E.g. the PortfolioConstructionModel is called even though there was no change in the AlphaModel, and rebalances the portfolio based on the price changes. 

Question1: What is the best way to have a rebalancing e.g. once a month or twice a year synchronized with the method OnSecurityChange.

Question2: What is the best way to calculate the alpha period time-span-value if it should be just valid until the next universe construction. e.g. reconstruction/rebalancing on the 1st Jan. and on the 1st July.

Cu Eugene

0

Hi Eugene,

I'm attaching a backtest which just rebalances on security changes using the EqualWeightingPortfolioConstructionModel.

Also, it might be interesting for you to take a look at this rebalancing method PortfolioRebalanceOnCustomFuncRegressionAlgorithm which rebalances based on the total deviation of securities from their target. There are other examples too, for specific date rules you can see PortfolioRebalanceOnDateRulesRegressionAlgorithm which rebalances every Wednesday.

Hope it helps!

1

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 Martin,

thx. that helped! 

0

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...

This discussion is closed