Exercises For Practical DSGE Modelling: Alina Barnett Martin Ellison
Exercises For Practical DSGE Modelling: Alina Barnett Martin Ellison
DSGE Modelling
Alina Barnett
Martin Ellison
1
1. Interactive MATLAB
Launch MATLAB by double clicking on the appropriate icon. In this first exercise we will use
MATLAB in interactive mode, which means it behaves similarly to a pocket calculator. After
opening, the screen is divided into three parts. In the top right-hand corner is the command
window. It is in here that interactive commands can be typed in and executed immediately.
The top left-hand window shows the current values of all the variables in the system – it is a
glorified version of the memory button on a calculator.
⎛1 2⎞
1. Enter the command A = [1, 2; 3, 4] to define the matrix A = ⎜⎜ ⎟⎟ . Print the matrix
⎝3 4⎠
by typing A in the command window. You should also be able to see A appear as a
current variable in the system. If you click on it you can see its values.
2. Define a second matrix B = [0.5, 0.6; 1, 1.5]. What are the values of C = A*B, C =
B*A, C = A.*B and C = A.^B?
⎛ 2 2⎞
3. Find the inverse of the matrix D = ⎜⎜ ⎟⎟ . To look up the function for inverting
⎝ 1 2 ⎠
⎛ 2 2⎞
matrices type help matfun. What is the inverse of D = ⎜⎜ ⎟⎟ ?
⎝ 1 1 ⎠
4. Use the colon operator to define a row vector X with elements starting from 0 and
proceeding to 100 in steps of 1. The syntax of the command is
(start):(increment):(finish). Check in the memory section that X has been defined
correctly.
5. Define a second vector Y that contains the squares of the values in the elements of
X. Plot the graph of X against Y using the command plot(x,y);
2
2. Drawing from a
normal distribution
In this exercise we use MATLAB’s ability to draw random numbers form a normal
distribution. The numbers drawn are not completely random (for that we would need to sit
for hours rolling a die or tossing a coin) but to all intents and purposes they can be thought
of as random. In fact, there are only 2^1492 random numbers in the computer, but for most
purposes this is more than sufficient.
2. We are now ready to start programming in MATLAB. Open a new M-file from the File
menu and include just the command Z = randn(100,1). Now select debug and run
from the run menu. The end result is just the same as if you had used MATLAB
interactively.
3. The next task is to calculate the mean of the simulated series recursively, i.e. first
calculate the mean of the first element of Z, then the mean of the first two elements
of Z, the first three, and continuing up until the last calculation of the mean of all 100
simulated numbers. In MATLAB, the easiest way to do this is to begin by defining the
random numbers Z. Next, use a for i=1:100 … end loop to calculate the means
recursively. Each time the loop is executed the mean has to be calculated for Z(1:i)
and stored in memory. Complete the exercise by plotting the recursive estimates of
the mean.
4. Repeat the exercise above but for recursive estimation of the variance of the
simulated series. Plot the recursive estimates on the same graph as the mean using
the plot(x,y,’r’);hold on; plot option. Which estimate converges quickest, the mean
or the variance?
5. How many numbers do you need to simulate before the simulated mean is within
0.01 of the theoretical mean of zero? To program this exercise it is easier to use a
while … end loop, in which the condition for continuing the loop is that the absolute
value of the estimated mean is greater than 0.01. Compare you results with the
convergence of the variance estimates. (In this part you may find it useful to start
your program with the command randn(‘state’,0). This forces the computer to use
the same random numbers each time you run the program so guarantees that the
results stay the same).
3
3. Simulating an
AR(1) process
In some models it is assumed that the interest rate followed an AR(1) process of the form
iˆt = ρiˆt −1 + vt . This exercise is designed to simulate the behaviour of interest rates under
such an assumption.
1. Define the shocks vt to the interest rate in the same way as before. To have shocks
with variance 0.1, we need to write vt = 0.1^0.5*randn(100,1).
2. Simulate the series for iˆt using a for … end loop with different values of the
persistence parameter ρ . Use a value of zero for iˆ−1 .
3. What are the theoretical mean and variance of iˆt ? How do the simulated mean and
variance compare with the theoretical values?
4
4. Simulating a Markov-
switching process
Another simple way in which interest rates might be set is to assume they follow a Markov-
switching process. In this scenario, interest rates switch between a discrete set of values,
with switches occurring randomly. The simplest case is one with only two states and
symmetric probabilities of switching between the states. In this exercise we will simulate this
process and examine its behaviour.
1. Suppose that the central bank switches interest rates between the levels of -1% and
+1%. The probability of switching from either -1% to +1% is 5%, i.e. 0.05. Simulate
the behaviour of interest rates for 500 periods. The easiest way to do this is again
with a for … end loop from 1 to 500. To assess whether there has been a switch
each period, make a random draw from a uniform distribution using rand(1,1). If this
number is greater than 1-0.05 = 0.95 then the process should switch. This will ensure
that switches occur on average 5% of the time. A neat trick to use here is that when
there is a switch, the interest rate is equal to the previous period’s interest rate
multiplied by -1. If there is no switch then the previous interest rate prevails.
3. The theoretical mean and variance for this Markov-chain are 0 and 1 respectively.
How do these compare with the mean and variance obtained from simulations?
5
5. Log-linearisation of
baseline model
This exercise is about log-linearisation of the baseline DSGE model presented in the
classes. To make the exercise more concrete, we introduce calibrated values for the
parameters of the model. These numbers, taken from Ellison and Scott (2000) are chosen
so that key-features of the model are matched to the UK economy.
1. Calculate the steady-state value of output, Y , in the economy. Can you explain why
you get quite a nice round answer? Using MATLAB, investigate how Y varies with
the calibrated parameters θ , χ ,η and σ . What is the economic intuition for each of
these relationships?
6
6. Log-linearisation of
an RBC model
The baseline DSGE model we have discussed so far emphasises the role that nominal
shocks play in the determination of output. Another class of models known as Real
Business Cycle (RBC) models, focuses on technology shocks as the dominant source of
output fluctuations. In this exercise, we derive the log-linearised form of a simple RBC
model. The exercise involves considerable work with pencil and paper rather than MATLAB.
In a simple RBC model, the consumer maximises the discounted value of current and
expected future utility from consumption, subject to a budget constraint and the (exogenous)
law of motion for technology. The full problem is given below.
∞
C t1−σ
max E ∑ β t
{C t }
t =0 1−σ
s.t.
C t + K t = At K tα−1 + (1 − δ ) K t −1
ln At +1 = ρ ln At + ε t
The utility function is of the standard CRRA form. The left hand side of the budget constraint
shows expenditure, which is divided between consumption Ct and capital Kt carried forward
to the next period. The right hand side of the budget constraint is correspondingly income,
which derives from the productivity and depreciated value of existing capital, At K tα−1 and
(1 − δ ) K t −1 . δ is the discount rate. Technology is assumed to follow and AR(1) process with
persistence parameter ρ and i.i.d. shocks ε t .
1. Show that the Euler equation for consumption can be written in the following form.
[
C t−σ = Et β C t−+σ1 (αAt +1 K tα −1 + 1 − δ ) ]
Interpret the Euler equation.
2. Find the steady state values A , C , K of technology, consumption and capital in the
model by taking steady-state versions of the Euler equation, budget constraint and
low of motion for technology. How do A , C , K vary with δ , β , α . Why?
3. Log-linearise the first order conditions, i.e. Euler equation, budget constraint and law
of motion for technology, to obtain a 3-dimensional system in At , C t , K t and the shock
ε t . You will need the general formula to log-linearise the budget constraint.
C t1−σ
l im = ln C t
σ →1 1 − σ
Prove that this is correct. To do this, you will need to apply l’Hôpital’s rule, which is repeated
below.
f (σ ) f ' (σ )
If l im f (σ ) = 0 and l im g (σ ) = 0 then l im = l im
σ →1 σ →1 σ →1 g (σ ) σ →1 g ' (σ )
8
8. B-K conditions in
baseline model
This exercise is designed to check whether the Blanchard-Kahn conditions hold in the
baseline model with AR(1) policy shocks. The state-space form of the model is given by
⎛ 1 0 0 ⎞⎛ vt +1 ⎞ ⎛ ρ 0 0 ⎞⎛ vt ⎞ ⎛ 1 ⎞
⎜ ⎟⎜ ⎟ ⎜ −1 ⎟⎜ ⎟ ⎜ ⎟
⎜ 0 1 σ ⎟⎜ Et xˆt +1 ⎟ = ⎜ σ 1 σ −1δ ⎟⎜ xˆt ⎟ + ⎜ 0 ⎟ε t +1
−1
⎜ 0 0 β ⎟⎜ E πˆ ⎟ ⎜ 0 −κ 1 ⎟⎠⎜⎝ πˆ t ⎟⎠ ⎜⎝ 0 ⎟⎠
⎝ ⎠⎝ t t +1 ⎠ ⎝
We use the same calibration as in exercise 6 and ρ = 0.5. The following M-file sets up the
standard state space form A0 Et X t +1 = A1 X t + B0 ε t +1 and calculates the alternative state
space form Et X t +1 = AX t + Bε t +1 . The code is available for download from
http://www2.warwick.ac.uk/fac/soc/economics/staff/faculty/ellison/boe/q8.m
clear;
beta=0.99;
sigma=1;
chi=1.55;
eta=0;
theta=2.064;
omega=0.5;
alpha=3;
delta=1.5;
rho=0.5;
% Calculate kappa
kappa=(1-omega)*(1-beta*omega)/(alpha*omega);
A0=zeros(3,3);
A0(1,1)=1;
A0(2,2)=1;
A0(2,3)=sigma^-1;
A0(3,3)=beta;
A1=zeros(3,3);
A1(1,1)=rho;
A1(2,1)=sigma^-1;
A1(2,2)=1;
A1(2,3)=sigma^-1*delta;
A1(3,2)=-kappa;
A1(3,3)=1;
9
B0=zeros(3,1);
B0(1,1)=1;
A=inv(A0)*A1;
B=inv(A0)*B0;
1. Use the command [p,lambda] = eig(A) to perform the Jordan decomposition of the A
matrix. The p* matrix can be extracted using the command pstar = inv(p). Are the
Blanchard-Kahn conditions satisfied for this calibration of the model? If the
eigenvalues are complex use abs(lambda) to obtain their magnitude.
2. Partition the lambda, pstar and R=Pstar*B matrices. Before doing this, ensure that
the stable eigenvectors (with absolute value less than one) are in the top-left corner
of the lambda matrix and the unstable eigenvectors (with absolute value greater than
one) are in the bottom-right partition of the lambda matrix. If the eigenvalues are in
the wrong places, use the following code to sort them into ascending order.
val=diag(lambda);
t=sortrows([val p’],1);
lambda=diag(t(:,1));
p=t(:,2:4)’;
pstar=inv(p);
10
9. B-K conditions and δ
This exercise investigates the relationship between the Blanchard-Kahn conditions and the
value for δ, the coefficient on inflation in the simple monetary policy rule. We use the same
state-space form as in the previous question, so begin with the following M-file. The code
can be downloaded from
http://www2.warwick.ac.uk/fac/soc/economics/staff/faculty/ellison/boe/q9.m
clear;
beta=0.99;
sigma=1;
chi=1.55;
eta=0;
theta=2.064;
omega=0.5;
alpha=3;
delta=1.5;
rho=0.5;
% Calculate kappa
kappa=(1-omega)*(1-beta*omega)/(alpha*omega);
A0=zeros(3,3);
A0(1,1)=1;
A0(2,2)=1;
A0(2,3)=sigma^-1;
A0(3,3)=beta;
A1=zeros(3,3);
A1(1,1)=rho;
A1(2,1)=sigma^-1;
A1(2,2)=1;
A1(2,3)=sigma^-1*delta;
A1(3,2)=-kappa;
A1(3,3)=1;
B0=zeros(3,1);
B0(1,1)=1;
A=inv(A0)*A1;
B=inv(A0)*B0;
11
% Jordan decomposition of A
[p,lambda] = eig(A);
pstar = inv(p);
val=diag(lambda);
t=sortrows([val p’],1);
lambda=diag(t(:,1));
p=t(:,2:4)’;
pstar=inv(p);
1. What restrictions are required on the parameter δ to ensure that the Blanchard-Kahn
conditions are met? To answer this question, write a for … end loop that checks
whether the Blanchard-Kahn conditions are satisfied for different values of δ from 0
to 2 in steps of 0.1. If the eigenvalues are complex use abs(lambda) to obtain their
magnitude. For each value of δ check that there are 1 stable and 2 unstable roots.
What is the economic intuition for your result?
2. For values of δ which satisfy the Blanchard-Kahn conditions, investigate how the
solved-out equilibrium laws of motion depend on δ. Use the command real(x) to
ignore any extremely small imaginary parts.
12
10. B-K conditions in
RBC model
In exercise 6 you were asked to derive the state-space form of a real business cycle model.
You should have obtained an algebraic equation of the form
The following M-file sets up the state-space form and solves for the Jordan decomposition
for a simple calibration of the model. It is available for download at
http://www2.warwick.ac.uk/fac/soc/economics/staff/faculty/ellison/boe/q10.m
clear;
beta=0.9;
alpha=0.75;
sigma=1;
delta=0.3;
rho=0.95;
kbar=((1-(1-delta)*beta)/(alpha*beta))^(1/(alpha-1));
cbar=kbar^alpha-delta*kbar;
ybar=kbar^alpha;
A0=zeros(3,3);
A0(1,1)=1-(1-delta)*beta;
A0(1,2)=(1-(1-delta)*beta)*(alpha-1);
A0(1,3)=-sigma;
A0(2,2)=kbar;
A0(3,1)=1;
A1=zeros(3,3);
A1(1,3)=-sigma;
A1(2,1)=ybar;
A1(2,2)=alpha*ybar+(1-delta)*kbar;
A1(2,3)=-cbar;
A1(3,1)=rho;
B0=zeros(3,1);
B0(3,1)=1;
13
% Calculate alternative state space matrices
A=inv(A0)*A1;
B=inv(A0)*B0;
% Jordan decomposition of A
[p,lambda] = eig(A);
pstar = inv(p);
val=diag(lambda);
t=sortrows([val p’],1);
lambda=diag(t(:,1));
p=t(:,2:4)’;
pstar=inv(p);
1. Are the Blanchard-Kahn conditions satisfied for this calibration of the model? If the
eigenvalues are complex use abs(lambda) to obtain their magnitude.
2. Can you find alternative calibrations for which the Blanchard-Kahn conditions do not
hold? Use the command real(x) to ignore any extremely small imaginary parts.
14
11. Stylised facts
This exercise asks you to calculate some stylised facts for the baseline model with
persistent interest rate shocks. As a reminder, the state space form and recursive solution
of the model are defined by
⎛ 1 0 0 ⎞⎛ vt +1 ⎞ ⎛ ρ 0 0 ⎞⎛ vt ⎞ ⎛ 1 ⎞
⎜ ⎟⎜ ⎟ ⎜ −1 ⎟⎜ ⎟ ⎜ ⎟
⎜ 0 1 σ ⎟⎜ Et xˆ t +1 ⎟ = ⎜ σ σ −1δ ⎟⎜ xˆ t ⎟ + ⎜ 0 ⎟ε t +1
−1
1
⎜ 0 0 β ⎟⎜ E πˆ ⎟ ⎜ 0
⎝ ⎠⎝ t t +1 ⎠ ⎝ −κ 1 ⎟⎠⎜⎝ πˆ t ⎟⎠ ⎜⎝ 0 ⎟⎠
y t = − P22*−1 P21* wt
wt +1 = ( P11* − P12* P22*−1 P21* ) −1 Λ 1 ( P11* − P12* P22*−1 P21* ) wt + ( P11* − P12* P22*−1 P21* ) −1 R1ε t +1
The MATLAB M-file below calculates the state space form, performs the Jordan
decomposition, and prints out the matrices of the recursive solution to the model. It can be
downloaded from
http://www2.warwick.ac.uk/fac/soc/economics/staff/faculty/ellison/boe/q11.m
clear;
beta=0.99;
sigma=1;
chi=1.55;
eta=0;
theta=2.064;
omega=0.5;
alpha=3;
delta=1.5;
rho=0.5;
% Calculate kappa
kappa=(1-omega)*(1-beta*omega)/(alpha*omega);
A0=zeros(3,3);
A0(1,1)=1;
A0(2,2)=1;
A0(2,3)=sigma^-1;
A0(3,3)=beta;
15
A1=zeros(3,3);
A1(1,1)=rho;
A1(2,1)=sigma^-1;
A1(2,2)=1;
A1(2,3)=sigma^-1*delta;
A1(3,2)=-kappa;
A1(3,3)=1;
B0=zeros(3,1);
B0(1,1)=1;
A=inv(A0)*A1;
B=inv(A0)*B0;
% Jordan decomposition of A
[p,lambda]=eig(A);
pstar=inv(p);
val=diag(lambda);
t=sortrows([val p’],1);
lambda=diag(t(:,1));
p=t(:,2:4)’;
pstar=inv(p);
% Partition matrices
LAMBDA1=lambda(1,1);
LAMBDA2=lambda(2:3,2:3);
P11=pstar(1,1);
P12=pstar(1,2:3);
P21=pstar(2:3,1);
P22=pstar(2:3,2:3);
R=pstar*B;
real(inv(P11-P12*inv(P22)*P21)*LAMBDA1*(P11-P12*inv(P22)*P21));
real(inv(P11-P12*inv(P22)*P21)*R(1));
real(-inv(P22)*P21);
16
1. Using the above code as a starting point, simulate the model for n periods, where n is
a large number such as 1000. To do this, begin by drawing random numbers (of unit
variance) from a normal distribution for the interest rate innovations {εt} using the
command et = randn(n,1). Next, simulate the backward-looking variables {wt}
recursively using a for … end loop. Finally, calculate the forward-looking variables
{yt} directly from the backward-looking variables {wt}. In this model, wt is the
persistent shock vt to the interest rate and yt is a 2 × 1 vector of the output gap and
inflation.
2. Calculate the interest rate each period by applying the simple interest rate rule
iˆt = δπˆ t + vt .
3. Calculate the standard deviations of the interest rate, output gap and inflation using
the command std(x). To ameliorate the effect of starting values, only use simulated
values from 100:(n-1). Do your calculated standard deviations agree with those given
in the lecture? If not, why not?
4. Calculate the correlations between the interest rate, output gap and inflation using
the command corrcoef(X). This command calculates the correlation between the
columns of X so define X as a 900 × 3 vector, in which the columns are the simulated
interest rate, output gap and inflation respectively.
5. Calculate the autocorrelation of the output gap. You can use the same command
corrcoef(X) as before. This time, fill the first column of X with the simulated output
gap observations from 100:(n-1) and the second column with simulated output gap
observations from 99:(n-2). By doing this, you are calculating the correlation
coefficient between the output gap at time t (the first column) and the output at time t-
1 (the second column). Calculating further autocorrelations is a simple generalization
of this procedure.
6. Calculate the cross correlation between the output gap and interest rates at lag 1 and
lead 1. The simplest approach to doing this is to follow the procedure in part (5),
although this time fill the second column of X with interest rate observations from
99:(n-2) for the correlation between the output gap at time t and interest rates at time
t-1, and interest rate observations for 101:n for the correlation between the output
gap at time t and interest rates at time t+1.
17
12. Impulse response
functions
This exercise is about impulse response functions, in our case the response of interest
rates, the output gap and inflation to innovations εt+1 in the interest rate shock vt. The steps
necessary to calculate the impulse responses are very similar to parts (1) and (2) of the
previous exercise performed when simulating the model. In fact, if you want it is possible to
recycle much of the code from the previous exercise when answering this question. The
state space form and recursive solution of the model remain the same:
⎛ 1 0 0 ⎞⎛ vt +1 ⎞ ⎛ ρ 0 0 ⎞⎛ vt ⎞ ⎛ 1 ⎞
⎜ ⎟⎜ ⎟ ⎜ −1 ⎟⎜ ⎟ ⎜ ⎟
⎜ 0 1 σ ⎟⎜ Et xˆ t +1 ⎟ = ⎜ σ σ −1δ ⎟⎜ xˆ t ⎟ + ⎜ 0 ⎟ε t +1
−1
1
⎜ 0 0 β ⎟⎜ E πˆ ⎟ ⎜ 0
⎝ ⎠⎝ t t +1 ⎠ ⎝ −κ 1 ⎟⎠⎜⎝ πˆ t ⎟⎠ ⎜⎝ 0 ⎟⎠
y t = − P22*−1 P21* wt
wt +1 = ( P11* − P12* P22*−1 P21* ) −1 Λ 1 ( P11* − P12* P22*−1 P21* ) wt + ( P11* − P12* P22*−1 P21* ) −1 R1ε t +1
As in the previous exercise, the starting point is a MATLAB M-file to calculate the state
space form, perform the Jordan decomposition, and print out the matrices of the recursive
solution to the model. The code below is identical to that in the previous exercise and can
be downloaded from
http://www2.warwick.ac.uk/fac/soc/economics/staff/faculty/ellison/boe/q12.m
clear;
beta=0.99;
sigma=1;
chi=1.55;
eta=0;
theta=2.064;
omega=0.5;
alpha=3;
delta=1.5;
rho=0.5;
% Calculate kappa
kappa=(1-omega)*(1-beta*omega)/(alpha*omega);
18
% Define state space matrices
A0=zeros(3,3);
A0(1,1)=1;
A0(2,2)=1;
A0(2,3)=sigma^-1;
A0(3,3)=beta;
A1=zeros(3,3);
A1(1,1)=rho;
A1(2,1)=sigma^-1;
A1(2,2)=1;
A1(2,3)=sigma^-1*delta;
A1(3,2)=-kappa;
A1(3,3)=1;
B0=zeros(3,1);
B0(1,1)=1;
A=inv(A0)*A1;
B=inv(A0)*B0;
% Jordan decomposition of A
[p,lambda]=eig(A);
pstar=inv(p);
val=diag(lambda);
t=sortrows([val p’],1);
lambda=diag(t(:,1));
p=t(:,2:4)’;
pstar=inv(p);
% Partition matrices
LAMBDA1=lambda(1,1);
LAMBDA2=lambda(2:3,2:3);
P11=pstar(1,1);
P12=pstar(1,2:3);
P21=pstar(2:3,1);
P22=pstar(2:3,2:3);
R=pstar*B;
19
% Print out matrices of recursive solution of model
real(inv(P11-P12*inv(P22)*P21)*LAMBDA1*(P11-P12*inv(P22)*P21));
real(inv(P11-P12*inv(P22)*P21)*R(1));
real(-inv(P22)*P21);
1. Calculate the response up to horizon h of the output gap and inflation to a unit εt
shock. To do this efficiently, define the shocks {εt} to be zero in all periods except the
first by applying the pair of commands et = zeros(h,1) and et(1) = 1. The response of
the backward-looking variables {wt} can be calculated recursively using a for … end
loop. The forward-looking variables {yt} are calculated as before as a function of the
backward-looking variables. Graph the impulse response functions of the output gap
and inflation using the plot(x,y) command. Are the impulse response functions the
same as those in the lecture? They should be!
2. Calculate the impulse response function for the interest rate by applying the simple
interest rate rule iˆt = δπˆ t + vt . Add this to your graph.
3. What is the impulse response function for the real interest rate? Use the ex post real
interest rate as defined by iˆt − πˆ t .
4. Investigate the consequences for the impulse response function of changing the
degree of persistence ρ in the interest rate shock. What happens if ρ = 0? Do you
appreciate now why we added this persistent shock to make the model more
interesting?
20
13. FEVD
This question is about calculating the forecast error variance decomposition in the simplest
possible model. Unfortunately, the model is not very simple since we need to introduce an
additional shock. FEVD only makes sense if we have more than one shock - in the one-
shock model we have looked at so far, the interest rate shock is responsible for 100% of the
variance in each variable at any horizon (because it is the only shock!).
To allow for a second shock in the system, we introduce persistent cost-push shocks in the
Phillips curve. The model is therefore given by the following structural equations:
xˆ t = Et xˆ t +1 − σ −1 (iˆt − Et πˆ t +1 )
πˆ t = β Et πˆ t +1 + κxˆ t + u t
iˆt = δπˆ t + vt
(1 − ω )(1 − βω )
κ=
αω
The two shocks vt and ut are AR(1) processes with shocks ε tv+1 and ε tu+1 . The shocks
themselves have variances σ v2 and σ u2 .
vt +1 = ρ v vt + ε tv+1
u t +1 = ρ u u t + ε tu+1
⎛1 0 0 0 ⎞⎛ vt +1 ⎞ ⎛ ρ v 0 0 0 ⎞⎛ vt ⎞ ⎛ 1 0⎞
⎜ ⎟⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟
⎜0 1 0 0 ⎟⎜ u t +1 ⎟ ⎜ 0 ρu 0 0 ⎟⎜ u t ⎟ ⎜ 0 1 ⎟⎛ ε tr+1 ⎞
= + ⎜ ⎟
⎜0 0 1 σ −1 ⎟⎜ Et xˆ t +1 ⎟ ⎜ σ −1 0 1 σ −1δ ⎟⎜ xˆ t ⎟ ⎜ 0 0 ⎟⎜⎝ ε tu+1 ⎟⎠
⎜ ⎟⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟
⎜0 0 0 β ⎟⎠⎜⎝ Et πˆ t +1 ⎟⎠ ⎜⎝ 0 −1 − κ 1 ⎟⎠⎜⎝ πˆ t ⎟⎠ ⎜⎝ 0 0 ⎟⎠
⎝
21
We calibrate the model with four additional parameters. The calibration of the other
parameters is the same as before.
The following M-file sets up the state-space form, solves for the Jordan decomposition of
the model, and calculates the impulse response functions. The impulse response functions
are stored in two variables, irf_v and irf_u. irf_v is a 4 × 25 matrix which shows the response
of (vt u t xˆ t πˆ t )' to a unit ε tv shock over the horizons 1 to 25. Each column of irf_v
corresponds to a different horizon. irf_u is a similar 4 × 25 matrix for the response to a unit
ε tu shock. The M-file is available for download at
http://www2.warwick.ac.uk/fac/soc/economics/staff/faculty/ellison/boe/q13.m
% Calibrated parameter values
clear;
beta=0.99;
sigma=1;
chi=1.55;
eta=0;
theta=2.064;
omega=0.5;
alpha=3;
delta=1.5;
rhov=0.5;
rhou=0.8;
sigmav=1;
sigmau=0.5;
% Calculate kappa
kappa=(1-omega)*(1-beta*omega)/(alpha*omega);
22
% Define state space matrices
A0=zeros(4,4);
A0(1,1)=1;
A0(2,2)=1;
A0(3,3)=1;
A0(3,4)=sigma^-1;
A0(4,4)=beta;
A1=zeros(4,4);
A1(1,1)=rhov;
A1(2,2)=rhou;
A1(3,1)=sigma^-1;
A1(3,3)=1;
A1(3,4)=sigma^-1*delta;
A1(4,2)=-1;
A1(4,3)=-kappa;
A1(4,4)=1;
B0=zeros(4,2);
B0(1,1)=1;
B0(2,2)=1;
A=inv(A0)*A1;
B=inv(A0)*B0;
% Jordan decomposition of A
[p,lambda]=eig(A);
pstar=inv(p);
val=diag(lambda);
t=sortrows([val p’],1);
lambda=diag(t(:,1));
p=t(:,2:5)’;
pstar=inv(p);
23
% Partition matrices
LAMBDA1=lambda(1:2,1:2);
LAMBDA2=lambda(3:4,3:4);
P11=pstar(1:2,1:2);
P12=pstar(1:2,3:4);
P21=pstar(3:4,1:2);
P22=pstar(3:4,3:4);
R=pstar*B;
h=20;
irf_v=zeros(4,h);
irf_u=zeros(4,h);
irf_v(1:2,1)=inv(P11-P12*inv(P22)*P21)*R(1:2,:)*[1;0];
irf_u(1:2,1)=inv(P11-P12*inv(P22)*P21)*R(1:2,:)*[0;1]);
i=1;
for i=1:(h-1);
irf_v(1:2,i+1)=inv(P11-P12*inv(P22)*P21)*LAMBDA1*(P11-
P12*inv(P22)*P21)*irf_v(1:2,i);
irf_u(1:2,i+1)=inv(P11-P12*inv(P22)*P21)*LAMBDA1*(P11-
P12*inv(P22)*P21)*irf_u(1:2,i);
end;
irf_u(3:4,:)=-inv(P22)*P21*irf_u(1:2,:);
irf_v(3:4,:)=-inv(P22)*P21*irf_v(1:2,:);
irf_v=real(irf_v);
irf_u=real(irf_u);
24
1. Verify your understanding of the M-file by plotting the response of the output gap and
inflation to the two different types of shocks. Note that the shock in each case is
normalised to 1, not to one standard deviation. It is probably more informative to use
the subplot option to generate a different graph for each set of impulse response
functions.
2. Calculate the impulse response function of the interest rate to each shock using the
formula iˆt = δπˆ t + vt . Add these to the graphs.
∑ (Ψ ) σ
i =1
1 2
i
2
v1
h h
∑ (Ψ ) σ
i =1
1 2
i
2
v1
+ ∑ (Ψi2 ) 2 σ v22
i =1
For each value of h from 1 to 10 in the for … end loop, sum the squares of the
relevant elements of irf_v and irf_u. The FEVD should be calculated from these two
sums, weighted by the corresponding variances of the shocks. Graph your results.
4. Calculate the FEVD for inflation and interest rates and compare them to the results
obtained for output.
5. Investigate how the results change as the relative persistence and/or the relative
variance of the two shocks changes.
25
14. Multi-shock
DSGE model
In this exercise you are required to analyse a version of the baseline DSGE model in which
there are three shocks: interest rate shocks, cost-push shocks and aggregate demand (IS)
shocks. In the analysis you should be able to recycle a lot of the code used before, most
notably from exercises 11 to 13. The basic structure of the model is the same as before,
consisting of a dynamic IS curve, a Phillips curve, and a simple rule for monetary policy.
xˆ t = Et xˆ t +1 − σ −1 (iˆt − Et πˆ t +1 ) + g t
πˆ t = βEt πˆ t +1 + κxˆ t + u t
iˆt = δπˆ t + vt
(1 − ω )(1 − βω )
κ=
αω
⎛ vt +1 ⎞ ⎛ ρ v 0 0 ⎞⎛ vt ⎞ ⎛υ v 0 0 ⎞⎛ ε tv+1 ⎞
⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟⎜ ⎟
⎜ u t +1 ⎟ = ⎜ 0 ρu 0 ⎟⎜ u t ⎟ + ⎜ 0 υ u 0 ⎟⎜ ε tu+1 ⎟
⎜g ⎟ ⎜ 0
⎝ t +1 ⎠ ⎝ 0 ρ g ⎟⎠⎜⎝ g t ⎟⎠ ⎜⎝ 0 0 υ g ⎟⎠⎜⎝ ε tg+1 ⎟⎠
The model is calibrated as before, with the only additional parameters to calibrate being
those relating to the shock processes. For completeness, the full calibration is reported
below:
26
Parameter Calibrated value Explanation
1. Substitute out for the interest rate in the IS curve and write down the state-space
form of the model A0 Et X t +1 = A1 X t + B0 ε t +1 . You should find that Xt is a 5×1 vector
(vt ( )
u t g t xˆ t πˆ t )' and εt is a 3×1 vector ε tv+1 ε tu+1 ε tg+1 ' . The parameter matrices
A0, A1 and B0 are of dimension 5×5, 5×5 and 5×3 respectively.
2. Invert the state space form into the alternative specification Et X t +1 = AX t + Bε t +1 and
perform the Jordan decomposition of the 5×5 matrix A. Check that the Blanchard-
Kahn conditions are satisfied. As there are three backward-looking variables
(vt u t g t ) and two forward-looking variables (xˆ t πˆ t ) in the model, you should
have three stable eigenvalues of magnitude less than 1 and two unstable
eigenvalues of magnitude greater than 1.
27
3. Partition the Xt vector into backward-looking variables w ~ = (v u g )' and forward
t t t t
looking variables y t = ( xˆ t πˆ t )' . Partition also the matrices Λ and P from the Jordan
~
decomposition. Calculate the solution for the equilibrium behaviour of the economy
using the equations
y t = − P22*−1 P21* wt
wt +1 = ( P11* − P12* P22*−1 P21* ) −1 Λ 1 ( P11* − P12* P22*−1 P21* ) wt + ( P11* − P12* P22*−1 P21* ) −1 R1ε t +1
4. Calculate via simulation a series of stylised facts which summarise the behaviour of
this model economy. Pay particular attention to the correlations and cross-
correlations between variables, which are no longer ±1 because there are many
shocks hitting the economy. Do the signs of the correlations match with your
expectations based on the behaviour of the UK economy? If not, why do you think
the model and data are different? How (heuristically) would you change the model to
better match UK data?
5. Derive the responses of interest rates, the output gap and inflation to the three
different shocks. Explain the intuition for the response of each variable to each type
of shock.
6. Which of the three shocks contributes most to fluctuations in interest rates, the output
gap and inflation? The key to answering this is to perform a forecast error variance
decomposition for the three variables. As a reminder, the relevant formula is
∑ (Ψ ) σ
i =1
1 2
i
2
v1
h h
∑ (Ψ ) σ
i =1
1 2
i
2
v1
+ ∑ (Ψi2 ) 2 σ v22
i =1
7. Assume that the welfare of agents in the economy can be measured by the function
∞
min ∑ β i (πˆ t2 + xˆ t2 + 0.1iˆt 2 )
i =0
28
15. DSGE model
with persistence
This exercise is about the effects of introducing ad hoc persistence factors in the baseline
model. Doing so is particularly prevalent in policy circles, following the lead of authors such
as Del Negro-Schorfeide and Smets-Wouters. The persistence factors introduce extra
lagged terms in the dynamic IS equation and the Phillips curve.
h 1
xˆ t = xˆ t −1 + Et xˆ t +1 − σ −1 (iˆt − Et πˆ t +1 )
1+ h 1+ h
γp β
πˆ t = πˆ t −1 + Et πˆ t +1 + κxˆ t
1 + βγ p 1 + βγ p
iˆt = δπˆ t + vt
(1 − ω )(1 − βω )
κ=
αω
Since we are attempting to explain the persistence of the output gap and inflation by the
lagged terms, it no longer makes sense to have persistent interest rate shocks. We
therefore proceed with interest rate shocks being white noise.
vt +1 = ε t +1
The calibration of the economy is standard, except for the parameters on lagged
endogenous variables in the IS and Phillips curves. As a baseline, we take the numbers
estimated by Smets-Wouters for the euroarea economy. The full calibration is
29
Parameter Calibrated value Explanation
1. Substitute out for the interest rate and vt +1 = ε t +1 in the IS curve and write down the
state-space form of the model A0 Et X t +1 = A1 X t + B0 ε t +1 . You should find that Xt is a
4×1 vector (xˆ t −1 πˆ t −1 xˆ t πˆ t )' and εt is a 1×1 vector (ε t +1 ) . Two of the equations in
the state-space form simply connect the second and third terms ( xˆ t πˆ t )' of Xt+1 to
the fourth and fifth terms ( xˆ t πˆ t )' of Xt, for example the first and second rows of the
state-space form take on the following form:
⎛ 1 0 0 0 ⎞ ⎡ xˆ t ⎤ ⎛ 0 0 1 0 ⎞ ⎡ xˆ t −1 ⎤ ⎛ 0 ⎞
⎜ ⎟⎢ ⎥ ⎜ ⎟⎢ ⎥ ⎜ ⎟
⎜ 0 1 0 0 ⎟ ⎢ πˆ t ⎥ ⎜ 0 0 0 1 ⎟ ⎢πˆ t −1 ⎥ ⎜ 0 ⎟
⎜ ⎟ ⎢ E xˆ ⎥ = ⎜ ⎟ ⎢ xˆ ⎥ + ⎜ ⎟ε t +1
⎜ ⎟⎢ t t +1
⎜ ⎟⎢ t ⎥ ⎜ ⎟
⎜ ⎟ E πˆ ⎥ ⎜ ⎟ πˆ ⎜ ⎟
⎝ ⎠ ⎣ t t +1 ⎦ ⎝ ⎠⎣ t ⎦ ⎝ ⎠
30
The parameter matrices A0, A1 and B0 are of dimension 4×4, 4×4 and 4×1
respectively.
2. Invert the state space form into the alternative state space form Et X t +1 = AX t + Bε t +1
and perform the Jordan decomposition of the 4×4 matrix A. Check that the
Blanchard-Kahn conditions are satisfied. As there are two backward-looking
variables (xˆ t −1 πˆ t −1 ) and two forward-looking variables (xˆ t πˆ t ) in the model, you
should have two stable eigenvalues of magnitude less than 1 and two unstable
eigenvalues of magnitude greater than 1.
looking variables y t = ( xˆ t πˆ t )' . Partition also the matrices Λ and P from the Jordan
~
decomposition. Calculate the solution for the equilibrium behaviour of the economy
using the equations
y t = − P22*−1 P21* wt
wt +1 = ( P11* − P12* P22*−1 P21* ) −1 Λ 1 ( P11* − P12* P22*−1 P21* ) wt + ( P11* − P12* P22*−1 P21* ) −1 R1ε t +1
4. Calculate via simulation a series of stylised facts which summarise the behaviour of
this model economy. Pay particular attention to the autocorrelations of the output gap
and inflation. How do these autocorrelations change as the degree of calibrated
persistence in the IS and Phillips varies from 0 to close to 1?
5. Derive the responses of interest rates, the output gap and inflation to the interest rate
shock for different calibrations of the persistence parameters. What degree of
persistence is needed to come close to your view of the degree of persistence of
inflation and the output gap in the UK economy?
31
16. Optimised
Taylor rule
This final exercise takes you through the steps necessary to optimise the coefficients on a
simple Taylor rule. The structure of the economy is given as before by a dynamic IS curve
and Phillips curve, with a Taylor rule for monetary policy.
xˆ t = Et xˆ t +1 − σ −1 (iˆt − Et πˆ t +1 ) + g t
πˆ t = βEt πˆ t +1 + κxˆ t + u t
iˆt = δ π πˆ t + δ x xˆ t + vt
(1 − ω )(1 − βω )
κ=
αω
The interest rate, cost-push and AD shocks are assumed to be an AR(1) processes
⎛ vt +1 ⎞ ⎛ ρ v 0 0 ⎞⎛ vt ⎞ ⎛υ v 0 0 ⎞⎛ ε tv+1 ⎞
⎜ ⎟ ⎜ ⎟⎜ ⎟ ⎜ ⎟⎜ ⎟
⎜ u t +1 ⎟ = ⎜ 0 ρu 0 ⎟⎜ u t ⎟ + ⎜ 0 υ u 0 ⎟⎜ ε tu+1 ⎟
⎜g ⎟ ⎜ 0
⎝ t +1 ⎠ ⎝ 0 ρ g ⎟⎠⎜⎝ g t ⎟⎠ ⎜⎝ 0 0 υ g ⎟⎠⎜⎝ ε tg+1 ⎟⎠
where λx and λi are suitable weights. A full calibration of the economy is given below.
32
Parameter Calibrated value Explanation
1. Substitute out for the interest rate in the IS curve and write down the state-space
form of the model A0 Et X t +1 = A1 X t + B0 ε t +1 for given Taylor rule parameters. You
should find that Xt is a 5×1 vector (vt u t g t xˆ t πˆ t )' and εt is a 3×1 vector
(ε v
t +1 ε tu+1 ε tg+1 )' . The parameter matrices A0, A1 and B0 are of dimension 5×5, 5×5
and 5×3 respectively.
2. Set up a grid for the parameters in the Taylor rule. You will need a row vector indx =
0:0.1:2 to act as an index for the grid points, varying from 0 to 2 in steps of 0.1.
33
3. Proceed to check the Blanchard-Kahn conditions for each combination of Taylor rule
parameters. The easiest way to do this is to loop through the combinations by a pair
of nested for … end loops.
for i = 1:21
for j = 1:21
end
end
For each combination of Taylor rule parameters indexed by i and j, calculate the state
space form A0 Et X t +1 = A1 X t + B0 ε t +1 , recycling the code in part 1. Invert the state
space form into the alternative state space form Et X t +1 = AX t + Bε t +1 and perform the
Jordan decomposition of the 5×5 matrix A. Check that the Blanchard-Kahn conditions
are satisfied. As there are three backward-looking variables (vt u t g t ) and two
forward-looking variables (xˆ t πˆ t ) in the model, you should have three stable
eigenvalues of magnitude less than 1 and two unstable eigenvalues of magnitude
greater than 1. If the Blanchard-Kahn conditions are satisfied for parameters indexed
by i and j, then store the value 1 in the ith row and jth column of a matrix bkij.
Otherwise store 0 in bkij. Storing 1 or 0 in bkij can be achieved easily using the if …
else … end statements.
4. Graph a surface plot of the matrix bkij using the command surface(indx,indx,bkij).
The combinations of Taylor rule parameters for which the Blanchard-Kahn conditions
hold should appear in a different colour than those for which it fails. Can you explain
why the region where the Blanchard-Kahn conditions are satisfied is shaped how it
is?
34
5. The mathematical condition for the Blanchard-Kahn conditions to hold under a
general Taylor rule is κ (δ π − 1) + (1 − β )δ x > 0 . Do your numerical results confirm this?
Do your results shed any further light on the results obtained in exercise 9?
6. Simulate the economy for all combinations of Taylor rule parameters that satisfy the
Blanchard-Kahn conditions. There are two obvious ways to do this. Firstly, you could
loop through all combinations i and j of parameters using a double for … end loop
again, performing a simulation only for those combinations for which bkij is equal to
1. Alternatively, you can combine checking the Blanchard-Kahn conditions and
simulating in the same loops - simply include the simulation in the branch of the if …
else … end that is selected when the Blanchard-Kahn conditions are satisfied.
To simulate the economy for relevant Taylor rule parameters, you will need to
partition the Xt vector into backward-looking variables w ~ = (v u g )' and forward
t t t t
looking variables y = ( xˆ πˆ )' . Partition also the matrices Λ and P from the Jordan
~
t t t
decomposition and calculate the solution for the equilibrium behaviour of the
economy using the equations
y t = − P22*−1 P21* wt
wt +1 = ( P11* − P12* P22*−1 P21* ) −1 Λ 1 ( P11* − P12* P22*−1 P21* ) wt + ( P11* − P12* P22*−1 P21* ) −1 R1ε t +1
For each combination of Taylor rule parameters, simulate the economy and calculate
the variance of simulated inflation, output gap and interest rates. Unconditional
expected welfare is then a weighted average σ π2ˆ + λ xσ x2ˆ + λiσ iˆ2 of these variances.
Store this number in the ith row and jth column of a matrix lossij. If the Blanchard-
Kahn conditions are not satisfied for the row i and column j combination then store a
very high value such as +9999 in lossij.
35
7. Calculate the optimal combination of Taylor rule parameters. The best combination is
that which minimises the loss in lossij. To find out the location of the minimum, use
the MATLAB command [C, I] = max(-lossij) to find the indices of the minimum. The
optimal Taylor rule parameters can then be read off from the elements of I using the
indx vector. Do the parameters you obtain look familiar?
8. This approach to optimisation is rather slow because it relies heavily on brute force to
find the optimal coefficients. A lot of time is wasted particularly in simulating the
economy for each combination of Taylor rule parameters. One way to speed up the
process is to recognise that, for each parameter combination, the equilibrium law of
motion for the economy is linear:
y t = − P22*−1 P21* wt
wt +1 = ( P11* − P12* P22*−1 P21* ) −1 Λ 1 ( P11* − P12* P22*−1 P21* ) wt + ( P11* − P12* P22*−1 P21* ) −1 R1ε t +1
Due to linearity, we can derive the variances of yt and wt directly, without simulation.
Use these analytical formulae to replace the simulations in your code. Do you get the
same results? How much faster is the search for the optimal Taylor rule coefficients
now?
9. Investigate how the optimised Taylor rule coefficients change with the parameters of
the model.
36