MMI: Market Meanness Index
-
Hi,
To develop momentum strategies, its relevant to understand is the trend is strong or a mean reversion is coming. Tipically, Hurst Exponent claims to work, but unfortunally I dont see value on this indicator with my data (latinamerican mutual funds).
Finally I found the MMI as an alternative with better results to implement in my strategies. You can get the explanation and several backtestings on https://financial-hacker.com/the-market-meanness-index/ (ps: you can read there with 55 is important)
This is my implementation on backtrader, pls your feedback is welcome
class MMI(bt.Indicator): lines = ('mmi',) plotinfo = dict(plothlines=[55]) params = dict(period=100,) def __init__(self): self.m = Average(self.data.close, period = self.p.period) #replace with median def next(self): nl = 0 nh = 0 for j in range(self.p.period-1): if j < 1: continue i=j * -1 if (self.data.close[i] > self.m[0]) and (self.data.close[i] > self.data.close[i-1]) : nl += 1 if (self.data.close[i] < self.m[0]) and (self.data.close[i] < self.data.close[i-1]) : nh += 1 self.l.mmi[0] = 100.0 * (nl+nh)/(self.p.period - 1)
-
Great strategy! Tried to replace with moving average and more on
__init__
instead ofnext
.
The results swift to 60-63 instead of ~55. Not sure is it because of any calculation error....def __init__(self): self.l.m = bt.ind.MovAv.Simple(self.data.close, period=self.p.period) #replace with median self.l.nl=bt.And(self.data.close>self.l.m,self.data.close>self.data.close(-1)) self.l.nh=bt.And(self.data.close<self.l.m,self.data.close<self.data.close(-1)) self.l.upSum = bt.ind.SumN(self.l.nl, period=self.p.period) self.l.downSum = bt.ind.SumN(self.l.nh, period=self.p.period) self.l.mmi= 100.0 * (self.l.upSum+self.l.downSum)/(self.p.period - 1)