1
import pandas as pd 
import numpy as np 
import statsmodels.tsa.api as smt 
import pandas_datareader.data as web 

start = '2007-01-01' 
end = '2015-01-01' 
get_px = lambda x: web.DataReader(x, 'yahoo', start=start, end=end)['Adj Close']  
symbols = ['SPY','TLT','MSFT'] 
# raw adjusted close prices 
data = pd.DataFrame({sym:get_px(sym) for sym in symbols}) 
# log returns 
lrets = np.log(data/data.shift(1)).dropna() 

# Select best lag order for MSFT returns  
max_lag = 30 
mdl = smt.AR(lrets.MSFT).fit(maxlag=max_lag, ic='aic', trend='nc') 
est_order = smt.AR(lrets.MSFT).select_order(maxlag=max_lag, ic='aic', trend='nc') 

print('best estimated lag order = {}'.format(est_order)) 
print mdl.params 

輸出會是這樣。爲什麼statsmodels select_order函數與AR模型中的params不同?

best estimated lag order = 23 
L1.MSFT -0.075405 
L2.MSFT -0.067423 
L3.MSFT  0.031371 
L4.MSFT -0.063610 
L5.MSFT -0.045080 
L6.MSFT -0.001510 
L7.MSFT -0.051875 
L8.MSFT -0.015192 
L9.MSFT -0.018665 
L10.MSFT 0.044720 
L11.MSFT 0.041655 
L12.MSFT 0.034231 
L13.MSFT -0.042473 
L14.MSFT -0.008583 
L15.MSFT 0.022171 
L16.MSFT 0.009983 
L17.MSFT 0.038606 
L18.MSFT -0.073060 
dtype: float64 

這裏的問題是,即使statsmodels決定,AR模型的理想滯後23,只有18個參數,當您檢查的參數。它不應該一樣嗎?如果來自「select_order」的次序數小於參數數組的長度,則可能是有意義的。我知道在這種情況下,「select_order」使用AIC標準來決定理想的滯後訂單。

有人可以解釋爲什麼嗎?假設23的確是理想的滯後階數,那麼我怎樣才能獲得額外的5個參數,因爲我在這裏只能得到18個參數?

+0

根據最好的數到代碼中,默認的'方法'不同,「cmle」適合,select_order中選擇「mle」。嘗試使用相同的方法參數。 – user333700

回答

1

不是所有的23個滯後有助於契合 - 如果他們是零,他們掉下來,也不會計算。

0

的一點是,maxlag就是這樣; statsmodels的select_order方法可以選擇的最大滯後數作爲最佳滯後數。如果select_order選擇的最大滯後數大於maxlag,則不需要選擇maxlag。它可以選擇第二個最好的滯後數,它可能低於maxlag。假設maxlag無限大,select_order會選擇15.如果你的maxlag是10,那麼沒有必要選擇10作爲最佳滯後數,因爲它最接近於15的理想數值。相反,它會研究可能性10滯後並解決問題;選擇滯後給出的約束條件是不能超過10這個數字很可能變成是,比方說,如果7的信息標準是一個更好的狀態,如果不是數分別爲10

相關問題