No stable equilibrium - Portfolio choice

Dear Prof. Pfeiffer,

I am currently working on a model regarding the maturity structure of government debt. Therefore, I tried to model an explicit choice of the household regarding the quantities of both debt assets. Sadly, my code fails and apparently there are 4 variables larger than 1 in modulus but only 3 forward looking variables. I cannot solve this sadly. Do you have some guidance?

Kind regards!

// New Keynesian DSGE Model with Explicit Portfolio Choice

var 
    c          // Consumption
    n          // Labor
    w          // Real wage
    y          // Output
    i_s        // Nominal interest rate (short-term)
    q_L        // Price of long-term bond (perpetuity)
    Pi         // Inflation rate
    mc         // Real marginal cost
    r_s        // Real interest rate (short-term)
    A          // Technology
    g          // Government spending
    b_s        // Short-term government bonds (nominal)
    b_L        // Long-term government bonds (nominal)
    t          // Taxes (real)
    d          // Firm dividends (real)
    spread     // Term spread
    omega      // Debt structure (government policy)
    alpha      // Portfolio share in short-term bonds (household choice)
    h_s        // Household holdings of short-term bonds
    h_L        // Household holdings of long-term bonds
    lambda_p   // Portfolio adjustment cost multiplier
;

varexo 
       e_a     // Technology shock
       e_g     // Government spending shock 
       e_i     // Monetary policy shock
       e_omega // Debt structure shock
       e_pref  // Bond preference shock
;

parameters 
           beta           // Discount factor
           sigma          // Risk aversion
           phi            // Inverse Frisch elasticity
           chi            // Labor disutility weight
           theta          // Calvo parameter (price stickiness)
           kappa          // Phillips curve slope
           rho_pi         // Taylor rule inflation response
           rho_y          // Taylor rule output gap response
           rho_a          // Technology shock persistence
           rho_g          // Government spending shock persistence
           rho_i          // Monetary policy shock standard deviation
           Pi_target      // Inflation target
           i_ss           // Steady state nominal interest rate
           g_ss           // Steady state government spending
           y_ss           // Steady state output
           b_s_ss         // Steady state short-term debt (share of GDP)
           b_L_ss         // Steady state long-term debt (share of GDP)
           omega_ss       // Steady state ratio of st lt debt
           rho_omega      // Persistence of debt structure shock
           gamma_y        // Output growth sensitivity in debt structure rule
           gamma_i        // Interest rate change sensitivity in debt structure rule
           sigma_a        // SD of technology shock
           sigma_g        // SD of government spending shock
           sigma_i        // SD of monetary policy shock
           sigma_omega    // SD of debt structure shock
           sigma_pref     // SD of bond preference shock
           phi_omega      // Debt structure impact on term premium
           tau_b          // Fiscal feedback to debt levels
           tau_omega      // Fiscal response to debt structure changes
           chi_p          // Portfolio adjustment cost parameter
           alpha_ss       // Steady state portfolio share
           psi_L          // Liquidity preference for long-term bonds
           rho_pref       // Persistence of bond preference shock
;

// Parameter values
beta = 0.99;
sigma = 1;
phi = 1;
chi = 1;
theta = 0.75;
kappa = (1-theta)*(1-beta*theta)/theta;
rho_i = 0.8;
rho_pi = 1.5;
rho_y = 0.5/4;
rho_a = 0.9;
rho_g = 0.8;
rho_omega = 0.95;     // Persistence of debt structure (increased for stability)
gamma_y = 0.1;       // Output growth sensitivity (reduced for stability)
gamma_i = 0.1;       // Interest rate change sensitivity (reduced for stability)
sigma_a = 0.025;
sigma_g = 0.025;
sigma_i = 0.025;
sigma_omega = 0.025; // Standard deviation of debt structure shock
sigma_pref = 0.02;   // Bond preference shock SD
Pi_target = 0;
i_ss = (1/beta) - 1;
g_ss = 0.2;
y_ss = 1;
b_s_ss = 0.3*4*y_ss; // 30% of GDP in short-term debt
omega_ss = 5.5;      // ratio of long-term to short-term debt in st st (~20% st debt)
b_L_ss = omega_ss*b_s_ss;  // 60% of GDP in long-term debt
phi_omega = 0.05;    // Impact of debt structure on term premium
tau_b = 0.3;         // Fiscal feedback to debt levels
tau_omega = 0.05;    // Fiscal response to debt composition

