Hi Everyone,
I was thinking about implementing something like that in Pipeline (According to what I understood, I think Pipeline would be the way to go for this algo), but I am totally stuck as I am rather new to Quantopian and Python:
Compute 2 mean reversion factors:
-Compute the 4 weeks industry relative return (for instance over the 11 Morningstar sectors)
-Percent above 100 days low with a 10 days lag
Compute 2 momentum factors:
-Compute the moving average over a 60 days window with a 10 days lag (i.e. say we are 16 October, I'd like to compute the the MA over 60 days until 2 October (10 trading days before 16 October).
For this one I tried something like that but could make it work:
class Factor1(CustomFactor):
# Pre-declare inputs and window_length
inputs = [USEquityPricing.close, ]
window_length = 70
# Compute factor1 value
def compute(self, today, assets, out, close):
x=close[0:59]
out[:] = x.apply(talib.SMA, timeperiod=60)
-compute the slope of the 200 days trend line with a 10 days lag
Then I would like to rank according to a "z-score" for each factor (z-score= (Factor_value_of_stock_i-Average_Factor_value)/(Std dev of Factor value)). In the end, I would actually like to compute a "double layer" score, first over each factor category (momentum/mean reversion) in order to put more weight on one factor over the other within the category (for instance score_mean_reversion=0.7*score_industry_relative_return+0.3*Percent_above_100_days_low), and then over the 2 categories (total score=.6*score_momentum+.4*score_mean_reversion)
Does anyone have an idea about how to implement that in Pipeline (is it possible?). My ultimate goal would be to add a few more factors (say try with some fundamentals as well).
Hope my explanation is clear enough. Thanks in advance for any help.
L