Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulate results from EconPDEs #13

Closed
azev77 opened this issue Jan 19, 2020 · 1 comment
Closed

Simulate results from EconPDEs #13

azev77 opened this issue Jan 19, 2020 · 1 comment

Comments

@azev77
Copy link

azev77 commented Jan 19, 2020

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

@matthieugomez
Copy link
Owner

matthieugomez commented Jan 20, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants