Hey girls and guys,
I am new to the community and love it so far. I am now trying to implement some CustomFactors, however, there is a challenge, I don't really know how to approach maybe somebody could help.
Basically what I am trying to do ist to program the Money Flow Index as described in here: MFI
class MoneyFlowIndex(CustomFactor):
inputs = [USEquityPricing.high, USEquityPricing.low, USEquityPricing.close, USEquityPricing.volume]
window_length = 20
def compute(self, today, asset_ids, out, high, low, close, volume):
typical_price = (high + low + close)/3
money_flow = typical_price * volume
pos_money_flow = 0
neg_money_flow = 0
for i in range(1, self.window_length):
if money_flow[i-1] - money_flow[i] > 0:
pos_money_flow += money_flow[i]
elif money_flow[i-1] - money_flow[i] < 0:
neg_money_flow += money_flow[i]
money_ration = pos_money_flow/neg_money_flow
out[:] = 100 - 100/(1 + money_ratio)
There are basically two problems I see. First of all I would need a window which goes one further than the window size to calculate all the changes.
Second, my iteration over the data rows doesn't work out and I probably have to use a filter I only have limited experience. Sorry for the beginner questions but the pipeline really needs some getting used to.
Thanks
Benjamin