Mariner Backtesting - TA-LIB MESA Adaptive Moving Average

MAMA

 

 mama, fama = MAMA(close, fastlimit=0, slowlimit=0)

Plot

MESA Adaptive Moving Average

Working Example

from cloudquant.interfaces import Strategy
from collections import OrderedDict
import ktgfunc
import talib

class WE_MAMA(Strategy):

    def on_start(self, md, order, service, account):
        # symbol and timestamp
        print(self.symbol + ":  " + service.time_to_string(service.system_time))
        daily_bars = md.bar.daily(start=-100)
        close = daily_bars.close
        mama, fama = talib.MAMA(close)

        # get the date values
        dates = service._context.market._storage.market_hours.keys()
        dateList = []
        for date in dates:
           dateList.append(str(date.strftime('%Y-%m-%d')))
        dates = sorted(dateList, reverse=True)[1:101]
        dates.sort()

        dict = OrderedDict()
        dict['date'] = dates
        dict['close'] = close
        dict['mama'] = mama
        dict['fama'] = fama
        symbol = 'MAMA: ' + self.symbol
        print ktgfunc.talib_table(symbol, 2, dict)

Console

MSFT:  2017-02-09 09:30:00.000000
MAMA: MSFT
Input Output
date close mama fama
2016-09-16 56.87 nan nan
2016-09-19 56.55 nan nan
2016-09-20 56.43 nan nan
2016-09-21 57.37 nan nan
2016-09-22 57.43 nan nan
2016-09-23 57.04 nan nan
2016-09-26 56.52 nan nan
2016-09-27 57.56 nan nan
2016-09-28 57.64 nan nan
2016-09-29 57.01 nan nan
2016-09-30 57.21 nan nan
2016-10-03 57.03 nan nan
2016-10-04 56.86 nan nan
2016-10-05 57.25 nan nan
2016-10-06 57.35 nan nan
2016-10-07 57.41 nan nan
2016-10-10 57.65 nan nan
2016-10-11 56.81 nan nan
2016-10-12 56.73 nan nan
2016-10-13 56.54 nan nan
2016-10-14 57.03 nan nan
2016-10-17 56.84 nan nan
2016-10-18 57.27 nan nan
2016-10-19 57.14 nan nan
2016-10-20 56.87 nan nan
2016-10-21 59.26 nan nan
2016-10-24 60.59 nan nan
2016-10-25 60.58 nan nan
2016-10-26 60.22 nan nan
2016-10-27 59.70 nan nan
2016-10-28 59.47 nan nan
2016-10-31 59.52 nan nan
2016-11-01 59.40 59.34 53.50
2016-11-02 59.03 59.33 53.65
2016-11-03 58.81 59.30 53.79
2016-11-04 58.32 58.81 55.04
2016-11-07 60.01 58.87 55.14
2016-11-08 60.06 58.93 55.23
2016-11-09 59.77 58.97 55.33
2016-11-10 58.31 58.94 55.42
2016-11-11 58.62 58.92 55.50
2016-11-14 57.73 58.33 56.21
2016-11-15 58.87 58.35 56.26
2016-11-16 59.65 58.42 56.32
2016-11-17 60.64 59.53 57.12
2016-11-18 60.35 59.57 57.18
2016-11-21 60.86 59.63 57.24
2016-11-22 61.12 59.71 57.30
2016-11-23 60.40 60.05 57.99
2016-11-25 60.53 60.08 58.04
2016-11-28 60.61 60.10 58.10
2016-11-29 61.09 60.15 58.15
2016-11-30 60.26 60.16 58.20
2016-12-01 59.20 60.11 58.25
2016-12-02 59.25 59.68 58.60
2016-12-05 60.22 59.71 58.63
2016-12-06 59.95 59.83 58.93
2016-12-07 61.37 59.94 58.97
2016-12-08 61.01 59.99 58.99
2016-12-09 61.97 60.09 59.02
2016-12-12 62.17 60.20 59.05
2016-12-13 62.98 61.59 59.68
2016-12-14 62.68 61.64 59.73
2016-12-15 62.58 61.69 59.78
2016-12-16 62.30 61.72 59.83
2016-12-19 63.62 61.81 59.88
2016-12-20 63.54 61.90 59.93
2016-12-21 63.54 61.98 59.98
2016-12-22 63.55 62.06 60.03
2016-12-23 63.24 62.65 60.69
2016-12-27 63.28 62.97 61.26
2016-12-28 62.99 62.97 61.30
2016-12-29 62.90 62.96 61.34
2016-12-30 62.14 62.92 61.38
2017-01-03 62.58 62.90 61.42
2017-01-04 62.30 62.60 61.72
2017-01-05 62.30 62.59 61.74
2017-01-06 62.84 62.61 61.77
2017-01-09 62.64 62.61 61.79
2017-01-10 62.62 62.61 61.81
2017-01-11 63.19 62.64 61.83
2017-01-12 62.61 62.64 61.85
2017-01-13 62.70 62.67 62.05
2017-01-17 62.53 62.66 62.07
2017-01-18 62.50 62.58 62.20
2017-01-19 62.30 62.57 62.21
2017-01-20 62.74 62.58 62.22
2017-01-23 62.96 62.77 62.35
2017-01-24 63.52 62.81 62.37
2017-01-25 63.68 62.85 62.38
2017-01-26 64.27 62.92 62.39
2017-01-27 65.78 64.35 62.88
2017-01-30 65.13 64.39 62.92
2017-01-31 64.65 64.40 62.96
2017-02-01 63.58 64.36 62.99
2017-02-02 63.17 64.16 63.09
2017-02-03 63.68 64.14 63.12
2017-02-06 63.64 64.11 63.14
2017-02-07 63.43 64.08 63.16
2017-02-08 63.34 63.71 63.30