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.

1

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

1

Thanks for this excellent peice of code, I'm very interested in adopting it.

Just a few qustions though I'm having trouble trying to incorporate this into my framework algorithm:

1. Since the framework is modular there is the possibility that there is more than 1 alpha (as there is in my case), possibly working on the same security symbols simultaniously. How do you recommend that we combine multiple signals into one optimization?

2. There are a lot of allocation based alphas that asign a % allocation to a security and not a simple "up, down, flat" signal. Do you have any ideas on how to incorporate these into the optimization?

 

As it's programed currently, it seems to be acting as an alpha in disguise and it will replace any other alpha your algorithm is already generating outside of the "up, down, flat" limitations rather than improving the alphas you already have.

1

Hi Lukel,

I'm glad you found the algo useful!

Regarding your questions:

  • Multi Alpha Framework. In the context of a Multi Alpha system, with multiple predictive models emitting signals (some times conflicting signals on same symbols), the way I perform optimization within the Portfolio Construction Module as follows:
    • First optimizing the allocation to each Alpha model. I keep track of the historical returns from the predictions of each Alpha and calculate the weights that maximize the sharpe ratio of the whole system for example (or perhaps portfolio variance or others).
    • Once you know the allocation to each Alpha (together with their recent accuracy, cumulative returns, etc.), you can easily rank the insights coming from the Alpha and make the final selection within the Portfolio Construction.
    • Finally, you can apply further optimization to the weights of the symbols from each Alpha as if each Alpha were an independent portfolio whose weights must sum up to "total allocation for the Alpha". Or simply equal weighting or whatever you want.

The whole idea is to treat each Alpha model as an "asset" that generates a series of returns with a certain distribution that can be modelled accordingly. Bear in mind I do this in the context of intraday strategies so for me what matters is which Alpha to "trust" for today, rather than actually constructing an optimal portfolio. But just sharing my thoughts here.

  • Regarding your point 2, could you please give an example so I can understand and give a better answer?
Thanks! Emilio InnoQuantivity.com 
2

This is really cool! Thanks for sharing!

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