Dear all,

I am trying to code up a representative agent with the recursive preferences and labor income in an endowment economy.

I wrote down the setup in a latex form here : https://www.dropbox.com/s/s5i5w2qr279r04l/model.pdf?dl=0

I don’t know how to code to compute the endogenous equity returns and equity volatility.

Here is my code.

```
var V S s d y c pi_e pi_b E_t_R_e R_f sigma_e e_y rho E_t_SDF_plus_1;
varexo e_d e_yy
parameters mu_d sigma_d mu_y sigma_y beta gamma psi
mu_d = 0.01;
sigma_d = 0.0705;
mu_y = 0.02;
sigma_y = 0.08;
beta = 0.975;
gamma = 8;
psi = 1.5;
rho = 0;
model;
#theta = (1 - gamma)/(1 - (1/psi));
// Generate a correlated shock
e_y = rho*e_d+sqrt(1-rho^2)*e_yy;
// Define Value function
V = ((1-beta)*c^((1-gamma)/theta) + beta*s^(1/theta))^(theta/(1-gamma));`
// Define an auxiliary variable s that captures E_t[V(+1)^sigma]
s = V(+1)^(1-gamma);
// Euler equation for equity
1 = beta*((V(+1)^(1-gamma))/s)^(1-(1/theta))*(c(+1)/c)^(-1/psi)*(S(+1)+exp(d(+1)))/S;
// Expectation of SDF
E_t_SDF_plus_1 = beta*((V(+1)^(1-gamma))/s)^(1-(1/theta))*(c(+1)/c)^(-1/psi);
//define gross risk-free rate
R_f = 1/E_t_SDF_plus_1;
//define gross return to equity
E_t_R_e = (S(+1)+exp(d(+1)))/S;
//Budget constraint with clearing condition
c = exp(d)+exp(y);
// Law of motion of log dividend
d = d(-1) + mu_d + sigma_d*e_d;
// Law of motion of log labor
y = y(-1) + mu_y + sigma_y*e_y;
end;
steady_state_model
V=c;
s = V^(1-gamma);
E_t_SDF_plus_1 = beta;
E_t_R_e = 1/beta;
R_f=1/E_t_SDF_plus_1;
end;
steady;
check;
shocks;
var e_d; stderr 1;
var e_yy; stderr 1;
end;
%% get second order decision rules
stoch_simul(order=2,periods=100000,drop=1000,irf=0) V S s d y c pi_e pi_b E_t_R_e R_f sigma_e e_y rho E_t_SDF_plus_1;
```