-
Notifications
You must be signed in to change notification settings - Fork 23
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
The Consumption Savings example is solved for one vector of parameters.
I want to do comparative statics: study how the solution changes as the parameter eg ρ changes.
My instinct is to define a function of the parameters, that solves the problem at a given set of parameters:
using InfiniteOpt, Ipopt
ρ = 0.025 # discount rate
k = 100.0 # utility bliss point
T = 10.0 # life horizon
r = 0.05 # interest rate
B0 = 100.0 # endowment
opt = Ipopt.Optimizer # desired solver
ns = 1_000; # number of gridpoints
function f(;ρ=ρ,k=k,T=T,r=r,B0=B0,opt=opt,ns=ns)
u(c; k=k) = -(c - k)^2 # utility function
discount(t; ρ=ρ) = exp(-ρ*t) # discount function
BC(B, c; r=r) = r*B - c # budget constraint
#
m = InfiniteModel(opt)
@infinite_parameter(m, t in [0, T], num_supports = ns)
@variable(m, B, Infinite(t)) ## state variables
@variable(m, c, Infinite(t)) ## control variables
@objective(m, Max, integral(u(c), t, weight_func = discount))
@constraint(m, B == B0, DomainRestrictions(t => 0))
@constraint(m, B == 0, DomainRestrictions(t => T))
@constraint(m, c1, deriv(B, t) == BC(B, c; r=r))
#
optimize!(m)
termination_status(m)
#
c_opt = value(c)
B_opt = value(B)
#
return [c_opt B_opt]
end
# Define a grid of the parameter of interest ρ and solve over the grid:
grid_ρ = [.025, .05, .075]
res = []
for ρ in grid_ρ
push!(res, f(ρ=ρ))
end This doesn't feel like a smart way to do comparative statics (don't know what they call it in your field).
Every time we solve the problem, we don't use the previous solution as a guess etc.
Is there a smarter/more powerful way to do this using your package?
I'm only asking in case there is a known, efficient, better approach to doing this.
Else don't waste time on this...
greimel
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested