Closed azev77 closed 4 years ago
You can use the package Interpolations to interpolate the values in result
:
using Interpolations
function simulate(m::AchdouHanLasryLionsMollModel, stategrid, result_ip)
T = 100
yT, aT, cT = zeros(T), zeros(T), zeros(T)
y, a = 1.0, 1.0
for t in 1:T
y += m.κy * (m.ybar - y) + m.σy * rand(Normal())
a += result_ip[:μa](y, a)
yT[t] = y
aT[t] = a
cT[t] = result_ip[:c](y, a)
end
return yT, aT, cT
end
m = AchdouHanLasryLionsMollModel()
stategrid = initialize_stategrid(m)
y0 = initialize_y(m, stategrid)
y, result, distance = pdesolve(m, stategrid, y0)
result_ip = Dict(x => interpolate(tuple(values(stategrid)...), result[x], Gridded(Linear())) for x in keys(result))
yT, aT, cT = simulate(m, stategrid, result_ip)
Is there an easy way to simulate the variables after solving? For example after I solve a simple consumption problem I would like to use the program output to plot for one path of shocks: income over time consumption over time wealth level over time
etc