AVGPRICE(open, high, low, close)
AVGPRICE
real = AVGPRICE(open, high, low, close)
Plot
Working Example
from cloudquant.interfaces import Strategy
from collections import OrderedDict
import ktgfunc
import talib
class WE_AVGPRICE(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
open = daily_bars.open
real = talib.AVGPRICE(open, high, low, 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['open'] = open
dict['high'] = high
dict['low'] = low
dict['close'] = close
dict['real'] = real
symbol = 'AVGPRICE: ' + self.symbol
print ktgfunc.talib_table(symbol, 1, dict)
Console
MSFT: 2017-02-09 09:30:00.000000
AVGPRICE: MSFT | |||||
---|---|---|---|---|---|
Input | Output | ||||
date | open | high | low | close | real |
2016-09-16 | 57.24 | 57.24 | 56.37 | 56.87 | 56.93 |
2016-09-19 | 56.89 | 57.36 | 56.47 | 56.55 | 56.82 |
2016-09-20 | 56.97 | 56.97 | 56.37 | 56.43 | 56.68 |
2016-09-21 | 57.12 | 57.46 | 56.70 | 57.37 | 57.16 |
2016-09-22 | 57.53 | 57.61 | 57.24 | 57.43 | 57.45 |
2016-09-23 | 57.48 | 57.52 | 56.99 | 57.04 | 57.26 |
2016-09-26 | 56.70 | 56.76 | 56.45 | 56.52 | 56.61 |
2016-09-27 | 56.55 | 57.67 | 56.30 | 57.56 | 57.02 |
2016-09-28 | 57.49 | 57.67 | 57.28 | 57.64 | 57.52 |
2016-09-29 | 57.42 | 57.78 | 56.83 | 57.01 | 57.26 |
2016-09-30 | 57.18 | 57.38 | 56.96 | 57.21 | 57.18 |
2016-10-03 | 57.02 | 57.16 | 56.68 | 57.03 | 56.97 |
2016-10-04 | 56.89 | 57.21 | 56.59 | 56.86 | 56.88 |
2016-10-05 | 56.91 | 57.57 | 56.88 | 57.25 | 57.15 |
2016-10-06 | 57.35 | 57.47 | 56.90 | 57.35 | 57.27 |
2016-10-07 | 57.46 | 57.59 | 57.03 | 57.41 | 57.37 |
2016-10-10 | 57.52 | 58.00 | 57.48 | 57.65 | 57.66 |
2016-10-11 | 57.50 | 57.63 | 56.51 | 56.81 | 57.11 |
2016-10-12 | 56.73 | 56.89 | 56.02 | 56.73 | 56.59 |
2016-10-13 | 56.32 | 56.92 | 55.94 | 56.54 | 56.43 |
2016-10-14 | 56.74 | 57.35 | 56.74 | 57.03 | 56.97 |
2016-10-17 | 56.98 | 57.07 | 56.49 | 56.84 | 56.84 |
2016-10-18 | 57.14 | 57.56 | 57.02 | 57.27 | 57.25 |
2016-10-19 | 57.08 | 57.45 | 57.01 | 57.14 | 57.17 |
2016-10-20 | 57.11 | 57.13 | 56.28 | 56.87 | 56.85 |
2016-10-21 | 59.88 | 60.04 | 59.09 | 59.26 | 59.57 |
2016-10-24 | 59.54 | 60.59 | 59.53 | 60.59 | 60.06 |
2016-10-25 | 60.44 | 60.96 | 60.39 | 60.58 | 60.59 |
2016-10-26 | 60.40 | 60.79 | 60.06 | 60.22 | 60.37 |
2016-10-27 | 60.20 | 60.42 | 59.69 | 59.70 | 60.00 |
2016-10-28 | 59.61 | 60.11 | 59.18 | 59.47 | 59.59 |
2016-10-31 | 59.76 | 60.01 | 59.52 | 59.52 | 59.70 |
2016-11-01 | 59.57 | 59.62 | 58.85 | 59.40 | 59.36 |
2016-11-02 | 59.42 | 59.53 | 58.90 | 59.03 | 59.22 |
2016-11-03 | 59.13 | 59.24 | 58.71 | 58.81 | 58.97 |
2016-11-04 | 58.26 | 58.88 | 58.13 | 58.32 | 58.40 |
2016-11-07 | 59.38 | 60.11 | 59.38 | 60.01 | 59.72 |
2016-11-08 | 60.14 | 60.37 | 59.75 | 60.06 | 60.08 |
2016-11-09 | 59.60 | 60.18 | 58.80 | 59.77 | 59.59 |
2016-11-10 | 60.07 | 60.08 | 57.24 | 58.31 | 58.93 |
2016-11-11 | 57.84 | 58.72 | 57.62 | 58.62 | 58.20 |
2016-11-14 | 58.62 | 58.68 | 56.90 | 57.73 | 57.98 |
2016-11-15 | 58.33 | 59.49 | 58.31 | 58.87 | 58.75 |
2016-11-16 | 58.94 | 59.66 | 54.27 | 59.65 | 58.13 |
2016-11-17 | 60.41 | 60.95 | 59.97 | 60.64 | 60.49 |
2016-11-18 | 60.78 | 61.14 | 60.30 | 60.35 | 60.64 |
2016-11-21 | 60.50 | 60.97 | 60.42 | 60.86 | 60.69 |
2016-11-22 | 60.98 | 61.26 | 60.81 | 61.12 | 61.04 |
2016-11-23 | 61.01 | 61.10 | 60.25 | 60.40 | 60.69 |
2016-11-25 | 60.30 | 60.53 | 60.13 | 60.53 | 60.37 |
2016-11-28 | 60.34 | 61.02 | 60.21 | 60.61 | 60.55 |
2016-11-29 | 60.65 | 61.41 | 60.52 | 61.09 | 60.92 |
2016-11-30 | 60.86 | 61.18 | 60.22 | 60.26 | 60.63 |
2016-12-01 | 60.11 | 60.15 | 58.94 | 59.20 | 59.60 |
2016-12-02 | 59.08 | 59.47 | 58.80 | 59.25 | 59.15 |
2016-12-05 | 59.70 | 60.58 | 59.56 | 60.22 | 60.02 |
2016-12-06 | 60.43 | 60.46 | 59.80 | 59.95 | 60.16 |
2016-12-07 | 60.01 | 61.38 | 59.80 | 61.37 | 60.64 |
2016-12-08 | 61.30 | 61.58 | 60.84 | 61.01 | 61.18 |
2016-12-09 | 61.18 | 61.99 | 61.12 | 61.97 | 61.57 |
2016-12-12 | 61.82 | 62.30 | 61.72 | 62.17 | 62.00 |
2016-12-13 | 62.50 | 63.42 | 62.24 | 62.98 | 62.78 |
2016-12-14 | 63.00 | 63.45 | 62.53 | 62.68 | 62.91 |
2016-12-15 | 62.70 | 63.15 | 62.30 | 62.58 | 62.68 |
2016-12-16 | 62.95 | 62.95 | 62.12 | 62.30 | 62.58 |
2016-12-19 | 62.56 | 63.77 | 62.42 | 63.62 | 63.09 |
2016-12-20 | 63.69 | 63.80 | 63.03 | 63.54 | 63.51 |
2016-12-21 | 63.43 | 63.70 | 63.12 | 63.54 | 63.45 |
2016-12-22 | 63.84 | 64.10 | 63.40 | 63.55 | 63.72 |
2016-12-23 | 63.45 | 63.54 | 62.80 | 63.24 | 63.26 |
2016-12-27 | 63.21 | 64.07 | 63.21 | 63.28 | 63.44 |
2016-12-28 | 63.40 | 63.40 | 62.83 | 62.99 | 63.16 |
2016-12-29 | 62.86 | 63.20 | 62.73 | 62.90 | 62.92 |
2016-12-30 | 62.96 | 62.99 | 62.03 | 62.14 | 62.53 |
2017-01-03 | 62.79 | 62.84 | 62.12 | 62.58 | 62.58 |
2017-01-04 | 62.48 | 62.75 | 62.12 | 62.30 | 62.41 |
2017-01-05 | 62.19 | 62.66 | 62.03 | 62.30 | 62.29 |
2017-01-06 | 62.30 | 63.15 | 62.04 | 62.84 | 62.58 |
2017-01-09 | 62.76 | 63.08 | 62.54 | 62.64 | 62.76 |
2017-01-10 | 62.73 | 63.07 | 62.28 | 62.62 | 62.67 |
2017-01-11 | 62.61 | 63.23 | 62.43 | 63.19 | 62.86 |
2017-01-12 | 63.06 | 63.40 | 61.95 | 62.61 | 62.76 |
2017-01-13 | 62.62 | 62.87 | 62.35 | 62.70 | 62.63 |
2017-01-17 | 62.68 | 62.70 | 62.03 | 62.53 | 62.48 |
2017-01-18 | 62.67 | 62.70 | 62.12 | 62.50 | 62.50 |
2017-01-19 | 62.24 | 62.98 | 62.19 | 62.30 | 62.43 |
2017-01-20 | 62.67 | 62.82 | 62.37 | 62.74 | 62.65 |
2017-01-23 | 62.70 | 63.12 | 62.57 | 62.96 | 62.84 |
2017-01-24 | 63.20 | 63.74 | 62.94 | 63.52 | 63.35 |
2017-01-25 | 63.95 | 64.10 | 63.45 | 63.68 | 63.80 |
2017-01-26 | 64.12 | 64.54 | 63.55 | 64.27 | 64.12 |
2017-01-27 | 65.39 | 65.91 | 64.89 | 65.78 | 65.49 |
2017-01-30 | 65.69 | 65.79 | 64.80 | 65.13 | 65.35 |
2017-01-31 | 64.86 | 65.15 | 64.26 | 64.65 | 64.73 |
2017-02-01 | 64.36 | 64.62 | 63.47 | 63.58 | 64.01 |
2017-02-02 | 63.25 | 63.41 | 62.75 | 63.17 | 63.14 |
2017-02-03 | 63.50 | 63.70 | 63.07 | 63.68 | 63.49 |
2017-02-06 | 63.50 | 63.65 | 63.14 | 63.64 | 63.48 |
2017-02-07 | 63.74 | 63.78 | 63.23 | 63.43 | 63.55 |
2017-02-08 | 63.57 | 63.81 | 63.22 | 63.34 | 63.49 |