# Model Parameters alpha = 0.01 # marginal adjustment cost beta = [0.8, 0.03] # marginal production cost parameters pbar = 1.0 # long-run average market price sigma = 0.2 # market price shock standard deviation delta = 0.9 # discount factor # Deterministic Steady-State sstar = (pbar - beta[0]) / beta[1] # deterministic steady-state state # Continuous State Shock Distribution m = 3 # number of market price shocks mu = np.log(pbar) - sigma ** 2 / 2 # mean log price p, w = qnwlogn(m, mu, sigma ** 2) # market price shocks and probabilities q = np.tile(w, (m, 1)) # market price transition probabilities # Approximation Structure n = 50 # number of collocation nodes smin = 0 # minimum state smax = 20 # maximum state basis = BasisSpline(n, smin, smax, labels=['lagged production']) # basis functions def bounds(s, i, j): return np.zeros_like(s), np.full(s.shape, np.inf) def reward(s, q, i, j):
## FORMULATION # Model Parameters alpha = 0.01 # marginal adjustment cost beta = [0.8, 0.03] # marginal production cost parameters pbar = 1.0 # long-run average market price sigma = 0.2 # market price shock standard deviation delta = 0.9 # discount factor # Deterministic Steady-State sstar = (pbar - beta[0]) / beta[1] # deterministic steady-state state # Continuous State Shock Distribution m = 3 # number of market price shocks mu = np.log(pbar) - sigma**2 / 2 # mean log price p, w = qnwlogn(m, mu, sigma**2) # market price shocks and probabilities q = np.tile(w, (m, 1)) # market price transition probabilities # Approximation Structure n = 50 # number of collocation nodes smin = 0 # minimum state smax = 20 # maximum state basis = BasisSpline(n, smin, smax, labels=['lagged production']) # basis functions def bounds(s, i, j): return np.zeros_like(s), np.full(s.shape, np.inf)
from compecon import BasisChebyshev, DPmodel from demos.setup import np, plt, demo from compecon.quad import qnwlogn ## FORMULATION # Model Parameters a = [1, -2] # producer benefit function parameters b = [2, -3] # recreational user benefit function parameters ymean = 1.0 # mean rainfall sigma = 0.2 # rainfall volatility delta = 0.9 # discount factor # Continuous State Shock Distribution m = 3 # number of rainfall shocks e, w = qnwlogn(m,np.log(ymean)-sigma ** 2/2,sigma ** 2) # rainfall shocks and proabilities # Approximation Structure n = 15 # number of collocation nodes smin = 2 # minimum state smax = 10 # maximum state basis = BasisChebyshev(n, smin, smax, labels=['reservoir']) # basis functions def bounds(s, i, j): return np.zeros_like(s), s.copy() def reward(s, x, i, j):
def reward(s, k, i, j): sk = s - k f = np.log(sk) fx= - sk ** -1 fxx = - sk ** -2 return f, fx, fxx
sigma = 0.1 m=5 e,w = qnwnorm(m, -sigma**2 / 2, sigma**2) growth_model = DPmodel(basis, reward, transition, bounds, x=['Investment'], discount=delta) # ======== Steady-State sstar = (beta * delta) ** (beta / (1 - beta)) # steady-state wealth kstar = beta * delta * sstar # steady-state capital investment vstar = np.log(sstar - kstar) / (1 - delta) # steady-state value pstar = 1 / (sstar * (1 - beta * delta)) # steady-state shadow price b = 1 / (1 - delta * beta) # =========== Compute Analytic Solution at Collocation Nodes vtrue = vstar + b * (np.log(snodes) - np.log(sstar)) ktrue = delta * beta * snodes # Set a refined grid to evaluate the functions #Wealth = np.linspace(smin, smax, n * 10) order = np.atleast_2d([0, 1]) # =========== Solve Bellman Equation options = dict(print=True,
from demos.setup import np, plt, demo from compecon.quad import qnwlogn ## FORMULATION # Model Parameters a = [1, -2] # producer benefit function parameters b = [2, -3] # recreational user benefit function parameters ymean = 1.0 # mean rainfall sigma = 0.2 # rainfall volatility delta = 0.9 # discount factor # Continuous State Shock Distribution m = 3 # number of rainfall shocks e, w = qnwlogn(m, np.log(ymean) - sigma**2 / 2, sigma**2) # rainfall shocks and proabilities # Approximation Structure n = 15 # number of collocation nodes smin = 2 # minimum state smax = 10 # maximum state basis = BasisChebyshev(n, smin, smax, labels=['reservoir']) # basis functions def bounds(s, i, j): return np.zeros_like(s), s.copy() def reward(s, x, i, j): a0, a1 = a