Hi All,
For anyones interest I have the original notebook to work with the changes accessing fundamental data via pipeline and a few depreciated functions
I am interested in making a factor for pipeline out of one of the factors that is included being the distance ranking function (extracted below), however I am struggling to get it working.
Any suggestions of how to put this into a custom factor
scores = pd.Series(index=asset.index)
for date in rolling_means.index:
mavg_values = rolling_means.loc[date]
ranking = stats.rankdata(mavg_values.values)
#print mavg_values.values.round(2)
#print ranking
d = distance.hamming(ranking, range(1, 11))
#print d
scores[date] = d
My attempt
class distance_rank(CustomFactor):
# this class generates the MACD as a Percentage
inputs = [USEP.close]
window_length = 90
def compute(self, today, assets, out, close):
anynan = columnwise_anynan(close)
for col_ix, have_nans in enumerate(anynan):
if have_nans:
out[col_ix] = nan
continue
ema_3 = talib.EMA(close[:, col_ix], timeperiod=3)
ema_5 = talib.EMA(close[:, col_ix], timeperiod=5)
ema_7 = talib.EMA(close[:, col_ix], timeperiod=7)
ema_10 = talib.EMA(close[:, col_ix], timeperiod=10)
ema_15 = talib.EMA(close[:, col_ix], timeperiod=15)
ema_30 = talib.EMA(close[:, col_ix], timeperiod=30)
ema_40 = talib.EMA(close[:, col_ix], timeperiod=40)
ema_50 = talib.EMA(close[:, col_ix], timeperiod=50)
ema_60 = talib.EMA(close[:, col_ix], timeperiod=60)
df = np.array([ema_3[-1],ema_5[-1],ema_7[-1],ema_10[-1],ema_15[-1],ema_30[-1],ema_40[-1],ema_50[-1],ema_60[-1]])
#df = pd.Series([ema_3,ema_5,ema_7,ema_10,ema_15,ema_30,ema_40,ema_50,ema_60])
ranking_short = rankdata(df)
d = distance.hamming(ranking_short, range(1, 11))
#out[col_ix] = ema_3[-1]
#out[col_ix] = ranking_short[-1]
out[col_ix] = d[-1]