I wasn't sure if I should make a new thread about this but I've tried everything that I can think of and still can't get the composite alpha model to work at all in python. Has anyone had any luck getting multiple alphas to work together? According to Alexandre it should work even though there is no CompositeAlphaModel.Py in the Github yet.
I've attached a backtest using one of the framework example algorithms posted by Jared with the alpha copied to show how I get the error. I've commented out line 46 on main.py that produces the following error so I could attach the backtest.
self.SetAlpha( CompositeAlphaModel([HistoricalReturnsAlphaModel(resolution = Resolution.Daily), HistoricalReturnsAlphaModel_copy(resolution = Resolution.Daily)]) )During the algorithm initialization, the following exception has occurred: NotImplementedException : IAlphaModel.Update must be implemented. Please implement this missing method on <class 'list'>
at QuantConnect.Algorithm.Framework.Alphas.AlphaModelPythonWrapper..ctor (Python.Runtime.PyObject model) [0x00052] in <11d86b1e19c04e2d8733c42b16bf26de>:0
at QuantConnect.Algorithm.Framework.Alphas.CompositeAlphaModel..ctor (Python.Runtime.PyObject[] alphaModels) [0x0004d] in <11d86b1e19c04e2d8733c42b16bf26de>:0
at QuantConnect.Algorithm.Framework.Alphas.CompositeAlphaModel..ctor (Python.Runtime.PyObject alphaModel) [0x00000] in <11d86b1e19c04e2d8733c42b16bf26de>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke(System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <2e7c1c96edae44d496118948ca617c11>:0
at Initialize in main.py:line 42
NotImplementedException : IAlphaModel.Update must be implemented. Please implement this missing method on <class 'list'>
at QuantConnect.Algorithm.Framework.Alphas.AlphaModelPythonWrapper..ctor (Python.Runtime.PyObject model) [0x00052] in <11d86b1e19c04e2d8733c42b16bf26de>:0
at QuantConnect.Algorithm.Framework.Alphas.CompositeAlphaModel..ctor (Python.Runtime.PyObject[] alphaModels) [0x0004d] in <11d86b1e19c04e2d8733c42b16bf26de>:0
at QuantConnect.Algorithm.Framework.Alphas.CompositeAlphaModel..ctor (Python.Runtime.PyObject alphaModel) [0x00000] in <11d86b1e19c04e2d8733c42b16bf26de>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke(System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <2e7c1c96edae44d496118948ca617c11>:0
Alexandre Catarino
Hi LukeI ,
The CompositeAlphaModel does not accept a list of AlphaModel, but a sequence of parameters. So, if you replace
self.SetAlpha( CompositeAlphaModel([HistoricalReturnsAlphaModel(resolution = Resolution.Daily), HistoricalReturnsAlphaModel_copy(resolution = Resolution.Daily)]) )
for
self.SetAlpha( CompositeAlphaModel(HistoricalReturnsAlphaModel(resolution = Resolution.Daily), HistoricalReturnsAlphaModel_copy(resolution = Resolution.Daily)) )
In other words, remove the brackets, it works fine.
LukeI
Ah, how'd I miss that? thanks!
Andrew Kamal
Wow, thanks. I wish I knew that. For a while I was wondering the problem with it and didn't know it does it as a sequence of parameters.
LukeI
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!