I have attempted to build the Adaptive Asset Allocation (AAA) algorithm outlined in ReSolve Asset Management's white paper. You can add any additional asset classes in the self.additional list that are't included in the original.
Please provide any feed back on code improvement.
I hope it's useful!
Jing Wu
Nice work! Thanks for sharing it. The code is very neat and easy to read. One suggestion I might have is about the history request. self.History() affects the running speed of the algorithm.
hist1 = self.History(self.stocks, 200, Resolution.Daily).unstack(level=0).close
hist2 = self.History(symbols, 200, Resolution.Daily).unstack(level=0).close.pct_change()[1:]
These two history methods get the same set of historical data. This repeat request slows down the algorithm. You can only select the required columns in the first history to construct a new dataframe.
For example, the above code is equivalent to the following
hist1 = self.History(self.stocks, 200, Resolution.Daily).unstack(level=0).close
hist2 = hist[symbols].pct_change()[1:]
Flame
Thanks for the feedback
Lexx7
This code has stopped working. I think symbol reference logic has changed? Can someone have a look please?
System.Collections.Generic.KeyNotFoundException: Trying to retrieve an element from a collection using a key that does not exist in that collection throws a KeyError exception. To prevent the exception, ensure that the 'VNQ', 'EEM', 'EZU', 'SPY', 'RWX', 'QQQ', 'IWM', 'IJR' key exist in the collection and/or that collection is not empty. ---> Python.Runtime.PythonException: KeyError : "None of [Index(['VNQ', 'EEM', 'EZU', 'SPY', 'RWX', 'QQQ', 'IWM', 'IJR'], dtype='object', name='symbol')] are in the [columns]"
Derek Melchin
Hi Lexx7,
There seems to be a bug with selecting multiple columns in the history DataFrame with a list of Symbols. See the attached research notebook for reference.
I've created a GitHub Issue to have this resolved. Our progress can be tracked here. For the time being, we can work around this bug by converting the list of tickers in Initialize to a list of Symbols.
self.stocks = [self.AddEquity(x, Resolution.Minute).Symbol for x in self.stocks]
Then when we are selecting the best performers, we just need to convert each Symbol to a Security Identifier.
symbols = [] for sym in range(int(len(sort) / 2)): symbols.append(str(sort[sym][0].ID))
See the attached backtest for reference.
Best,
Derek Melchin
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.
Ws2402
I was trying to replicate the above version that Derek Melchin made changes on. The problem is when I try to print the weights of the portfolio, it always outputs equal weights instead of "optimized" weights. Not sure what's wrong here? I did not make changes to the original code that Derek published. Thanks Folks.
Louis Szeto
Hi Ws2402
The code is bug-free. This is usually related to the initial values of the scipy optimizer, it could be stuck in a local minimum if the initial values are not properly chosen in some loss function, and the optimizer returns the initial values that are the equal-weighting portfolio.
However, minimal variance optimization has only 1 global minimum but not local ones, so it seems that the equal-weighting portfolio is just happening to be the minimum-variance portfolio by chance. We've also seen other values in the backtest so the loss function and optimizer are correctly set.Â
Best
Louis
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.
Flame
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!