Hi Quantopian Community,
I am wondering how to combine factors to put through alphalens i.e. Value + Momentum example below.
I have attached a code snippet for the momentum & value factors & my weak attempt to combine them.
class Momentum(CustomFactor):
inputs = [USEquityPricing.close]
window_length = 252
def compute(self, today, assets, out, close):
out[:] = close[-20] / close[0]
class Value(CustomFactor):
inputs = [USEquityPricing.close,
morningstar.valuation_ratios.fcf_per_share]
window_length = 1
def compute(self, today, assets, out, close, fcf):
out[:] = close[-1] / fcf[-1]
class Combined(CustomFactor):
inputs = [Momentum,
morningstar.valuation_ratios.fcf_yield]
window_length = 1
def compute(self, today, assets, out, Momentum, fcf):
value_table = pd.DataFrame(index=assets)
value_table["momentum"] = Momentum[-1]
value_table["fcf"] = fcf[-1]
value_rank = value_table.rank("fcf").mean(axis=1)
mom_rank = value_table.rank("momentum").mean(axis=1)
out[:] = value_rank + mom_rank