This code aggregates the data from the synthetix pool and backtests returns to calculate the optimal weights for sUSD, sETH, and sBTC to capture that highest r^2 possible. This optimal portfolio would allow the user to stay neutral to the debt-pool, accumulating pure yield on staked snx.
from sys import excepthook
import yfinance as yf
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
indices = (yf.download(tickers="EURUSD=X", period="3mo", interval="1d").index)
eth = yf.download(tickers="ETH-USD", period="3mo", interval="1d")
eth = eth.filter(items = indices, axis=0)['Close'].to_numpy()
btc = yf.download(tickers="BTC-USD", period="3mo", interval="1d")
btc = btc.filter(items = indices, axis=0)['Close'].to_numpy()
jpy = yf.download(tickers="JPYUSD=X", period="3mo", interval="1d")['Close'].to_numpy()
chf = yf.download(tickers="CHFUSD=X", period="3mo", interval="1d")['Close'].to_numpy()
aud = yf.download(tickers="AUDUSD=X", period="3mo", interval="1d")['Close'].to_numpy()
matic = yf.download(tickers="MATIC-USD", period="3mo", interval="1d")
matic = matic.filter(items = indices, axis=0)['Close'].to_numpy()
eur = yf.download(tickers="EURUSD=X", period="3mo", interval="1d")['Close'].to_numpy()
usd = np.ones(eur.shape)
assets = [usd, eth, btc, eur, jpy, chf, aud, matic]
assets = np.array(assets)
returns = assets[:, 1:] / assets[:, :-1]
weights = np.array([.6338, .1662, .1014, .0487, .0283, .0153, .0051, .0012])
pool_returns = weights @ returns
sim_returns = returns[:3]
m = np.linalg.lstsq(sim_returns.T, pool_returns.T, rcond=None)[0]
print(m, "weights")
yhat = m @ sim_returns
plt.plot(pool_returns, color="red")
plt.plot(yhat, color="blue")
r2 = np.corrcoef(yhat, pool_returns)[0,1]
plt.title("debt pool returns vs hedge returns " + str(r2) + " r^2")
plt.show()
plt.scatter(np.arange(len(pool_returns)), (pool_returns - yhat))
plt.title("residual scatter plot")
plt.show()