options = dict(print=True, algorithm='newton', maxit=253) S = growth_model.solve(vtrue, ktrue, print=True, algorithm='newton', maxit=120) v, pr = growth_model.Value(S.Wealth, order) k = growth_model.Policy(S.Wealth) # resid = growth_model.residuals(s) # ============ Simulate Model T = 20 data = growth_model.simulate(T, np.atleast_2d(smin)) # ============ Compute Linear-Quadratic Approximation growth_model.lqapprox(sstar, kstar) vlq, plq = growth_model.Value(S.Wealth, order) klq = growth_model.Policy(S.Wealth) # ============ Compute Analytic Solution vtrue = vstar + b * (np.log(S.Wealth) - np.log(sstar)) # ============== Make plots: Wealth = S.Wealth.T # Plot Optimal Policy demo.figure('Optimal Investment Policy', 'Wealth', 'Investment') plt.plot(Wealth, np.c_[k, klq]) demo.annotate(sstar, kstar,'$s^*$ = %.2f\n$k^*$ = %.2f' % (sstar, kstar), 'bo', (10, -7))
model = DPmodel(basis, reward, transition, bounds, x=['released'], discount=delta, e=e, w=w) # Deterministic Steady-State xstar = 1 # deterministic steady-state action sstar = 1 + (a[0] *(1-delta)/b[0]) ** (1 / b[1]) # deterministic steady-state stock # Check Model Derivatives # dpcheck(model,sstar,xstar) ## SOLUTION # Compute Linear-Quadratic Approximation at Collocation Nodes model.lqapprox(sstar, xstar) # Solve Bellman Equation model.solve() # no need to pass LQ to model, it's already there resid, s, v, x = model.solution() # Plot Optimal Policy demo.figure('Optimal Irrigation Policy', 'Reservoir Level', 'Irrigation') plt.plot(s, x.T) # Plot Value Function demo.figure('Value Function', 'Reservoir Level', 'Value') plt.plot(s, v.T) # Plot Shadow Price Function demo.figure('Shadow Price Function', 'Reservoir Level', 'Shadow Price')
discount=delta, e=e, w=w) # Deterministic Steady-State xstar = 1 # deterministic steady-state action sstar = 1 + (a[0] * (1 - delta) / b[0])**(1 / b[1] ) # deterministic steady-state stock # Check Model Derivatives # dpcheck(model,sstar,xstar) ## SOLUTION # Compute Linear-Quadratic Approximation at Collocation Nodes model.lqapprox(sstar, xstar) # Solve Bellman Equation model.solve() # no need to pass LQ to model, it's already there resid, s, v, x = model.solution() # Plot Optimal Policy demo.figure('Optimal Irrigation Policy', 'Reservoir Level', 'Irrigation') plt.plot(s, x.T) # Plot Value Function demo.figure('Value Function', 'Reservoir Level', 'Value') plt.plot(s, v.T) # Plot Shadow Price Function demo.figure('Shadow Price Function', 'Reservoir Level', 'Shadow Price')