i’m trying to run a python code which i found on the net (https://levelup.gitconnected.com/cryptocurrency-portfolio-optimization-in-python-46b5bd6d6f81) with spyder, but it gives error. this error: Traceback (most recent call last):

File C:\Programs\Anaconda\lib\site-packages\requests\models.py:971 in json
return complexjson.loads(self.text, **kwargs)

File C:\Programs\Anaconda\lib\json_init_.py:346 in loads
return _default_decoder.decode(s)

File C:\Programs\Anaconda\lib\json\decoder.py:337 in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())

File C:\Programs\Anaconda\lib\json\decoder.py:355 in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None

JSONDecodeError: Expecting value


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File C:\Programs\Anaconda\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)

File c:\users\sepanta.spyder-py3\untitled0.py:14
resp = resp.json()

File C:\Programs\Anaconda\lib\site-packages\requests\models.py:975 in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value. this is the code i was trying to run:import pandas as pd
import requests
import time
from pypfopt import risk_models
from pypfopt.risk_models import CovarianceShrinkage
from pypfopt import expected_returns
from pypfopt.efficient_frontier import EfficientFrontier
# get the starting date in unix timestamp
date_time = ‘2020-01-01 00:00:00’
pattern = ‘%Y-%m-%d %H:%M:%S’
epoch = int(time.mktime(time.strptime(date_time, pattern)))
# get all the cryptocurrencies in USD
resp = requests.get(‘https://api.kraken.com/0/public/AssetPairs’)
resp = resp.json()
# Keep all the cryptos over USD
dollar_pairs = []
for pair in resp[‘result’]:
if pair.endswith(‘USD’):
dollar_pairs.append(pair)
# get all the unixtimestamps
tmp_url = f’https://api.kraken.com/0/public/OHLC?pair=XXBTZUSD&since={epoch}&interval=1440’.format(epoch)
resp = requests.get(tmp_url)
dummy_df = pd.DataFrame(resp.json()[‘result’][‘XXBTZUSD’])[[0]]
# create a pandas data frame and add the closing prices of each asset
df = pd.DataFrame(index=dummy_df[0])
for pair in dollar_pairs:
tmp_url = f’https://api.kraken.com/0/public/OHLC?pair={pair}&since={epoch}&interval=1440’.format(pair,epoch)
resp = requests.get(tmp_url)
tmp_df = pd.DataFrame(resp.json()[‘result’][pair])[[0,4]]
tmp_df.columns = [‘unixtimestap’, pair]
tmp_df[pair] = tmp_df[pair].astype(float)
df = pd.concat([df,tmp_df.set_index(‘unixtimestap’)], axis=1)
# remove the last row since it is not a full day
df = df[:-1].copy()
# drop the columns with a least one NA
df.dropna(axis=‘columns’, inplace=True)
# remove the other fiat currencies liker EURO and the stable coins like Tether and DAI
df.drop(columns=[‘USDCUSD’, ‘USDTZUSD’, ‘DAIUSD’, ‘ZGBPZUSD’,‘ZEURZUSD’, ‘PAXGUSD’], axis=1, inplace=True)
# calculate the mean and variance
mu = expected_returns.ema_historical_return(df, frequency=365)
Sigma = risk_models.exp_cov(df, frequency=365)
sharpe_weights = ef.max_sharpe()
(ef.clean_weights())
ef.portfolio_performance(verbose=True)
ef = EfficientFrontier(mu, Sigma)
min_vol_weights = ef.min_volatility()
(ef.clean_weights())
ef.portfolio_performance(verbose=True)
with open(“AB.json”, encoding=‘utf-8’, errors=‘ignore’) as json_data:
data = json.load(json_data, strict=False)