Mariner Backtesting - TA-LIB Stochastic Relative Strength Index

STOCHRSI

 

 fastk, fastd = STOCHRSI(close, timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0)

Plot

Stochastic Relative Strength Index

Working Example

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

class WE_STOCHRSI(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
        fastk, fastd = talib.STOCHRSI(close, timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0)

        # 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['fastk'] = fastk
        dict['fastd'] = fastd
        symbol = 'STOCHRSI: ' + self.symbol
        print ktgfunc.talib_table(symbol, 2, dict)

Console

MSFT:  2017-02-09 09:30:00.000000
STOCHRSI: MSFT
Input Output
date close fastk fastd
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 45.92 15.31
2016-10-17 56.84 61.21 35.71
2016-10-18 57.27 100.00 69.04
2016-10-19 57.14 81.27 80.83
2016-10-20 56.87 0.00 60.42
2016-10-21 59.26 100.00 60.42
2016-10-24 60.59 100.00 66.67
2016-10-25 60.58 99.57 99.86
2016-10-26 60.22 83.80 94.46
2016-10-27 59.70 0.00 61.12
2016-10-28 59.47 0.00 27.93
2016-10-31 59.52 2.72 0.91
2016-11-01 59.40 0.00 0.91
2016-11-02 59.03 0.00 0.91
2016-11-03 58.81 0.00 -0.00
2016-11-04 58.32 0.00 -0.00
2016-11-07 60.01 100.00 33.33
2016-11-08 60.06 100.00 66.67
2016-11-09 59.77 76.59 92.20
2016-11-10 58.31 0.00 58.86
2016-11-11 58.62 15.81 30.80
2016-11-14 57.73 0.00 5.27
2016-11-15 58.87 50.91 22.24
2016-11-16 59.65 100.00 50.30
2016-11-17 60.64 100.00 83.64
2016-11-18 60.35 87.74 95.91
2016-11-21 60.86 100.00 95.91
2016-11-22 61.12 100.00 95.91
2016-11-23 60.40 0.00 66.67
2016-11-25 60.53 12.94 37.65
2016-11-28 60.61 21.28 11.41
2016-11-29 61.09 70.99 35.07
2016-11-30 60.26 0.00 30.76
2016-12-01 59.20 0.00 23.66
2016-12-02 59.25 2.51 0.84
2016-12-05 60.22 48.19 16.90
2016-12-06 59.95 67.06 39.25
2016-12-07 61.37 100.00 71.75
2016-12-08 61.01 78.97 82.01
2016-12-09 61.97 100.00 92.99
2016-12-12 62.17 100.00 92.99
2016-12-13 62.98 100.00 100.00
2016-12-14 62.68 73.19 91.06
2016-12-15 62.58 25.92 66.37
2016-12-16 62.30 0.00 33.04
2016-12-19 63.62 100.00 41.97
2016-12-20 63.54 88.85 62.95
2016-12-21 63.54 88.85 92.57
2016-12-22 63.55 89.65 89.12
2016-12-23 63.24 0.00 59.50
2016-12-27 63.28 7.57 32.41
2016-12-28 62.99 0.00 2.52
2016-12-29 62.90 0.00 2.52
2016-12-30 62.14 0.00 -0.00
2017-01-03 62.58 30.27 10.09
2017-01-04 62.30 10.17 13.48
2017-01-05 62.30 11.47 17.30
2017-01-06 62.84 100.00 40.55
2017-01-09 62.64 53.26 54.91
2017-01-10 62.62 48.43 67.23
2017-01-11 63.19 100.00 67.23
2017-01-12 62.61 0.00 49.48
2017-01-13 62.70 12.71 37.57
2017-01-17 62.53 0.00 4.24
2017-01-18 62.50 0.00 4.24
2017-01-19 62.30 0.00 -0.00
2017-01-20 62.74 100.00 33.33
2017-01-23 62.96 100.00 66.67
2017-01-24 63.52 100.00 100.00
2017-01-25 63.68 100.00 100.00
2017-01-26 64.27 100.00 100.00
2017-01-27 65.78 100.00 100.00
2017-01-30 65.13 43.02 81.01
2017-01-31 64.65 0.00 47.67
2017-02-01 63.58 0.00 14.34
2017-02-02 63.17 0.00 -0.00
2017-02-03 63.68 20.66 6.89
2017-02-06 63.64 26.39 15.68
2017-02-07 63.43 42.55 29.87
2017-02-08 63.34 21.26 30.07