Mariner Backtesting - TA-LIB Chaikin A/D Line

AD

 real = AD(high, low, close, volume)

Plot

Chaikin A/D Line

Working Example

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

class WE_AD(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
        high = daily_bars.high
        low = daily_bars.low
        # talib expects volume to be a numpy float array
        v = daily_bars.volume
        volume = numpy.asarray(v, dtype=float)

        real = talib.AD(high, low, close, volume)

        # 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['high'] = high
        dict['low'] = low
        dict['close'] = close
        dict['volume'] = volume
        dict['real'] = real
        symbol = 'AD: ' + self.symbol
        print ktgfunc.talib_table(symbol, 1, dict)

Console

MSFT:  2017-02-09 09:30:00.000000
AD: MSFT
Input Output
date high low close volume real
2016-09-16 57.24 56.37 56.87 44571091.00 6072747.93
2016-09-19 57.36 56.47 56.55 20956079.00 -11156148.67
2016-09-20 56.97 56.37 56.43 17384082.00 -25063570.05
2016-09-21 57.46 56.70 57.37 34358572.00 1262326.75
2016-09-22 57.61 57.24 57.43 19822203.00 1796060.00
2016-09-23 57.52 56.99 57.04 19955479.00 -14398632.67
2016-09-26 56.76 56.45 56.52 21688900.00 -26296168.87
2016-09-27 57.67 56.30 57.56 28065078.00 -2710147.82
2016-09-28 57.67 57.28 57.64 20543966.00 14673145.79
2016-09-29 57.78 56.83 57.01 25463618.00 -690574.11
2016-09-30 57.38 56.96 57.21 30450631.00 5681903.19
2016-10-03 57.16 56.68 57.03 19190339.00 14691442.83
2016-10-04 57.21 56.59 56.86 20086050.00 11960666.21
2016-10-05 57.57 56.88 57.25 16726411.00 13389377.62
2016-10-06 57.47 56.90 57.35 16212687.00 22894077.18
2016-10-07 57.59 57.03 57.41 20124844.00 30087288.97
2016-10-10 58.00 57.48 57.65 18196509.00 23784625.82
2016-10-11 57.63 56.51 56.81 26497418.00 11352642.12
2016-10-12 56.89 56.02 56.73 22177464.00 25374532.05
2016-10-13 56.92 55.94 56.54 25313748.00 31154367.33
2016-10-14 57.35 56.74 57.03 27402551.00 30268924.89
2016-10-17 57.07 56.49 56.84 23830115.00 34709429.80
2016-10-18 57.56 57.02 57.27 19150364.00 33455541.01
2016-10-19 57.45 57.01 57.14 22878406.00 24459613.08
2016-10-20 57.13 56.28 56.87 49455856.00 42859321.49
2016-10-21 60.04 59.09 59.26 80023831.00 -8130072.27
2016-10-24 60.59 59.53 60.59 54066978.00 45936905.73
2016-10-25 60.96 60.39 60.58 30797202.00 35671310.08
2016-10-26 60.79 60.06 60.22 25128079.00 21563469.51
2016-10-27 60.42 59.69 59.70 28480469.00 -6149542.23
2016-10-28 60.11 59.18 59.47 33781433.00 -19083882.14
2016-10-31 60.01 59.52 59.52 26434751.00 -45518633.14
2016-11-01 59.62 58.85 59.40 24656951.00 -34950384.54
2016-11-02 59.53 58.90 59.03 22172630.00 -47974726.62
2016-11-03 59.24 58.71 58.81 21737488.00 -61511350.62
2016-11-04 58.88 58.13 58.32 28698150.00 -75862165.85
2016-11-07 60.11 59.38 60.01 31664948.00 -52753242.07
2016-11-08 60.37 59.75 60.06 22935355.00 -52393937.82
2016-11-09 60.18 58.80 59.77 49736785.00 -32716687.23
2016-11-10 60.08 57.24 58.31 57822638.00 -47279233.58
2016-11-11 58.72 57.62 58.62 38767843.00 -15237283.08
2016-11-14 58.68 56.90 57.73 41578422.00 -18009213.36
2016-11-15 59.49 58.31 58.87 35904127.00 -19995468.55
2016-11-16 59.66 54.27 59.65 27438882.00 7341616.49
2016-11-17 60.95 59.97 60.64 32132728.00 19248590.92
2016-11-18 61.14 60.30 60.35 27686736.00 -5142155.97
2016-11-21 60.97 60.42 60.86 19652595.00 6649401.03
2016-11-22 61.26 60.81 61.12 23206602.00 15575017.18
2016-11-23 61.10 60.25 60.40 21936368.00 1380989.37
2016-11-25 60.53 60.13 60.53 8410638.00 9791627.37
2016-11-28 61.02 60.21 60.61 20733011.00 9535707.66
2016-11-29 61.41 60.52 61.09 22367255.00 15818648.77
2016-11-30 61.18 60.22 60.26 34677272.00 -15624605.62
2016-12-01 60.15 58.94 59.20 34542646.00 -35099302.72
2016-12-02 59.47 58.80 59.25 25515890.00 -26340159.97
2016-12-05 60.58 59.56 60.22 23569552.00 -19556667.17
2016-12-06 60.46 59.80 59.95 20027055.00 -30480420.64
2016-12-07 61.38 59.80 61.37 30808969.00 -61521.45
2016-12-08 61.58 60.84 61.01 21222039.00 -11533021.02
2016-12-09 61.99 61.12 61.97 27349357.00 14551599.34
2016-12-12 62.30 61.72 62.17 20198516.00 25695502.80
2016-12-13 63.42 62.24 62.98 35721348.00 34777205.36
2016-12-14 63.45 62.53 62.68 30352925.00 14322052.64
2016-12-15 63.15 62.30 62.58 27669868.00 4807150.06
2016-12-16 62.95 62.12 62.30 42453675.00 -18834944.49
2016-12-19 63.77 62.42 63.62 34338219.00 7872494.49
2016-12-20 63.80 63.03 63.54 26028558.00 16436790.87
2016-12-21 63.70 63.12 63.54 17097365.00 24101165.68
2016-12-22 64.10 63.40 63.55 22176697.00 11178087.75
2016-12-23 63.54 62.80 63.24 12404739.00 13524978.66
2016-12-27 64.07 63.21 63.28 11763173.00 3676731.09
2016-12-28 63.40 62.83 62.99 14665097.00 -2755332.44
2016-12-29 63.20 62.73 62.90 10250582.00 -5590532.54
2016-12-30 62.99 62.03 62.14 25579908.00 -25308363.46
2017-01-03 62.84 62.12 62.58 17452390.00 -20548536.09
2017-01-04 62.75 62.12 62.30 21340044.00 -29694269.23
2017-01-05 62.66 62.03 62.30 24876968.00 -33248121.80
2017-01-06 63.15 62.04 62.84 20154615.00 -24351083.18
2017-01-09 63.08 62.54 62.64 20382734.00 -37184784.43
2017-01-10 63.07 62.28 62.62 18594565.00 -39773912.44
2017-01-11 63.23 62.43 63.19 21517335.00 -20408362.25
2017-01-12 63.40 61.95 62.61 20968328.00 -22288295.76
2017-01-13 62.87 62.35 62.70 19422310.00 -15311341.07
2017-01-17 62.70 62.03 62.53 20664147.00 -5133568.94
2017-01-18 62.70 62.12 62.50 20072514.00 1095822.85
2017-01-19 62.98 62.19 62.30 18451787.00 -12419837.87
2017-01-20 62.82 62.37 62.74 30338462.00 7131901.18
2017-01-23 63.12 62.57 62.96 23097906.00 17037091.08
2017-01-24 63.74 62.94 63.52 21658284.00 26980852.45
2017-01-25 64.10 63.45 63.68 24660251.00 19772498.11
2017-01-26 64.54 63.55 64.27 43633281.00 39927456.70
2017-01-27 65.91 64.89 65.78 44826340.00 73327093.43
2017-01-30 65.79 64.80 65.13 31731271.00 62749677.05
2017-01-31 65.15 64.26 64.65 25270674.00 59626315.85
2017-02-01 64.62 63.47 63.58 39671568.00 27544123.33
2017-02-02 63.41 62.75 63.17 45828988.00 40042697.44
2017-02-03 63.70 63.07 63.68 30301759.00 68420494.46
2017-02-06 63.65 63.14 63.64 20021886.00 87657044.02
2017-02-07 63.78 63.23 63.43 20277228.00 82126967.64
2017-02-08 63.81 63.22 63.34 18099993.00 71389616.22