Income fluctuation problem


I am using the ifp.ipynb code from the quantecon website to work through an income fluctuation problem. 41. Optimal Savings III: Occasionally Binding Constraints — Quantitative Economics with Julia.

I’m having an issue where consumption is exceeding income even though households are not being allowed to borrow. I’m following the code exactly but I modified the section to compute the asset series as follows to store the consumption and income values. I’m not sure what is going wrong. Thanks

function compute_asset_series(cp, T = 1000; verbose = false)
    (; Pi, z_vals, R) = cp  # simplify names
    z_idx = 1:length(z_vals)
    v_init, c_init = initialize(cp)
    c = compute_fixed_point(x -> K(cp, x), c_init,
                            max_iter = 150, verbose = false)

    cf = interp(cp.asset_grid, c)

    a_path = zeros(T + 1) # Array to store the path of assets
    c_path = zeros(T)  # Array to store the path of consumption
    z_path = zeros(T)  # Array to store the path of y
    state_path = simulate(MarkovChain(Pi), T)
    for t in 1:T
        i_z = state_path[t]
        z_path[t] = z_vals[i_z]  # Store the current value of y
        c_path[t] = cf(a_path[t], i_z)  # Compute consumption at time t
        a_path[t + 1] = R * a_path[t] + z_path[t] - c_path[t]  # Update asset for next period
    return a_path[1:end-1], c_path, z_path  # Return a tuple containing asset path, consumption path, and income path