how to write an rbc model in matlab

To write an RBC (Real Business Cycle) model in Matlab, we need to follow these steps:

  1. Define the model's equations: We follow the standard RBC model that includes households, firms, and a production function. Below are the equations:

Household optimization problem:

\begin{aligned} V(k_t,z_t,\epsilon_t)&=\max_{c_t,k_{t+1}}E_{t}\sum_{n=0}^\infty\beta^n u(c_{t+n})\ \text{subject to:}\ c_t+k_{t+1}&=(1-\delta)k_t+f(k_t,z_t)\ c_t&=\epsilon_t k_t^\alpha+(1-\alpha)z_t\ \log z_{t+1}&=\rho \log z_t+\varepsilon_{t+1}
\end{aligned}

where:

  • k_t: capital at time t
  • z_t: technology level (total factor productivity)
  • epsilon_t: productivity shock at time t
  • c_t: consumption at time t
  • f(k_t,z_t): production function
  • delta: depreciation rate
  • alpha: output elasticity of capital
  • rho: persistence of productivity shock
  • epsilon_{t+1}: innovation shock
  1. Define the parameters and solve the model:

To solve the model, we will use a combination of numerical methods. The code below defines the parameters:

main.m
alpha = 0.33;   % output elasticity of capital
beta = 0.95;    % discount factor
delta = 0.1;    % depreciation rate
rho = 0.9;      % autocorrelation of technology shock
sigma_e = 0.02; % standard deviation of technology shock
228 chars
6 lines
  1. Define the simulation horizon:
main.m
T = 200;        % number of periods to simulate
48 chars
2 lines
  1. Compute the steady-state values:

The steady-state is computed analytically as follows:

main.m
r = 1/beta - 1 + delta;
k_ss = (alpha/(1/beta - (1 - delta)))^(1/(1-alpha));
c_ss = k_ss^alpha - delta*k_ss;
109 chars
4 lines
  1. Run the simulation:

The code below simulates the RBC model:

main.m
k = zeros(T,1); % initialize capital vector
z = zeros(T,1); % initialize technology vector
e = randn(T,1)*sigma_e; % generate technology shocks
k(1) = k_ss;    % set initial capital to steady-state
for t=2:T
    % compute consumption
    c = k(t-1)^alpha + (1-delta)*k(t-1) - k(t);
    z(t) = rho*z(t-1) + e(t); % update technology
    k(t+1) = alpha*beta*(k(t)^alpha)*(exp(z(t)))^(1-alpha) + ...
        (1-delta)*k(t) - c; % update capital
end

% compute output and consumption
y = k(2:end).^alpha.*(exp(z(2:end)));
c = y - k(3:end) + (1-delta)*k(2:end);
557 chars
16 lines

The variables y and c contain the output and consumption generated by the model.

Note: this is a basic example of an RBC model, and it can be extended to include more complex features such as multiple sectors or a government sector.

gistlibby LogSnag