Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #+BEGIN_SRC jupyter-python :session woodford :results drawer
- from dsge.symbols import Variable, Equation
- both_terminal = DSGE.read('models/woodford.yaml')
- fix_parameters(both_terminal, gammatilde='gamma', alpha=0.33)
- v_epsxi = Variable('v_epsxi')
- v_epsi = Variable('v_epsi')
- v_epsy = Variable('v_epsy')
- both_terminal['var_ordering'] = both_terminal['var_ordering'] + [v_epsxi, v_epsi, v_epsy]
- both_terminal['perturb_eq'] = (both_terminal['perturb_eq'] +
- [Equation(v_epsxi, both_terminal.shocks[0]),
- Equation(v_epsi, both_terminal.shocks[1]),
- Equation(v_epsy, both_terminal.shocks[2])])
- woodford_both_terminal = both_terminal.compile_model()
- p0 = results.xs(r'Woodford-$\bar\phi$',axis=1).mean()
- p0 = p0[[str(x) for x in both_terminal.parameters]]
- CC, TT, RR, QQ, DD, ZZ, HH = woodford_both_terminal.system_matrices(p0)
- import statsmodels.api as sm
- class my_dsge(sm.tsa.statespace.MLEModel):
- _start_params = p0
- _param_names = [str(x) for x in both_terminal.parameters]
- def __init__(self, endog):
- super().__init__(endog, k_states=TT.shape[0], initialization='stationary')
- self['obs_intercept',:,:] = DD
- self['design',:,:] = ZZ
- self['transition',:,:] = TT
- self['selection',:20,:3] = RR
- self['state_cov',:3,:3] = QQ
- def update(self, params, **kwargs):
- params = super().update(params, **kwargs)
- mleresults = my_dsge(woodford_both_terminal.yy).smooth(p0)
- res = p.DataFrame(mleresults.smoothed_state.T, columns=woodford_both_terminal.state_names, index=woodford_both_terminal.yy.index)
- resf = p.DataFrame(mleresults.filtered_state.T, columns=woodford_both_terminal.state_names, index=woodford_both_terminal.yy.index)
- ax= res.pibar.plot()
- resf.pibar.plot(ax=ax)
- #+END_SRC
- #+RESULTS:
- :RESULTS:
- : <matplotlib.axes._subplots.AxesSubplot at 0x7f72927eb198>
- [[file:./.ob-jupyter/e9642ba614ff6c63a8118aab755d92928e2bb83d.png]]
- :END:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement