Back

Algo Framework ETF Momentum Rebalancing using Mean Variance Optimization

Hello All!

Yesterday we presented a webinar for Interactive Brokers on using Mean Variance Optimization for ETF Portfolio Rebalancing. We implemented it in the Algorithm Framework -- a new way we're offering for users to design algorithms which is more modular and extensible.  

The Framework was built using the most common abstractions we see in the community. It has 5 modules - Universe Selection, Alpha Creation, Portfolio Construction, Execution and Risk Management. If you're interested I'd recommend checking it out as a way to improve your algorithm foo! 

The key module we discuss here is the Mean Variance Portfolio Construction Model. This takes the historical returns of the assets presented by the Historical Returns Alpha Model and uses them to construct the portfolio! Its fascinating stuff on the cutting edge of Quant finance so I'd highly recommend learning the new framework.

Check out the video and slides below!

https://www.youtube.com/watch?v=YcuMzLmOzH0

 

https://www.slideshare.net/quantconnect/quantconnect-etf-momentum-asset-allocation
Update Backtest






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.



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 all!

I am also getting errors when trying to backtest this algorithm.

Best,

Andrew

0

andrew_czeizler, this is an old post. Now we've already put "HistoricalReturnsAlphaModel" and "MeanVarianceOptimizationPortfolioConstructionModel" into the LEAN framework library. Please see the attached algorithm. 

You'll find the model source code on Github

https://github.com/QuantConnect/Lean/tree/master/Algorithm.Framework
0


I cloned the algo from above, and I went to run the backtest and I got a bunch of insufficient buying power errors.  Any idea as to why this is happening?  Below is an example of the errors I am seeing.

 Backtest Handled Error: Order Error: id: 101, Insufficient buying power to complete order (Value:8129.9063), Reason: Id: 101, Initial Margin: 4065.9531329395, Free Margin: 1253.9592675246086301998343

 Backtest Handled Error: Unable to compute order quantity of DBC. Reason: The portfolio does not have enough margin available.. Returning null.
0

Lexx7,

To answer your questions in order:

1) The portfolio rebalances daily as it is, so if you only want to trade monthly, then you can add logic in the Alpha Model so that it only sends out signals when you want it to, i.e. in monthly intervals. You can see the backtest I've attached for an example in the HistoricalReturnsAlphaModel.py file.

2) Period refers to the number of periods (dependent on the data resolution) for which we want to examine prices, whereas lookback is the number of periods for which we want to examine returns. If you subscribe to daily data and ask the algorithm to rebalance the portfolio every day, it will try to look back for n-days of returns and use an n-day period of prices to find the optimal portfolio. Since you're subscribed to daily-data, this will result in an equal-weighted portfolio every time, and so the resolution of the data universe needs to be higher than that of the HistoricalReturnsAlphaModel.

3) Margin requirements get used up when the algorithm tries to take any position and so orders that require more capital than available will be canceled. You can find more information about margin accounts and other account types 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.


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