简体   繁体   中英

Minimum Spanning Tree issue

I found this code online but some parts were missing. I have added 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)

When running the code I'm getting this error. What's the issue here?

mst = sm.MinimumSpanningTree(dataset = np.log(combo).diff().T)
AttributeError: module 'statsmodels.api' has no attribute 'MinimumSpanningTree'

I installed statsmodels and ran solutions from here to look for the tree. I also did a directory search for the package in my installation area and followed with a listing of all contained files; the only file with "tree" in the file name or contents is sandbox/regression/treewalkerclass.py .

I tentatively conclude that there is, indeed, no such attribute in the current release (0.9.0) of statsmodels .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM