Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #+BEGIN_SRC jupyter-python :session woodford :results drawer
  2. from dsge.symbols import Variable, Equation
  3. both_terminal = DSGE.read('models/woodford.yaml')
  4. fix_parameters(both_terminal, gammatilde='gamma', alpha=0.33)
  5. v_epsxi = Variable('v_epsxi')
  6. v_epsi = Variable('v_epsi')
  7. v_epsy = Variable('v_epsy')
  8. both_terminal['var_ordering'] = both_terminal['var_ordering'] + [v_epsxi, v_epsi, v_epsy]
  9. both_terminal['perturb_eq'] = (both_terminal['perturb_eq'] +
  10. [Equation(v_epsxi, both_terminal.shocks[0]),
  11. Equation(v_epsi, both_terminal.shocks[1]),
  12. Equation(v_epsy, both_terminal.shocks[2])])
  13.  
  14. woodford_both_terminal = both_terminal.compile_model()
  15.  
  16. p0 = results.xs(r'Woodford-$\bar\phi$',axis=1).mean()
  17. p0 = p0[[str(x) for x in both_terminal.parameters]]
  18. CC, TT, RR, QQ, DD, ZZ, HH = woodford_both_terminal.system_matrices(p0)
  19.  
  20. import statsmodels.api as sm
  21.  
  22. class my_dsge(sm.tsa.statespace.MLEModel):
  23.  
  24. _start_params = p0
  25. _param_names = [str(x) for x in both_terminal.parameters]
  26.  
  27. def __init__(self, endog):
  28. super().__init__(endog, k_states=TT.shape[0], initialization='stationary')
  29.  
  30. self['obs_intercept',:,:] = DD
  31. self['design',:,:] = ZZ
  32. self['transition',:,:] = TT
  33. self['selection',:20,:3] = RR
  34. self['state_cov',:3,:3] = QQ
  35.  
  36. def update(self, params, **kwargs):
  37. params = super().update(params, **kwargs)
  38.  
  39. mleresults = my_dsge(woodford_both_terminal.yy).smooth(p0)
  40. res = p.DataFrame(mleresults.smoothed_state.T, columns=woodford_both_terminal.state_names, index=woodford_both_terminal.yy.index)
  41. resf = p.DataFrame(mleresults.filtered_state.T, columns=woodford_both_terminal.state_names, index=woodford_both_terminal.yy.index)
  42. ax= res.pibar.plot()
  43. resf.pibar.plot(ax=ax)
  44. #+END_SRC
  45.  
  46. #+RESULTS:
  47. :RESULTS:
  48. : <matplotlib.axes._subplots.AxesSubplot at 0x7f72927eb198>
  49. [[file:./.ob-jupyter/e9642ba614ff6c63a8118aab755d92928e2bb83d.png]]
  50. :END:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement