我在网上找到了此代码,但是缺少了一些部分。我添加了statsmodels.api
import requests # for making http requests to binance
import json # for parsing what binance sends back to us
import pandas as pd # for storing and manipulating the data we get back
import numpy as np # numerical python, i usually need this somewhere
# and so i import by habit nowadays
import statsmodels.api as sm
import matplotlib.pyplot as plt # for charts and such
import datetime as dt # for dealing with times
def get_bars(symbol, interval = '1h'):
root_url = 'https://api.binance.com/api/v1/klines'
url = root_url + '?symbol=' + symbol + '&interval=' + interval
data = json.loads(requests.get(url).text)
df = pd.DataFrame(data)
df.columns = ['open_time',
'o', 'h', 'l', 'c', 'v',
'close_time', 'qav', 'num_trades',
'taker_base_vol', 'taker_quote_vol', 'ignore']
df.index = [dt.datetime.fromtimestamp(x/1000.0) for x in df.close_time]
return df
symbols =
json.loads(requests.get("https://api.binance.com/api/v1/exchangeInfo").text)
symbols = [symbol['symbol'] for symbol in symbols['symbols'] if
symbol['quoteAsset'] == 'ETH']
ethusdt = get_bars('ETHUSDT')
price_data = []
new_symbols = []
for symbol in symbols:
print(symbol)
data = get_bars(symbol)
new_symbols.append(symbol.replace('ETH','USDT'))
price_data.append(data['c'].astype('float') *
ethusdt['c'].astype('float'))
combo = pd.concat(price_data, axis = 1)
combo.columns = new_symbols
mst = sm.MinimumSpanningTree(dataset = np.log(combo).diff().T)
运行代码时出现此错误。这是什么问题?
mst = sm.MinimumSpanningTree(dataset = np.log(combo).diff().T)
AttributeError: module 'statsmodels.api' has no attribute 'MinimumSpanningTree'
答案 0 :(得分:0)
我安装了statsmodels并从here运行了解决方案来寻找树。我还在安装区域中对目录进行了目录搜索,然后列出了所有包含的文件;在文件名或内容中唯一带有“ tree”的文件是sandbox/regression/treewalkerclass.py
。
我初步得出结论,在statsmodels
的当前版本(0.9.0)中确实没有这样的属性。