chi_p = 0.5;         // Portfolio adjustment cost
alpha_ss = 1/(1+omega_ss); // Steady state portfolio share consistent with govt debt ratio
psi_L = 0.01;        // Base liquidity preference for long-term bonds
rho_pref = 0.7;      // Persistence of bond preference shock

model;
    // 1. Modified Euler equation for short-term bonds with portfolio choice
    c^(-sigma)*(1 + lambda_p) = beta*(1+i_s)*c(+1)^(-sigma)/(1+Pi(+1));
    
    // 2. Modified Euler equation for long-term bonds with portfolio choice
    c^(-sigma)*(1 + lambda_p) = beta*c(+1)^(-sigma)*(q_L(+1) + 1)/(q_L*(1+Pi(+1))) + psi_L*exp(e_pref);
    
    // 3. Portfolio adjustment cost (quadratic in deviation from optimal)
    lambda_p = chi_p*(alpha - alpha_ss)^2;
    
    // 4. Portfolio share definition
    alpha = h_s/(h_s + q_L*h_L);
    
    // 5. Household budget constraint with bond holdings
    c + h_s + q_L*h_L = w*n + d + (1+i_s(-1))*h_s(-1)/(1+Pi) + (q_L+1)*h_L(-1)/(1+Pi) - t;
    
    // 6. Labor supply
    chi*n^phi*c^sigma = w;
    
    // 7. NK Phillips curve
    Pi = beta*Pi(+1) + kappa*mc;
    
    // 8. Marginal cost
    mc = w/A;
    
    // 9. Production function
    y = A*n;
    
    // 10. Market clearing
    y = c + g;
    
    // 11. Bond market clearing conditions
    h_s = b_s;
    
    // 12. Government budget constraint
    b_s/(1+Pi) + q_L*b_L/(1+Pi) = g + (1+i_s(-1))*b_s(-1)/(1+Pi) + (q_L+1)*b_L(-1)/(1+Pi) - t;
    
    // 13. Government debt issuance policy
    b_L = omega*b_s;
    
    // 14. Enhanced tax rule with debt composition feedback
    t = tau_b*((b_s(-1)+q_L(-1)*b_L(-1))/y) + 0.05*g + tau_omega*(omega - omega_ss);

    // 15. Taylor rule with stronger inflation response
    i_s = rho_i*i_s(-1) + (1-rho_i)*(i_ss + 2.0*(Pi-Pi_target) + rho_y*(y-y_ss)) + e_i;
    
    // 16. Technology shock
    log(A) = rho_a*log(A(-1)) + e_a;
    
    // 17. Government spending shock
    log(g) = (1-rho_g)*log(g_ss) + rho_g*log(g(-1)) + e_g;
    
    // 18. Fisher equation
    1+r_s = (1+i_s)/(1+Pi(+1));
    
    // 19. Firm profits/dividends (in real terms)
    d = y - w*n;
    
    // 20. Term spread definition
    spread = 1/q_L - (1+i_s);

    // 21. Government debt structure policy
    log(omega) = (1-rho_omega)*log(omega_ss) + rho_omega*log(omega(-1)) - gamma_y*(y-y(-1)) - gamma_i*(i_s-i_s(-1)) - e_omega;
end;


initval;
    A = 1;
    g = g_ss;
    Pi = Pi_target;
    i_s = i_ss;
    r_s = (1/beta) - 1;
    q_L = beta/(1-beta);  // Steady state price of perpetuity bond
    mc = 1;
    w = A;
    y = y_ss;
    c = y - g;
    n = y/A;
    omega = omega_ss;
    b_s = b_s_ss*(1+Pi);
    b_L = b_L_ss*(1+Pi);
    h_s = b_s;
    h_L = b_L;
    alpha = 1/(1+omega_ss);
    lambda_p = 0;
    t = g + (i_ss*b_s_ss + b_L_ss/q_L);
    d = y - w*n;
    spread = 1/q_L - (1+i_s);
end;

steady;
check;
model_diagnostics;

shocks;
    var e_a = sigma_a^2;
    var e_g = sigma_g^2;
    var e_i = sigma_i^2;
    var e_omega = sigma_omega^2;
    var e_pref = sigma_pref^2;
end;

stoch_simul(order=1, irf=40) y Pi i_s r_s q_L b_s b_L alpha spread;

Most often it’s a timing problem, but in your case the following seems relevant: