使用来自 statsmodel 的 arma_order_select_ic 选择 ARMA 模型顺序

ARMA model order selection using arma_order_select_ic from statsmodel

我正在使用 statsmodel 库中的 arma_order_select_ic 来计算 ARMA 模型的 (p,q) 阶数,我正在使用 for 循环遍历每个列中的不同公司数据框。代码如下:

import pandas as pd
from statsmodels.tsa.stattools import arma_order_select_ic

df = pd.read_csv("Adjusted_Log_Returns.csv", index_col = 'Date').dropna()

main_df = pd.DataFrame()


for i in range(146):
    order_selection = arma_order_select_ic(df.iloc[i].values, max_ar = 4, 
    max_ma = 2, ic = "aic")
    ticker = [df.columns[i]]

    df_aic_min = pd.DataFrame([order_selection["aic_min_order"]], index = 
    ticker)

main_df = main_df.append(df_aic_min)


main_df.to_csv("aic_min_orders.csv")

代码运行良好,最后我在 csv 文件中得到了所有结果,但让我感到困惑的是,当我为一家公司计算 for 循环外的 (p,q) 时,我得到不同的结果

order_selection = arma_order_select_ic(df["ABL"].values, max_ar = 4, 
max_ma = 2, ic = "aic")

公司 ABL 的顺序在 for 循环中计算时为 (1,1),而在其外部计算时为 (4,1)。

所以我的问题是我做错了什么或者为什么会这样?任何帮助将不胜感激。

提前致谢

从您的代码中可以清楚地看出,您正试图在 ' 数据上查找 ARMA 模型的参数,但这不是代码在做什么:您在循环中找到 .

的参数

考虑一下:

import pandas as pd

df = pd.DataFrame({'a': [3, 4]})

>>> df.iloc[0]
a    3
Name: 0, dtype: int64

>>> df['a']
0    3
1    4
Name: a, dtype: int64

您可能应该将代码更改为

for c in df.columns:
    order_selection = arma_order_select_ic(df[c].values, max_ar = 4, 
    max_ma = 2, ic = "aic")
    ticker = [c]