我有一个函数,其中包含:
filter_df['returns'][i] = (
params['const_mean_equation'] /
(1 - params['AR_mean_equation0'] - params['MA_mean_equation0']))
filter_df['sigma_2'][i] = (
params['const_variance_equation'] /
(1 - params['arch0'] - params['garch0']) #unconditional variance)
filter_df['residuals'][i] = y[i] - filter_df['returns'][i]
并通过包含以下内容的字典
{'const_variance_equation': 1,
'arch0': 2,
'garch0': 3,
'const_mean_equation': 4,
'AR_mean_equation0': 5,
'MA_mean_equation0': 6}
但是,我希望第一个变量的RHS根据提供的字典是动态的。也就是说,如果我通过这样的字典:
{'const_variance_equation': 1,
'arch0': 2,
'garch0': 3,
'arch1': 2,
'garch1': 3,
'const_mean_equation': 4,
'AR_mean_equation0': 5,
'MA_mean_equation0': 6
'AR_mean_equation1': 5,
'MA_mean_equation1': 6}
该功能自动(动态)更改为:
filter_df['returns'][i] = (
params['const_mean_equation'] /
(1 - params['AR_mean_equation0'] - params['MA_mean_equation0'] -
params['AR_mean_equation1'] - params['MA_mean_equation1']))
filter_df['sigma_2'][i] = (
params['const_variance_equation'] /
(1 - params['arch0'] - params['garch0'] - params['arch1'] -
params['garch1']) #unconditional variance)
filter_df['residuals'][i] = y[i] - filter_df['returns'][i]
我不确定如何自动执行此过程。我曾想过做类似的事情:对于第一个方程(filter_df['returns'][i])
,如果params[key]
包含字符串'AR_mean'
和'MA_mean'
,请始终减去-但我不太确定如何继续该过程。使用相同的逻辑,对于sigma_2
,如果所有params[key]
包含字符串'arch'
,则将减去所有df['date']=pd.to_datetime(df['date'])
print(df.set_index('date').asfreq('D').ffill().reset_index())
。有提示吗?