简体   繁体   中英

Out-of-sample simulation of arima model fitted by statsmodel

Question

My aim was to simulate multiple scenarios of daily temperature of a specific place(say, Tokyo) in future and observe the dynamics. To do that, I tried statsmodels.tsa.arima_model.ARMAResults.forecast function after removing trend+seasonality of the original data, confirmed the remained data's stationarity by KPSS test and ADF test, searched the proper orders of ARMA model, fitted the model by statsmodels.tsa.arima_model.ARIMA.fit(method='mle', trend='nc') . However, the result was not what I wanted. Forecasted daily temperatures was single and converges to zero so quickly (ie [ 0.04579973, -0.35632123, 0.27349546, -0.14268638, -0.01815464, 0.06129577, -0.01736912, -0.03543152, 0.04223661, -0.01285459, -0.01444013, 0.01744708, -0.00351766, -0.0083289 , 0.00844778....]) though it gave me confidential interval info. Would anyone tell me how to simulate the development of temperature scinarios?

Environment

Python version: 3.6.7 Statsmodel version: 0.9.0 Environment: Google Colab

Codes

TS below is the time-series data(pd.Series) which has been removed trend and seasonarity. stationarity has been already confirmed by ADF/KPSS test.

print(sm.tsa.arma_order_select_ic(TS, ic='aic', trend='nc'))
#(4, 1)
arima_mdl = smt.ARIMA(TS, order=(4,0,1)).fit(method='mle', trend='nc')
arima_mdl.summary()

#                        coef  std err     z    P>|z|  [0.025   0.975]
#ar.L1.residual_base    1.4031  0.013   104.805 0.000   1.377   1.429
#ar.L2.residual_base    -0.4380 0.017   -25.640 0.000   -0.471  -0.405
#ar.L3.residual_base    0.0433  0.017   2.621   0.009   0.011   0.076
#ar.L4.residual_base    -0.0243 0.010   -2.375  0.018   -0.044  -0.004
#ma.L1.residual_base    -0.9187 0.009   -98.722 0.000   -0.937  -0.900
#Roots
#        Real   Imaginary   Modulus Frequency
#AR.1   1.0290  -0.0000j    1.0290  -0.0000
#AR.2   2.0195  -0.0000j    2.0195  -0.0000
#AR.3   -0.6329 -4.4078j    4.4530  -0.2727
#AR.4   -0.6329 +4.4078j    4.4530  0.2727
#MA.1   1.0885  +0.0000j    1.0885  0.0000


And forcast code below:

arima_mdl.forecast(steps=200,alpha=0.05)
#array([-8.56316155e-01, -4.25869289e-01, -2.84155971e-01, -2.06066070e-01, -1.62323717e-01, -1.39464719e-01, -1.26609792e-01, -1.18587231e-01,-1.13033412e-01, -1.08753068e-01, -1.05144590e-01, -1.01910598e-01,-9.89029729e-02, -9.60471132e-02, -9.33049505e-02, -9.06565532e-02,-8.80909949e-02, -8.56018380e-02, -8.31848964e-02, -8.08371274e-02,...

I found sm.tsa.arma_generate_sample function helps me to do it as below.

arparams = np.array([1.4031,-0.4380,0.0433,-0.0243])
maparams = np.array([-0.9187])
ar = np.r_[1, -arparams] # add zero-lag and negate
ma = np.r_[1, maparams] # add zero-lag
arimasim = sm.tsa.arma_generate_sample(ar, ma, 3)
arimasim

The code above generated a single scenario for 3 days. By wrapping the logic and map it several times, I could observe the dynamics.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM