After reading some papers on Hedge fund replication Hasanhodzic & Lo and more globally on returns-based style analysis Can active equity managers be cloned using factor funds, I would try by myself to see If I can roughly copy an Equity index or Fund returns. I tried to do a rolling OLS with statsmodels but I quickly see that I need constraints for beta coefficients.
I try to fit :
Rfund= ∝ + ∑ β*Rriskfactor + ϵ
Indeed, for practical reasons (i.e get directly portfolio weights for each risk factor) I need that the sum of β = 1. Regression coefficients can be negative as a long/short strategies are employed.
Could you please give me a solution to use in Python as it seems that statsmodels can't be constrained. I see that maybe I should use Scipy minimize or cvxopt for quadratic program but I'm not familiar at all with those methods.
here my first attempt before facing constraints issues.
Thanks for your help !
import pandas as pd
from pandas_datareader import data as pdr
import datetime
import statsmodels.api as sm
from statsmodels.regression.rolling import RollingOLS
import matplotlib.pyplot as plt
all_returns = pd.DataFrame()
tickers = ['^GSPC', '^STOXX50E', 'IEF', 'EURUSD=X', 'CL=F', 'NG=F', 'HG=F', 'GC=F', 'AQMRX']
end_date = datetime.datetime.now() - datetime.timedelta(-1)
start_date = datetime.date(2018, 12, 30)
for t in tickers:
df = pdr.DataReader(t, 'yahoo', start_date, end_date)
all_returns = all_returns.assign(**{t: df['Close'].pct_change()})
all_returns = all_returns.dropna()
x = all_returns[['^GSPC', '^STOXX50E', 'IEF', 'EURUSD=X', 'CL=F', 'NG=F', 'HG=F', 'GC=F']]
y = all_returns['AQMRX']
x = sm.add_constant(x)
rols = RollingOLS(y,x, window=60)
rres = rols.fit()
fig = rres.plot_recursive_coefficient(variables=['^GSPC','CL=F','IEF'], figsize=(14, 18))
plt.show()