Back

Algorithm Framework Module - Portfolio Construction Model With Custom Optimizer

Hi Guys,

I wanted to share with the community my implementation of a Custom Optimization Portfolio Construction Model.

The Portfolio Construction Model calculates the desired targets for each asset in our portfolio. This is a custom implementation of the model that will allow you to use different optimization techniques for your portfolio (maximize portfolio return, minimize portfolio volatility, maximize portfolio sharpe ratio, and even a standard equal weighting for comparison).

Once the predictions are sent to the Portfolio Construction Model, it will get the daily log-returns of the last 252 trading days and calculate the weights for each individual security that optimize the provided objective function. The model will also plot the optimal allocation for each asset so we can inspect what it's doing.

The below algorithm is a simple example to show how it works with a buy and hold strategy, but this module can be plugged into any other strategy requiring portfolio target calculations.

Ideas to try (user-defined inputs in the main.py script):

  • Change the objectiveFunction parameter to test other objective functions to optimize. Options are: 'return' (maximize portfolio return), 'std' (minimize portfolio standard deviation), 'sharpe' (maximize portfolio sharpe ratio), and also 'equal' (for a standard equal weighting).
  • The rebalancingParam is currently set to 365 days, but it can be set to a discretionary number of days to rebalance the portfolio and go back to optimal weights. For instance, if you want to rebalance every 30 days simply do rebalancingParam = 30

Emilio

InnoQuantivity.com

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.


This is really cool, thanks for sharing!

It also highlights the power of the algorithm framework, since it effectively separates concerns and makes code like this highly reusable.

0

Thanks Petter, I'm glad you liked it!

I totally agree with you and that was exactly the purpose of the post. t's challenging to make 100% reusable modules, but I think with time we will get there and sharing with the community will become super powerful.

Emilio

InnoQuantivity.com

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