我正在尝试创建一个 Matplotlib 图表,显示 Poloniex 交易所上加密货币对的布林带和价格图表。当我为 BTC/ETH 对获取数据时,这些频段似乎可以工作,但对于 BTC/BURST 等不太活跃的货币对则不行。
似乎 BTC/ETH 对的标准偏差计算正确,并且显示了波段,但 BTC/BURST 对的标准偏差始终为零,因此波段绘制在 10 天 SMA 之上。
这是我的代码
import API
import numpy as np
from talib.abstract import *
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import time
from pprint import pprint
key = 'keyHere'
secret = 'secretHere'
api = API.poloniex(key, secret)
pair = "BTC_BURST"
interval = 1800 # 30 mins
steps = 336 # 1 week
startTime = int(time.time()) - steps * interval
stopTime = int(time.time())
print 'fetching', steps, 'candles from server'
fetchStart = time.time()
data = api.api_query('returnChartData', {"currencyPair": pair, "period": interval,
"start": startTime, "end": stopTime})
print 'fetched', len(data['candleStick']), 'candles in', time.time() - fetchStart, 'seconds'
pprint(data)
inputs = {
'open': np.empty(steps),
'high': np.empty(steps),
'low': np.empty(steps),
'close': np.empty(steps),
'volume': np.empty(steps)
}
for x in range(0, steps):
candle = data['candleStick'][x]
inputs['open'][x] = candle['open']
inputs['high'][x] = candle['high']
inputs['low'][x] = candle['low']
inputs['close'][x] = candle['close']
inputs['volume'][x] = candle['volume']
pprint(STDDEV(inputs, timeperiod=10, nbdev=2))
upper, middle, lower = BBANDS(inputs, timeperiod=10, nbdevup=2, nbdevdn=2)
# pprint(upper)
# pprint(middle)
# pprint(lower)
candlestick2_ohlc(plt.gca(), inputs['open'], inputs['high'],
inputs['low'], inputs['close'], width=0.8)
plt.plot(upper)
plt.plot(middle)
plt.plot(lower)
plt.show()
这个问题是因为 BTC/ETH 对的交易量较高吗?任何帮助是极大的赞赏。