试图弄清楚所有这些如何工作之后,我设法将Bitmex的存储桶式API提要加载到DataFrame中。现在,尝试遵循我能找到的所有逻辑(包括文档),以了解如何将其解析为talib以吐出(正确的)数字,这就是我遇到的问题。我不需要绘制图形(尽管这很酷),但这是在以后的阶段。到目前为止,我有:
import requests
import numpy
import talib
import talib as ta
import panda as pd
dfURI = 'https://www.bitmex.com/api/v1/trade/bucketed?binSize=1h&partial=false&symbol=XBT&columns=timestamp%2C%20open%2C%20high%2C%20low%2C%20close%2C%20volume&count=96&reverse=true'
df = pd.read_json(dfURI, orient="columns")
df.columns = ["high", "close", "low", "open", "symbol", "timestamp", "volume"]
df = df.set_index('timestamp')
period = "4H" #1D or 1H
data_rows = "1"
if period == "4H" :
data_period = df.resample('4H').mean()
data_rows = 8
elif period == "1D" :
data_period = df.resample('1D').mean()
data_rows = 2
elif period == "1H" :
data_period = df.resample('1H').mean()
data_rows = 12
#daily_close = df.set_index('timestamp').resample('1D').mean()
print (data_period.tail(data_rows))
close = data_period['close'] #.values
low = data_period['low'] #.values
high = data_period['high'] #.values
#real = talib.WILLR(high, low, close.values, timeperiod=14)
realK, realD = talib.STOCHRSI(close)
logger.info("TALib output is: \n %s %s " % (realK, realD))
JSON读取的输出是正确的(尽管它不是基于时间戳排序的,但稍后会介绍)
high close low open volume
timestamp
2018-09-10 12:00:00 6294.500 6315.375 6273.750 6292.125 1.052005e+08
2018-09-10 16:00:00 6268.250 6289.875 6243.875 6273.625 9.917725e+07
2018-09-10 20:00:00 6289.625 6298.625 6270.625 6288.000 4.804955e+07
2018-09-11 00:00:00 6337.125 6369.875 6301.875 6321.375 1.142635e+08
2018-09-11 04:00:00 6326.500 6342.250 6321.625 6331.875 5.114736e+07
2018-09-11 08:00:00 6309.500 6322.000 6297.250 6314.250 6.218389e+07
2018-09-11 12:00:00 6251.125 6286.625 6220.750 6276.250 1.322033e+08
2018-09-11 16:00:00 6247.500 6248.000 6180.000 6204.500 2.071930e+08
现在,当尝试使用talib.stochrsi(Close)或talib.willr(按代码中的设置)调用数据时,我得到了完全错误的数字(相对于交易视图)和NaN代码,就像这样:
2018-09-10 04:00:00 NaN
2018-09-10 08:00:00 NaN
2018-09-10 12:00:00 NaN
2018-09-10 16:00:00 NaN
2018-09-10 20:00:00 NaN
2018-09-11 00:00:00 52.523650
2018-09-11 04:00:00 76.982179
2018-09-11 08:00:00 75.890822
2018-09-11 12:00:00 46.515123
2018-09-11 16:00:00 22.056595
我在这里做错了什么?任何帮助将非常感激。很想获得正确的STOCHRSI值!