I want to create a multi-level row index for which level 0 is the name of the list element in the list I have named environ (see code below e.g. regime1). The second level of this row index is the parameter name (e.g. alpha[1] ). The column index is the name of the type of model fit to the data (e.g. model_1). The end goal, is to create a loop, in which I can pass a list of names associated with a data series, the label of the series becomes the first level of a row multilevel index, the second level is the parameter name, the column index is the name of the model fit to the data series.
Imports:
from arch import arch_model
from collections import OrderedDict
import numpy as np
import pandas as pd
import datetime as dt
import arch.data.sp500
Below is how I want the output to look like, if I printed the results of the code loop.
model_1 model_2
Regime 1 alpha[1] 0.102150 0.099596
beta[1] 0.885206 0.899932
mu 0.056353 0.066129
nu NaN 6.607229
omega 0.017507 0.008664
model_1 model_2
Regime_2 alpha[1] 0.102150 0.099596
beta[1] 0.885206 0.899932
mu 0.056353 0.066129
nu NaN 6.607229
omega 0.017507 0.008664
The code below is my latest attempt to get the desired output above:
environ = ['regime1','regime2']
data = arch.data.sp500.load()
market = data['Adj Close']
returns = 100 * market.pct_change().dropna()
returns2 = 100 * market.pct_change().dropna()
datasets = [returns,returns2]
for i,j in zip(environ,datasets):
model1 = arch_model(datasets[j]).fit(disp='off')
model2 = arch_model(datasets[j], dist='t').fit(disp='off')
comparison = pd.DataFrame( OrderedDict((('model_1',model1.params), ('model_2', model2.params))))
print(comparison)
The current error I am receiving:
TypeError: list indices must be integers or slices, not Series
I don't believe fixing the error above will solve my problem. I want to return a multilevel dataframe, that looks similar to the desired output above.