Closed rajach closed 4 years ago
Try this:
engine.add(factors.Returns(win=252).demean(groupby=sec).rank().zscore(), 'momentum')
Currently groupby does not support factor data.
Thank you. To avoid the value error I used:
{asst:sec.get(asst, -1) for asst in df.index.get_level_values('asset').unique() }
Calling demean with a groupby column name gives error. Is this the right way to use it?
Uncommenting the momentum factor (middle line) above gives:
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) ..\spectre_env\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 2645 try: -> 2646 return self._engine.get_loc(key) 2647 except KeyError: pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() KeyError: 'sector' During handling of the above exception, another exception occurred: ......