I wrote multivariate minimum variance as follows
,maxi.set[“Time”] = weekly_returns.index
maxi.param[“weekly_returns”] = weekly_returns
maxi.param[“Sigma”]=sigma
These have same date format but I guess I got loading error.
tscv = TimeSeriesSplit(max_train_size=11, test_size=1)
for train_index, test_index in tscv.split(assets):
train_assets = assets.iloc[train_index]
test_assets = assets.iloc[test_index]
weekly_returns = train_assets.pct_change().fillna(method='bfill')
#mean_return = weekly_returns.mean()
weekly_returns["Date"] = weekly_returns.index.format()
weekly_returns.set_index("Date", inplace=True)
#daily_returns_test = test_assets.pct_change().dropna()
#mean_return_test = daily_returns_test.mean()
dfs = []
for i, slice_df in train_assets.groupby("Date"):
df = risk_models.risk_matrix(train_assets, method="sample_cov").stack().to_frame()
df.reset_index(inplace=True) # Turn the index into regular data columns
df.columns = ["Stock1", "Stock2", "S"] # Adjust column names
df["Time"] = i # Add new column with the index of the slice
dfs.append(df)
# sigma = pd.concat(dfs) # Concatenate all dataframes
#sigma.set_index(["Time", "Stock1", "Stock2"], inplace=True)
#daily_returns_test = test_assets.pct_change().dropna()
#mean_return_test = daily_returns_test.mean()
maxi = AMPL()
maxi.read("min_var_one.mod")
maxi.set["A"] = list(assets.columns)
maxi.set["Time"] = weekly_returns.index.values#array of dates
maxi.param["weekly_returns"] = weekly_returns
maxi.param["Sigma"]=sigma
#maxi.param["mean_return"] = mean_return
#ampl.getParameter("daily_returns").setValues(daily_returns_train.stack())
#ampl.getParameter("mean_return").setValues(mean_return_train)
maxi.option["solver"] = SOLVER
maxi.solve()
#ampl.var["w"].to_pandas()
#ampl.get_data("w").to_pandas().plot.barh()
#ampl.get_data["w"].to_pandas()
weights_df_max = maxi.var["w"].to_pandas()
my sigma, maxi.set[“Time”] = weekly_returns.index.values has same dates, but for time it is array format the others have index format?
sigma=