STOCH
slowk, slowd = STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0)
Plot
Working Example
from cloudquant.interfaces import Strategy
from collections import OrderedDict
import ktgfunc
import talib
class WE_STOCH(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
slowk, slowd = talib.STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_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['high'] = high
dict['low'] = low
dict['close'] = close
dict['slowk'] = slowk
dict['slowd'] = slowd
symbol = 'STOCH: ' + self.symbol
print ktgfunc.talib_table(symbol, 2, dict)
Console
MSFT: 2017-02-09 09:30:00.000000
STOCH: MSFT | |||||
---|---|---|---|---|---|
Input | Output | ||||
date | high | low | close | slowk | slowd |
2016-09-16 | 57.24 | 56.37 | 56.87 | nan | nan |
2016-09-19 | 57.36 | 56.47 | 56.55 | nan | nan |
2016-09-20 | 56.97 | 56.37 | 56.43 | nan | nan |
2016-09-21 | 57.46 | 56.70 | 57.37 | nan | nan |
2016-09-22 | 57.61 | 57.24 | 57.43 | nan | nan |
2016-09-23 | 57.52 | 56.99 | 57.04 | nan | nan |
2016-09-26 | 56.76 | 56.45 | 56.52 | nan | nan |
2016-09-27 | 57.67 | 56.30 | 57.56 | nan | nan |
2016-09-28 | 57.67 | 57.28 | 57.64 | 67.28 | 56.92 |
2016-09-29 | 57.78 | 56.83 | 57.01 | 79.40 | 66.50 |
2016-09-30 | 57.38 | 56.96 | 57.21 | 69.33 | 72.00 |
2016-10-03 | 57.16 | 56.68 | 57.03 | 53.29 | 67.34 |
2016-10-04 | 57.21 | 56.59 | 56.86 | 44.68 | 55.76 |
2016-10-05 | 57.57 | 56.88 | 57.25 | 42.72 | 46.90 |
2016-10-06 | 57.47 | 56.90 | 57.35 | 52.08 | 46.49 |
2016-10-07 | 57.59 | 57.03 | 57.41 | 71.96 | 55.59 |
2016-10-10 | 58.00 | 57.48 | 57.65 | 78.44 | 67.49 |
2016-10-11 | 57.63 | 56.51 | 56.81 | 59.18 | 69.86 |
2016-10-12 | 56.89 | 56.02 | 56.73 | 43.67 | 60.43 |
2016-10-13 | 56.92 | 55.94 | 56.54 | 28.28 | 43.71 |
2016-10-14 | 57.35 | 56.74 | 57.03 | 39.36 | 37.10 |
2016-10-17 | 57.07 | 56.49 | 56.84 | 45.16 | 37.60 |
2016-10-18 | 57.56 | 57.02 | 57.27 | 62.95 | 49.16 |
2016-10-19 | 57.45 | 57.01 | 57.14 | 70.04 | 59.38 |
2016-10-20 | 57.13 | 56.28 | 56.87 | 67.66 | 66.88 |
2016-10-21 | 60.04 | 59.09 | 59.26 | 66.54 | 68.08 |
2016-10-24 | 60.59 | 59.53 | 60.59 | 75.02 | 69.74 |
2016-10-25 | 60.96 | 60.39 | 60.58 | 90.36 | 77.31 |
2016-10-26 | 60.79 | 60.06 | 60.22 | 92.07 | 85.82 |
2016-10-27 | 60.42 | 59.69 | 59.70 | 69.62 | 84.02 |
2016-10-28 | 60.11 | 59.18 | 59.47 | 44.37 | 68.69 |
2016-10-31 | 60.01 | 59.52 | 59.52 | 22.61 | 45.53 |
2016-11-01 | 59.62 | 58.85 | 59.40 | 21.13 | 29.37 |
2016-11-02 | 59.53 | 58.90 | 59.03 | 19.53 | 21.09 |
2016-11-03 | 59.24 | 58.71 | 58.81 | 15.56 | 18.74 |
2016-11-04 | 58.88 | 58.13 | 58.32 | 9.49 | 14.86 |
2016-11-07 | 60.11 | 59.38 | 60.01 | 37.36 | 20.81 |
2016-11-08 | 60.37 | 59.75 | 60.06 | 63.76 | 36.87 |
2016-11-09 | 60.18 | 58.80 | 59.77 | 84.76 | 61.96 |
2016-11-10 | 60.08 | 57.24 | 58.31 | 64.42 | 70.98 |
2016-11-11 | 58.72 | 57.62 | 58.62 | 50.36 | 66.51 |
2016-11-14 | 58.68 | 56.90 | 57.73 | 34.03 | 49.60 |
2016-11-15 | 59.49 | 58.31 | 58.87 | 42.73 | 42.37 |
2016-11-16 | 59.66 | 54.27 | 59.65 | 58.86 | 45.21 |
2016-11-17 | 60.95 | 59.97 | 60.64 | 82.65 | 61.41 |
2016-11-18 | 61.14 | 60.30 | 60.35 | 92.13 | 77.88 |
2016-11-21 | 60.97 | 60.42 | 60.86 | 93.26 | 89.35 |
2016-11-22 | 61.26 | 60.81 | 61.12 | 94.14 | 93.18 |
2016-11-23 | 61.10 | 60.25 | 60.40 | 75.84 | 87.75 |
2016-11-25 | 60.53 | 60.13 | 60.53 | 55.66 | 75.21 |
2016-11-28 | 61.02 | 60.21 | 60.61 | 37.16 | 56.22 |
2016-11-29 | 61.41 | 60.52 | 61.09 | 50.96 | 47.93 |
2016-11-30 | 61.18 | 60.22 | 60.26 | 42.54 | 43.55 |
2016-12-01 | 60.15 | 58.94 | 59.20 | 31.95 | 41.82 |
2016-12-02 | 59.47 | 58.80 | 59.25 | 12.70 | 29.07 |
2016-12-05 | 60.58 | 59.56 | 60.22 | 27.45 | 24.04 |
2016-12-06 | 60.46 | 59.80 | 59.95 | 39.99 | 26.71 |
2016-12-07 | 61.38 | 59.80 | 61.37 | 67.45 | 44.96 |
2016-12-08 | 61.58 | 60.84 | 61.01 | 75.81 | 61.08 |
2016-12-09 | 61.99 | 61.12 | 61.97 | 92.76 | 78.67 |
2016-12-12 | 62.30 | 61.72 | 62.17 | 91.16 | 86.58 |
2016-12-13 | 63.42 | 62.24 | 62.98 | 93.94 | 92.62 |
2016-12-14 | 63.45 | 62.53 | 62.68 | 84.38 | 89.83 |
2016-12-15 | 63.15 | 62.30 | 62.58 | 73.64 | 83.99 |
2016-12-16 | 62.95 | 62.12 | 62.30 | 55.53 | 71.19 |
2016-12-19 | 63.77 | 62.42 | 63.62 | 62.35 | 63.84 |
2016-12-20 | 63.80 | 63.03 | 63.54 | 69.68 | 62.52 |
2016-12-21 | 63.70 | 63.12 | 63.54 | 86.69 | 72.91 |
2016-12-22 | 64.10 | 63.40 | 63.55 | 80.48 | 78.95 |
2016-12-23 | 63.54 | 62.80 | 63.24 | 68.56 | 78.58 |
2016-12-27 | 64.07 | 63.21 | 63.28 | 52.67 | 67.24 |
2016-12-28 | 63.40 | 62.83 | 62.99 | 33.45 | 51.56 |
2016-12-29 | 63.20 | 62.73 | 62.90 | 21.32 | 35.81 |
2016-12-30 | 62.99 | 62.03 | 62.14 | 10.81 | 21.86 |
2017-01-03 | 62.84 | 62.12 | 62.58 | 14.92 | 15.68 |
2017-01-04 | 62.75 | 62.12 | 62.30 | 17.35 | 14.36 |
2017-01-05 | 62.66 | 62.03 | 62.30 | 23.25 | 18.51 |
2017-01-06 | 63.15 | 62.04 | 62.84 | 38.37 | 26.32 |
2017-01-09 | 63.08 | 62.54 | 62.64 | 49.95 | 37.19 |
2017-01-10 | 63.07 | 62.28 | 62.62 | 59.82 | 49.38 |
2017-01-11 | 63.23 | 62.43 | 63.19 | 67.94 | 59.24 |
2017-01-12 | 63.40 | 61.95 | 62.61 | 64.95 | 64.24 |
2017-01-13 | 62.87 | 62.35 | 62.70 | 64.64 | 65.84 |
2017-01-17 | 62.70 | 62.03 | 62.53 | 45.75 | 58.45 |
2017-01-18 | 62.70 | 62.12 | 62.50 | 43.22 | 51.20 |
2017-01-19 | 62.98 | 62.19 | 62.30 | 34.02 | 41.00 |
2017-01-20 | 62.82 | 62.37 | 62.74 | 45.60 | 40.95 |
2017-01-23 | 63.12 | 62.57 | 62.96 | 61.51 | 47.04 |
2017-01-24 | 63.74 | 62.94 | 63.52 | 82.36 | 63.15 |
2017-01-25 | 64.10 | 63.45 | 63.68 | 83.43 | 75.76 |
2017-01-26 | 64.54 | 63.55 | 64.27 | 84.13 | 83.31 |
2017-01-27 | 65.91 | 64.89 | 65.78 | 87.27 | 84.94 |
2017-01-30 | 65.79 | 64.80 | 65.13 | 85.87 | 85.76 |
2017-01-31 | 65.15 | 64.26 | 64.65 | 72.88 | 82.01 |
2017-02-01 | 64.62 | 63.47 | 63.58 | 42.34 | 67.03 |
2017-02-02 | 63.41 | 62.75 | 63.17 | 22.19 | 45.80 |
2017-02-03 | 63.70 | 63.07 | 63.68 | 16.13 | 26.89 |
2017-02-06 | 63.65 | 63.14 | 63.64 | 26.99 | 21.77 |
2017-02-07 | 63.78 | 63.23 | 63.43 | 34.68 | 25.93 |
2017-02-08 | 63.81 | 63.22 | 63.34 | 43.04 | 34.90 |