SUB
real = SUB(high, low)
Plot
Working Example
from cloudquant.interfaces import Strategy
from collections import OrderedDict
import ktgfunc
import talib
class WE_SUB(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)
high = daily_bars.high
low = daily_bars.low
real = talib.SUB(high, low)
# 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['real'] = real
symbol = 'SUB: ' + self.symbol
print ktgfunc.talib_table(symbol, 1, dict)
Console
MSFT: 2017-02-09 09:30:00.000000
SUB: MSFT | |||
---|---|---|---|
Input | Output | ||
date | high | low | real |
2016-09-16 | 57.24 | 56.37 | 0.87 |
2016-09-19 | 57.36 | 56.47 | 0.89 |
2016-09-20 | 56.97 | 56.37 | 0.60 |
2016-09-21 | 57.46 | 56.70 | 0.76 |
2016-09-22 | 57.61 | 57.24 | 0.37 |
2016-09-23 | 57.52 | 56.99 | 0.53 |
2016-09-26 | 56.76 | 56.45 | 0.31 |
2016-09-27 | 57.67 | 56.30 | 1.37 |
2016-09-28 | 57.67 | 57.28 | 0.39 |
2016-09-29 | 57.78 | 56.83 | 0.95 |
2016-09-30 | 57.38 | 56.96 | 0.43 |
2016-10-03 | 57.16 | 56.68 | 0.49 |
2016-10-04 | 57.21 | 56.59 | 0.62 |
2016-10-05 | 57.57 | 56.88 | 0.70 |
2016-10-06 | 57.47 | 56.90 | 0.58 |
2016-10-07 | 57.59 | 57.03 | 0.56 |
2016-10-10 | 58.00 | 57.48 | 0.52 |
2016-10-11 | 57.63 | 56.51 | 1.12 |
2016-10-12 | 56.89 | 56.02 | 0.86 |
2016-10-13 | 56.92 | 55.94 | 0.98 |
2016-10-14 | 57.35 | 56.74 | 0.62 |
2016-10-17 | 57.07 | 56.49 | 0.59 |
2016-10-18 | 57.56 | 57.02 | 0.53 |
2016-10-19 | 57.45 | 57.01 | 0.44 |
2016-10-20 | 57.13 | 56.28 | 0.85 |
2016-10-21 | 60.04 | 59.09 | 0.96 |
2016-10-24 | 60.59 | 59.53 | 1.06 |
2016-10-25 | 60.96 | 60.39 | 0.57 |
2016-10-26 | 60.79 | 60.06 | 0.73 |
2016-10-27 | 60.42 | 59.69 | 0.74 |
2016-10-28 | 60.11 | 59.18 | 0.93 |
2016-10-31 | 60.01 | 59.52 | 0.50 |
2016-11-01 | 59.62 | 58.85 | 0.76 |
2016-11-02 | 59.53 | 58.90 | 0.63 |
2016-11-03 | 59.24 | 58.71 | 0.53 |
2016-11-04 | 58.88 | 58.13 | 0.75 |
2016-11-07 | 60.11 | 59.38 | 0.74 |
2016-11-08 | 60.37 | 59.75 | 0.63 |
2016-11-09 | 60.18 | 58.80 | 1.38 |
2016-11-10 | 60.08 | 57.24 | 2.84 |
2016-11-11 | 58.72 | 57.62 | 1.10 |
2016-11-14 | 58.68 | 56.90 | 1.79 |
2016-11-15 | 59.49 | 58.31 | 1.18 |
2016-11-16 | 59.66 | 54.27 | 5.39 |
2016-11-17 | 60.95 | 59.97 | 0.99 |
2016-11-18 | 61.14 | 60.30 | 0.84 |
2016-11-21 | 60.97 | 60.42 | 0.55 |
2016-11-22 | 61.26 | 60.81 | 0.45 |
2016-11-23 | 61.10 | 60.25 | 0.85 |
2016-11-25 | 60.53 | 60.13 | 0.40 |
2016-11-28 | 61.02 | 60.21 | 0.81 |
2016-11-29 | 61.41 | 60.52 | 0.89 |
2016-11-30 | 61.18 | 60.22 | 0.97 |
2016-12-01 | 60.15 | 58.94 | 1.22 |
2016-12-02 | 59.47 | 58.80 | 0.67 |
2016-12-05 | 60.58 | 59.56 | 1.02 |
2016-12-06 | 60.46 | 59.80 | 0.66 |
2016-12-07 | 61.38 | 59.80 | 1.58 |
2016-12-08 | 61.58 | 60.84 | 0.74 |
2016-12-09 | 61.99 | 61.12 | 0.87 |
2016-12-12 | 62.30 | 61.72 | 0.58 |
2016-12-13 | 63.42 | 62.24 | 1.18 |
2016-12-14 | 63.45 | 62.53 | 0.92 |
2016-12-15 | 63.15 | 62.30 | 0.85 |
2016-12-16 | 62.95 | 62.12 | 0.83 |
2016-12-19 | 63.77 | 62.42 | 1.35 |
2016-12-20 | 63.80 | 63.03 | 0.77 |
2016-12-21 | 63.70 | 63.12 | 0.58 |
2016-12-22 | 64.10 | 63.40 | 0.69 |
2016-12-23 | 63.54 | 62.80 | 0.74 |
2016-12-27 | 64.07 | 63.21 | 0.86 |
2016-12-28 | 63.40 | 62.83 | 0.57 |
2016-12-29 | 63.20 | 62.73 | 0.47 |
2016-12-30 | 62.99 | 62.03 | 0.96 |
2017-01-03 | 62.84 | 62.12 | 0.72 |
2017-01-04 | 62.75 | 62.12 | 0.63 |
2017-01-05 | 62.66 | 62.03 | 0.63 |
2017-01-06 | 63.15 | 62.04 | 1.11 |
2017-01-09 | 63.08 | 62.54 | 0.54 |
2017-01-10 | 63.07 | 62.28 | 0.79 |
2017-01-11 | 63.23 | 62.43 | 0.80 |
2017-01-12 | 63.40 | 61.95 | 1.45 |
2017-01-13 | 62.87 | 62.35 | 0.52 |
2017-01-17 | 62.70 | 62.03 | 0.67 |
2017-01-18 | 62.70 | 62.12 | 0.58 |
2017-01-19 | 62.98 | 62.19 | 0.78 |
2017-01-20 | 62.82 | 62.37 | 0.45 |
2017-01-23 | 63.12 | 62.57 | 0.55 |
2017-01-24 | 63.74 | 62.94 | 0.80 |
2017-01-25 | 64.10 | 63.45 | 0.65 |
2017-01-26 | 64.54 | 63.55 | 0.99 |
2017-01-27 | 65.91 | 64.89 | 1.02 |
2017-01-30 | 65.79 | 64.80 | 0.99 |
2017-01-31 | 65.15 | 64.26 | 0.89 |
2017-02-01 | 64.62 | 63.47 | 1.15 |
2017-02-02 | 63.41 | 62.75 | 0.66 |
2017-02-03 | 63.70 | 63.07 | 0.63 |
2017-02-06 | 63.65 | 63.14 | 0.51 |
2017-02-07 | 63.78 | 63.23 | 0.55 |
2017-02-08 | 63.81 | 63.22 | 0.59 |