Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    MMI: Market Meanness Index

    Indicators/Strategies/Analyzers
    2
    2
    505
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mariano Volpedo
      Mariano Volpedo last edited by

      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)
      B 1 Reply Last reply Reply Quote 4
      • B
        barton05 @Mariano Volpedo last edited by

        @Mariano-Volpedo

        Great strategy! Tried to replace with moving average and more on __init__ instead of next.
        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)
        
        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors