-1

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'
Prune
  • 76,765
  • 14
  • 60
  • 81
  • As best I can find in the `statsmodels` documentation, there is no class or method named `MinimumSpanningTree`. Where did you get the idea that the package has one? – Prune Oct 22 '18 at 18:32
  • I couldn't find it myself but it was included in the code. – Coinmamba Oct 22 '18 at 18:42
  • My guess is that `sm` in that code example does not refer to `statsmodels`. statsmodels does not have any graph function or classes. – Josef Oct 22 '18 at 23:36
  • Just ran into your post, the sm refeers to a third party api which implement out of the box minimum spanning tree graphs (SliceM***** - you need to pay an api key to use their services). Did you find any other out-of-the-box solution for generating/displaying minimum spanning trees from daily returns ? I'm being lazy right now and am therefor looking for one;) – DrGorilla.eth Jun 24 '19 at 12:57

1 Answers1

0

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.

Prune
  • 76,765
  • 14
  • 60
  • 81