Skip to content

Commit e116b25

Browse files
committed
Cleaned up 2nd-order IRF method and added Schmidt-Grohe-Uribe03 example model to test 2nd-order solution method
1 parent a4acd56 commit e116b25

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

pymaclab/dsge/solvers/modsolvers.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,10 +1983,17 @@ def save_sim(self,intup,fpath=None,filtup=None,insim='insim'):
19831983
return "Your plot has been saved in: "+fpath
19841984

19851985

1986-
def irf(self,tlen,sntup):
1986+
def irf(self,tlen,sntup,shockmod=None):
19871987
# Deals with 0-tuples
19881988
if type(sntup) != type((1,2,3)) and type(sntup) == type('abc'):
19891989
sntup = (sntup,)
1990+
# Deal with shockmod, also take care of 0-tuples by turning all into lists
1991+
if shockmod != None and type(shockmod) != type((1,2,3)) and type(shockmod) == type(1.0):
1992+
shockmod = [shockmod,]
1993+
elif shockmod != None and len(shockmod) > 1:
1994+
shockmod = [x for x in shockmod]
1995+
elif shockmod == None:
1996+
shockmod = [1.0,]*len(sntup)
19901997
tlen = tlen + 1
19911998
ncon = self.ncon
19921999
nexo = self.nexo
@@ -2012,21 +2019,24 @@ def irf(self,tlen,sntup):
20122019
return 'Error: '+name+' is not a valid exoshock name for this model!'
20132020
for name in sntup:
20142021
sposli.append(exoli.index(name))
2022+
20152023
# Expose spos choice to self for show_irf
20162024
self.spos = (sntup,sposli)
20172025

20182026
shock = MAT.zeros((nexo,1))
20192027
sendo = MAT.zeros((nendo,1))
20202028

2021-
for spos in sposli:
2022-
shock[spos,0] = 1.0
2029+
for i1,spos in enumerate(sposli):
2030+
shock[spos,0] = 1.0*shockmod[i1]
20232031
shock = MAT.vstack((shock,sendo))
2024-
shock = np.dot(ssigma,shock)
2032+
2033+
self.sshock = COP.deepcopy(shock)
20252034

20262035
x_one_m1 = shock
20272036
x_one_0 = pp*x_one_m1
20282037
x_two_m1 = shock
20292038
y_one_0 = ff*x_one_m1
2039+
# Because they are jump variables
20302040
y_one_m1 = MAT.zeros(y_one_0.shape)
20312041
y_two_0 = 0.5*MAT.kron(MAT.eye(ncon),x_one_m1.T)*ee*x_one_m1
20322042
if self.oswitch:
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
%Model Description+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2+
This is just a standard RBC model, but the one used and paramterized
3+
in Schmidt-Grohe and Uribe's 2004 paper showing the 2nd-order accurate
4+
solution of a fairly standard RBC model
5+
6+
7+
%Model Information+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8+
Name = Standard RBC Model, SGU03;
9+
10+
11+
%Parameters++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12+
alpha = 0.3;
13+
delta = 1.0;
14+
betta = 0.95;
15+
gamma = 2.0;
16+
rho = 0.0;
17+
z_bar = 1.0;
18+
sigma_eps = 1.0;
19+
20+
21+
%Variable Vectors+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22+
[1] k(t):capital{endo}[log,bk]
23+
[2] c(t):consumption{con}[log,bk]
24+
[4] y(t):output{con}[log,bk]
25+
[4] R(t):rrate{con}[log,bk]
26+
[5] z(t):eps(t):productivity{exo}[log,bk]
27+
28+
%Boundary Conditions++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29+
None
30+
31+
32+
%Variable Substitution Non-Linear System++++++++++++++++++++++++++++++++++++++++++++++++
33+
[1] @inv(t) = k(t)-(1-delta)*k(t-1);
34+
[2] @inv_bar = SS{@inv(t)};
35+
[2] @F(t) = z(t-1)*k(t-1)**alpha;
36+
[2] @Fk(t) = DIFF{@F(t),k(t-1)};
37+
[2] @Fk_bar = SS{@Fk(t)};
38+
[2] @F_bar = SS{@F(t)};
39+
[4] @U(t) = @I{gamma!=1.0}{c(t)**(1-gamma)/(1-gamma)}+@I{gamma==1.0}{LOG(c(t))};
40+
[5] @MU(t) = DIFF{@U(t),c(t)};
41+
[5] @MU_bar = SS{@MU(t)};
42+
[6] @MU(t+1) = FF_1{@MU(t)};
43+
44+
45+
46+
%Non-Linear First-Order Conditions++++++++++++++++++++++++++++++++++++++++++++++++++++++
47+
# Insert here the non-linear FOCs in format g(x)=0
48+
49+
[1] y(t)-@inv(t)-c(t) = 0;
50+
[2] betta*(@MU(t+1)/@MU(t))*E(t)|R(t+1)-1 = 0;
51+
[3] @F(t)-y(t) = 0;
52+
[4] R(t) - (1+@Fk(t)-delta) = 0;
53+
[5] LOG(z(t))-rho*LOG(z(t-1))-eps(t) = 0;
54+
55+
56+
%Steady States [Closed Form]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57+
[1] k_bar = ((1/betta-1+delta)/(z_bar*alpha))**(1/(alpha-1));
58+
[2] y_bar = z_bar*k_bar**alpha;
59+
[3] c_bar = y_bar - delta*k_bar;
60+
[4] R_bar = 1/betta;
61+
62+
63+
%Steady State Non-Linear System [Manual]+++++++++++++++++++++++++++++++++++++++++++++++++
64+
None
65+
66+
%Log-Linearized Model Equations++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67+
None
68+
69+
70+
%Variance-Covariance Matrix++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
71+
Sigma = [sigma_eps**2];
72+
73+
74+
%End Of Model File+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

0 commit comments

Comments
 (0)