OBV
real = OBV(close, volume)
Plot
Working Example
from cloudquant.interfaces import Strategy
from collections import OrderedDict
import ktgfunc
import numpy
import talib
class WE_OBV(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
# talib expects volume to be a numpy float array
v = daily_bars.volume
volume = numpy.asarray(v, dtype=float)
real = talib.OBV(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['close'] = close
dict['volume'] = volume
dict['real'] = real
symbol = 'OBV: ' + self.symbol
print ktgfunc.talib_table(symbol, 1, dict)
Console
MSFT: 2017-02-09 09:30:00.000000
OBV: MSFT | |||
---|---|---|---|
Input | Output | ||
date | close | volume | real |
2016-09-16 | 56.87 | 44571091.00 | 44571091.00 |
2016-09-19 | 56.55 | 20956079.00 | 23615012.00 |
2016-09-20 | 56.43 | 17384082.00 | 6230930.00 |
2016-09-21 | 57.37 | 34358572.00 | 40589502.00 |
2016-09-22 | 57.43 | 19822203.00 | 60411705.00 |
2016-09-23 | 57.04 | 19955479.00 | 40456226.00 |
2016-09-26 | 56.52 | 21688900.00 | 18767326.00 |
2016-09-27 | 57.56 | 28065078.00 | 46832404.00 |
2016-09-28 | 57.64 | 20543966.00 | 67376370.00 |
2016-09-29 | 57.01 | 25463618.00 | 41912752.00 |
2016-09-30 | 57.21 | 30450631.00 | 72363383.00 |
2016-10-03 | 57.03 | 19190339.00 | 53173044.00 |
2016-10-04 | 56.86 | 20086050.00 | 33086994.00 |
2016-10-05 | 57.25 | 16726411.00 | 49813405.00 |
2016-10-06 | 57.35 | 16212687.00 | 66026092.00 |
2016-10-07 | 57.41 | 20124844.00 | 86150936.00 |
2016-10-10 | 57.65 | 18196509.00 | 104347445.00 |
2016-10-11 | 56.81 | 26497418.00 | 77850027.00 |
2016-10-12 | 56.73 | 22177464.00 | 55672563.00 |
2016-10-13 | 56.54 | 25313748.00 | 30358815.00 |
2016-10-14 | 57.03 | 27402551.00 | 57761366.00 |
2016-10-17 | 56.84 | 23830115.00 | 33931251.00 |
2016-10-18 | 57.27 | 19150364.00 | 53081615.00 |
2016-10-19 | 57.14 | 22878406.00 | 30203209.00 |
2016-10-20 | 56.87 | 49455856.00 | -19252647.00 |
2016-10-21 | 59.26 | 80023831.00 | 60771184.00 |
2016-10-24 | 60.59 | 54066978.00 | 114838162.00 |
2016-10-25 | 60.58 | 30797202.00 | 84040960.00 |
2016-10-26 | 60.22 | 25128079.00 | 58912881.00 |
2016-10-27 | 59.70 | 28480469.00 | 30432412.00 |
2016-10-28 | 59.47 | 33781433.00 | -3349021.00 |
2016-10-31 | 59.52 | 26434751.00 | 23085730.00 |
2016-11-01 | 59.40 | 24656951.00 | -1571221.00 |
2016-11-02 | 59.03 | 22172630.00 | -23743851.00 |
2016-11-03 | 58.81 | 21737488.00 | -45481339.00 |
2016-11-04 | 58.32 | 28698150.00 | -74179489.00 |
2016-11-07 | 60.01 | 31664948.00 | -42514541.00 |
2016-11-08 | 60.06 | 22935355.00 | -19579186.00 |
2016-11-09 | 59.77 | 49736785.00 | -69315971.00 |
2016-11-10 | 58.31 | 57822638.00 | -127138609.00 |
2016-11-11 | 58.62 | 38767843.00 | -88370766.00 |
2016-11-14 | 57.73 | 41578422.00 | -129949188.00 |
2016-11-15 | 58.87 | 35904127.00 | -94045061.00 |
2016-11-16 | 59.65 | 27438882.00 | -66606179.00 |
2016-11-17 | 60.64 | 32132728.00 | -34473451.00 |
2016-11-18 | 60.35 | 27686736.00 | -62160187.00 |
2016-11-21 | 60.86 | 19652595.00 | -42507592.00 |
2016-11-22 | 61.12 | 23206602.00 | -19300990.00 |
2016-11-23 | 60.40 | 21936368.00 | -41237358.00 |
2016-11-25 | 60.53 | 8410638.00 | -32826720.00 |
2016-11-28 | 60.61 | 20733011.00 | -12093709.00 |
2016-11-29 | 61.09 | 22367255.00 | 10273546.00 |
2016-11-30 | 60.26 | 34677272.00 | -24403726.00 |
2016-12-01 | 59.20 | 34542646.00 | -58946372.00 |
2016-12-02 | 59.25 | 25515890.00 | -33430482.00 |
2016-12-05 | 60.22 | 23569552.00 | -9860930.00 |
2016-12-06 | 59.95 | 20027055.00 | -29887985.00 |
2016-12-07 | 61.37 | 30808969.00 | 920984.00 |
2016-12-08 | 61.01 | 21222039.00 | -20301055.00 |
2016-12-09 | 61.97 | 27349357.00 | 7048302.00 |
2016-12-12 | 62.17 | 20198516.00 | 27246818.00 |
2016-12-13 | 62.98 | 35721348.00 | 62968166.00 |
2016-12-14 | 62.68 | 30352925.00 | 32615241.00 |
2016-12-15 | 62.58 | 27669868.00 | 4945373.00 |
2016-12-16 | 62.30 | 42453675.00 | -37508302.00 |
2016-12-19 | 63.62 | 34338219.00 | -3170083.00 |
2016-12-20 | 63.54 | 26028558.00 | -29198641.00 |
2016-12-21 | 63.54 | 17097365.00 | -29198641.00 |
2016-12-22 | 63.55 | 22176697.00 | -7021944.00 |
2016-12-23 | 63.24 | 12404739.00 | -19426683.00 |
2016-12-27 | 63.28 | 11763173.00 | -7663510.00 |
2016-12-28 | 62.99 | 14665097.00 | -22328607.00 |
2016-12-29 | 62.90 | 10250582.00 | -32579189.00 |
2016-12-30 | 62.14 | 25579908.00 | -58159097.00 |
2017-01-03 | 62.58 | 17452390.00 | -40706707.00 |
2017-01-04 | 62.30 | 21340044.00 | -62046751.00 |
2017-01-05 | 62.30 | 24876968.00 | -62046751.00 |
2017-01-06 | 62.84 | 20154615.00 | -41892136.00 |
2017-01-09 | 62.64 | 20382734.00 | -62274870.00 |
2017-01-10 | 62.62 | 18594565.00 | -80869435.00 |
2017-01-11 | 63.19 | 21517335.00 | -59352100.00 |
2017-01-12 | 62.61 | 20968328.00 | -80320428.00 |
2017-01-13 | 62.70 | 19422310.00 | -60898118.00 |
2017-01-17 | 62.53 | 20664147.00 | -81562265.00 |
2017-01-18 | 62.50 | 20072514.00 | -101634779.00 |
2017-01-19 | 62.30 | 18451787.00 | -120086566.00 |
2017-01-20 | 62.74 | 30338462.00 | -89748104.00 |
2017-01-23 | 62.96 | 23097906.00 | -66650198.00 |
2017-01-24 | 63.52 | 21658284.00 | -44991914.00 |
2017-01-25 | 63.68 | 24660251.00 | -20331663.00 |
2017-01-26 | 64.27 | 43633281.00 | 23301618.00 |
2017-01-27 | 65.78 | 44826340.00 | 68127958.00 |
2017-01-30 | 65.13 | 31731271.00 | 36396687.00 |
2017-01-31 | 64.65 | 25270674.00 | 11126013.00 |
2017-02-01 | 63.58 | 39671568.00 | -28545555.00 |
2017-02-02 | 63.17 | 45828988.00 | -74374543.00 |
2017-02-03 | 63.68 | 30301759.00 | -44072784.00 |
2017-02-06 | 63.64 | 20021886.00 | -64094670.00 |
2017-02-07 | 63.43 | 20277228.00 | -84371898.00 |
2017-02-08 | 63.34 | 18099993.00 | -102471891.00 |