def acovf_explicit(ar, ma, nobs): """add correlation of MA representation explicitely """ ir = arma_impulse_response(ar, ma) acovfexpl = [np.dot(ir[: nobs - t], ir[t:nobs]) for t in range(10)] return acovfexpl
def acovf_explicit(ar, ma, nobs): '''add correlation of MA representation explicitely ''' ir = arma_impulse_response(ar, ma) acovfexpl = [np.dot(ir[:nobs - t], ir[t:nobs]) for t in range(10)] return acovfexpl
>>> # verified for points [[5,10,20,25]] at 4 decimals with Bhardwaj, Swanson, Journal of Eonometrics 2006 ''' print lpol_fiar(0.4, n=20) print lpol_fima(-0.4, n=20) print np.sum((lpol_fima(-0.4, n=n)[1:] + riinv[1:])**2) #different signs print np.sum((lpol_fiar(0.4, n=n)[1:] - riinv[1:])**2) #corrected signs #test is now in statsmodels.tsa.tests.test_arima_process from scikits.statsmodels.tsa.tests.test_arima_process import test_fi test_fi() ar_true = [1, -0.4] ma_true = [1, 0.5] ar_desired = arma_impulse_response(ma_true, ar_true) ar_app, ma_app, res = ar2arma(ar_desired, 2,1, n=100, mse='ar', start=[0.1]) print ar_app, ma_app ar_app, ma_app, res = ar2arma(ar_desired, 2,2, n=100, mse='ar', start=[-0.1, 0.1]) print ar_app, ma_app ar_app, ma_app, res = ar2arma(ar_desired, 2,3, n=100, mse='ar')#, start = [-0.1, 0.1]) print ar_app, ma_app slow = 1 if slow: ar_desired = lpol_fiar(0.4, n=100) ar_app, ma_app, res = ar2arma(ar_desired, 3, 1, n=100, mse='ar')#, start = [-0.1, 0.1]) print ar_app, ma_app ar_app, ma_app, res = ar2arma(ar_desired, 10, 10, n=100, mse='ar')#, start = [-0.1, 0.1]) print ar_app, ma_app
-0.00231864]) >>> # verified for points [[5,10,20,25]] at 4 decimals with Bhardwaj, Swanson, Journal of Eonometrics 2006 ''' print lpol_fiar(0.4, n=20) print lpol_fima(-0.4, n=20) print np.sum((lpol_fima(-0.4, n=n)[1:] + riinv[1:])**2) #different signs print np.sum((lpol_fiar(0.4, n=n)[1:] - riinv[1:])**2) #corrected signs #test is now in statsmodels.tsa.tests.test_arima_process from scikits.statsmodels.tsa.tests.test_arima_process import test_fi test_fi() ar_true = [1, -0.4] ma_true = [1, 0.5] ar_desired = arma_impulse_response(ma_true, ar_true) ar_app, ma_app, res = ar2arma(ar_desired, 2, 1, n=100, mse='ar', start=[0.1]) print ar_app, ma_app ar_app, ma_app, res = ar2arma(ar_desired, 2, 2, n=100, mse='ar', start=[-0.1, 0.1]) print ar_app, ma_app ar_app, ma_app, res = ar2arma(ar_desired, 2, 3, n=100,
def test_arma_impulse_response(): arrep = arma_impulse_response(armarep.ma, armarep.ar, nobs=21)[1:] marep = arma_impulse_response(armarep.ar, armarep.ma, nobs=21)[1:] assert_array_almost_equal(armarep.marep.ravel(), marep, 14) #difference in sign convention to matlab for AR term assert_array_almost_equal(-armarep.arrep.ravel(), arrep, 14)
def test_fi(): #test identity of ma and ar representation of fi lag polynomial n = 100 mafromar = arma_impulse_response(lpol_fiar(0.4, n=n), [1], n) assert_array_almost_equal(mafromar, lpol_fima(0.4, n=n), 13)
from scikits.statsmodels.tsa.arima_process import arma_generate_sample, arma_impulse_response from scikits.statsmodels.tsa.arima_process import arma_acovf, arma_acf, ARIMA # from movstat import acf, acovf # from scikits.statsmodels.sandbox.tsa import acf, acovf, pacf from scikits.statsmodels.tsa.stattools import acf, acovf, pacf ar = [1.0, -0.6] # ar = [1., 0.] ma = [1.0, 0.4] # ma = [1., 0.4, 0.6] # ma = [1., 0.] mod = "" #'ma2' x = arma_generate_sample(ar, ma, 5000) x_acf = acf(x)[:10] x_ir = arma_impulse_response(ar, ma) # print x_acf[:10] # print x_ir[:10] # irc2 = np.correlate(x_ir,x_ir,'full')[len(x_ir)-1:] # print irc2[:10] # print irc2[:10]/irc2[0] # print irc2[:10-1] / irc2[1:10] # print x_acf[:10-1] / x_acf[1:10] # detrend helper from matplotlib.mlab def detrend(x, key=None): if key is None or key == "constant": return detrend_mean(x) elif key == "linear": return detrend_linear(x)
from scikits.statsmodels.tsa.arima_process import arma_generate_sample, arma_impulse_response from scikits.statsmodels.tsa.arima_process import arma_acovf, arma_acf, ARIMA #from movstat import acf, acovf #from scikits.statsmodels.sandbox.tsa import acf, acovf, pacf from scikits.statsmodels.tsa.stattools import acf, acovf, pacf ar = [1., -0.6] #ar = [1., 0.] ma = [1., 0.4] #ma = [1., 0.4, 0.6] #ma = [1., 0.] mod = '' #'ma2' x = arma_generate_sample(ar, ma, 5000) x_acf = acf(x)[:10] x_ir = arma_impulse_response(ar, ma) #print x_acf[:10] #print x_ir[:10] #irc2 = np.correlate(x_ir,x_ir,'full')[len(x_ir)-1:] #print irc2[:10] #print irc2[:10]/irc2[0] #print irc2[:10-1] / irc2[1:10] #print x_acf[:10-1] / x_acf[1:10] # detrend helper from matplotlib.mlab def detrend(x, key=None): if key is None or key == 'constant': return detrend_mean(x) elif key == 'linear':