我正在运行以下代码来对币安的加密货币运行 Dickey-Fuller 测试,但结果是我得到一个空列表。
import pandas as pd
import numpy as np
from binance.um_futures import UMFutures
from binance.exceptions import BinanceAPIException
from binance.client import Client
import time
api_key = ''
api_secret = ''
client = UMFutures(key = api_key, secret = api_secret)
def klines(symbol):
try:
df = pd.DataFrame(client.klines(symbol, '1h', limit = 720))
except BinanceAPIException as e:
print(e)
sleep(60)
df = pd.DataFrame(client.klines(symbol, '1h', limit = 720))
df = df.iloc[:,:6]
df.columns = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume']
df = df.set_index('Time')
df.index = pd.to_datetime(df.index, unit='ms')
df.drop(columns = ['Open', 'High', 'Low', 'Volume'], axis = 1, inplace = True)
df = df.astype(float)
return df
from statsmodels.tsa.stattools import adfuller
base = ['BTCUSDT', 'ETHUSDT','BCHUSDT','XRPUSDT', 'FLOWUSDT', 'MATICUSDT', 'ZENUSDT', 'SUSHIUSDT',
'BANDUSDT', 'LRCUSDT','FLMUSDT', 'BAKEUSDT', 'BELUSDT', 'MANAUSDT', 'CRVUSDT', 'ATAUSDT', 'BELUSDT', 'DGBUSDT', 'DOGEUSDT']
res = []
for i in base:
for j in base[base.index(i):]:
if i != j:
spreadcheck = adfuller((klines(i)['Close'])/(klines(j)['Close']).dropna(), autolag='AIC')
if spreadcheck[1] < 0.001:
res.append([i,j, spreadcheck[0], spreadcheck[1]])
def PValue(inputList):
return inputList[3]
res = sorted(res, key=PValue)
res
为什么会发生这种情况?我缺少的是什么?谢谢!!!
我遇到错误“ModuleNotFoundError:没有名为“binance.um_futures”的模块” 那么我无法运行代码,但为什么要从“inputList”中选择第三个索引? “inputList”有价值吗?