Hi All,
I am attempting to build, using the Algorithm Framework, a part of ResolveAssetManagements ensemble approach to Gary Antonacci's Global Equities Momentum (GEM). Their version, instead of picking the best performing lookback period, picks an ensemble of lookback periods, and trades them all (amongst other things).
I have been able to build this startegy in a Jupter Notebook using ticker strings to build the DataFrame Columns and lookback periods (ints) as index values & Int again as DF values themselves. When I transfer this to Lean I run into the problem that Symbol Objects are not callable(?) and Indicator values, not being Int's, means I cannot do comparative analysis (><) between them.
I am trying to get my head around how to best implement Symbol objects and Indicator Objects in a Dataframe.
BUT is a DF even the best way to do this analysis??
#1: df[symbol] doesnt work. I think it's because a QuantConnect Symbol object is not callable? I've tried str(symbol) ive tried accessing first elements of symbols with symbol[0] but nothing seems to work. I am trying to avoid hard coding ticker strings "SPY" "VEU" etc... which does work.
#2: Even if I hard code ticker_strings and gain access to the values... I still can't do a comparison between them. I think this is because I havent used .Current.Value, however, when I build the DF using that I lose my indicator lookback indexing!
ISSUE: Rookie programmer trying to convert a dict of dicts into a dataframe, without losing a direct link between values and index, in orde to do comparative analysis. I can build the DataFrame but then run into trouble accessing it using Symbols as the columns, Indicator lookbacks as the Index.
Also, when attempting to do comparative analysis between assets on MomentumPercent Indicators I get another error as I did not build the DataFrame using .Current.Value
Why didn't I? Because when I do that I lose my lookback indexing in the dataframe. I did try creating a list of lookbacks[] and appending the lookback periods to use as an index but then I couldnt be sure the values would always match up with the appropriate index?
Anyway, have a look at the code - Any assistance you can offer would be very much appreciated.
Derek Melchin
Hi Mark,
Pandas may be overkill for a problem like this. Instead, I'd recommend using the light-weight alternative, numpy. The following snippet resolves the issue:
strategies = {} for symbol, symbolData in self.symbolDataBySymbol.items(): strategies[symbol] = np.array([]) for lookback in symbolData.momp.keys(): strategies[symbol] = np.append(strategies[symbol], symbolData.momp[lookback].Current.Value)
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.
Mark Reeve
Ahhhhh! Thanks Derek - that is exactly what I was looking for ;)
With your help I have now created a GEM Ensemble using the Algorithm Framework, the first one I have attached consists of 12 seperate lookbacks.
Mark Reeve
The second one combines 12 US_Equity momentum filters with 12 relative momentum comparisons - giving an Ensemble of 144 GEM strategies.
Mark Reeve
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!