PageRenderTime 1ms CodeModel.GetById 127ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/statsmodels/tsa/vector_ar/tests/example_svar.py

http://github.com/statsmodels/statsmodels
Python | 26 lines | 20 code | 4 blank | 2 comment | 0 complexity | df879db0db3e90688299009ea0ea33d1 MD5 | raw file
 1import numpy as np
 2import statsmodels.api as sm
 3import pandas as pd
 4
 5from statsmodels.tsa.vector_ar.svar_model import SVAR
 6
 7
 8mdatagen = sm.datasets.macrodata.load(as_pandas=False).data
 9mdata = mdatagen[['realgdp','realcons','realinv']]
10names = mdata.dtype.names
11start = pd.datetime(1959, 3, 31)
12end = pd.datetime(2009, 9, 30)
13#qtr = pd.DatetimeIndex(start=start, end=end, freq=pd.datetools.BQuarterEnd())
14qtr = pd.date_range(start=start, end=end, freq='BQ-MAR')
15data = pd.DataFrame(mdata, index=qtr)
16data = (np.log(data)).diff().dropna()
17
18#define structural inputs
19A = np.asarray([[1, 0, 0],['E', 1, 0],['E', 'E', 1]])
20B = np.asarray([['E', 0, 0], [0, 'E', 0], [0, 0, 'E']])
21A_guess = np.asarray([0.5, 0.25, -0.38])
22B_guess = np.asarray([0.5, 0.1, 0.05])
23mymodel = SVAR(data, svar_type='AB', A=A, B=B, freq='Q')
24res = mymodel.fit(maxlags=3, maxiter=10000, maxfun=10000, solver='bfgs')
25res.irf(periods=30).plot(impulse='realgdp', plot_stderr=True,
26                         stderr_type='mc', repl=100)