## FORMULATION # Model Parameters A = 6 # maximum asset age alpha = np.array([50, -2.5, -2.5]) # production function coefficients kappa = 40 # net replacement cost pbar = 1 # long-run mean unit profit gamma = 0.5 # unit profit autoregression coefficient sigma = 0.15 # standard deviation of unit profit shock delta = 0.9 # discount factor # Continuous State Shock Distribution m = 5 # number of unit profit shocks [e,w] = qnwnorm(m,0,sigma ** 2) # unit profit shocks and probabilities # Deterministic Discrete State Transitions h = np.zeros((2, A)) h[0, :-1] = np.arange(1, A) # Approximation Structure n = 200 # number of collocation nodes pmin = 0 # minimum unit profit pmax = 2 # maximum unit profit basis = BasisSpline(n, pmin, pmax, labels=['unit profit']) # basis functions # Model Structure def profit(p, x, i, j): a = i + 1
from compecon.tools import example ''' Example in page 3 ''' example(3) p = 0.25 for i in range(100): deltap = (.5 * p **-.2 + .5 * p ** -.5 - 2)/(.1 * p **-1.2 + .25 * p **-1.5) p += deltap if abs(deltap) < 1.e-8: break print('Price = ', p) ''' Example in page 4 ''' example(4) y, w = qnwnorm(10, 1, 0.1) a = 1 for it in range(100): aold = a p = 3 - 2 * a * y f = w.dot(np.maximum(p, 1)) a = 0.5 + 0.5 * f if abs(a - aold) < 1.e-8: break print('Acreage = ', a) print('Expected market price = ', np.dot(w, p)) print('Expected effective producer price = ', f)
# r = 0.1 # annual interest rate # N = 300 # number of time intervals # dt = T/N # length of time interval # delta = exp(-r*dt) # per period discount factor # mu = dt*(r-sigma ** 2/2) # mean of log price innovation # Model Parameters K = 1.0 # option strike price N = 300 # number of periods to expiration mu = 0.0001 # mean of log price innovation sigma = 0.0080 # standard devitation of log price innovation delta = 0.9998 # discount factor # Continuous State Shock Distribution m = 15 # number of price shocks [e, w] = qnwnorm(m, mu, sigma**2) # price shocks and probabilities # Approximation Structure n = 500 # number of collocation nodes pmin = -1 # minimum log price pmax = 1 # maximum log price Value = BasisSpline(n, pmin, pmax, labels=['logprice'], l=['value']) # basis functions # p = funnode(basis) # collocaton nodes # Phi = funbase(basis) # interpolation matrix ## SOLUTION # Intialize Value Function # c = zeros(n,1) # conditional value function basis coefficients
## FORMULATION # Model Parameters alpha = np.array([[0.9, -0.1]]).T # transition function constant coefficients beta = np.array([[-0.5, 0.2], [0.3, -0.4]]) # transition function state coefficients gamma = np.array([[-0.1, 0.0]]).T # transition function action coefficients omega = np.identity(2) # central banker's preference weights sbar = np.array([[1, 0]]).T # equilibrium targets sigma = 0.08 * np.identity(2), # shock covariance matrix delta = 0.9 # discount factor # Continuous State Shock Distribution m = [3, 3] # number of shocks mu = [0, 0] # means of shocks [e,w] = qnwnorm(m,mu,sigma) # shocks and probabilities # Approximation Structure n = 21 # number of collocation coordinates, per dimension smin = [-2, -3] # minimum states smax = [ 2, 3] # maximum states basis = BasisChebyshev(n, smin, smax, method='complete', labels=['GDP gap', 'inflation']) # basis functions print(basis) def bounds(s, i, j): lb = np.zeros_like(s[0]) ub = np.full(lb.shape, np.inf) return lb, ub
## FORMULATION # Model Parameters u = 90 # unemployment benefit v = 95 # benefit of pure leisure wbar = 100 # long-run mean wage gamma = 0.40 # wage reversion rate p0 = 0.20 # probability of finding job p1 = 0.90 # probability of keeping job sigma = 5 # standard deviation of wage shock delta = 0.95 # discount factor # Continuous State Shock Distribution m = 15 # number of wage shocks e, w = qnwnorm(m, 0, sigma**2) # wage shocks # Stochastic Discrete State Transition Probabilities q = np.zeros((2, 2, 2)) q[1, 0, 1] = p0 q[1, 1, 1] = p1 q[:, :, 0] = 1 - q[:, :, 1] # Model Structure # Approximation Structure n = 150 # number of collocation nodes wmin = 0 # minimum wage wmax = 200 # maximum wage basis = BasisSpline(n, wmin, wmax, labels=['wage']) # basis functions
## FORMULATION # Model Parameters alpha = np.array([[0.9, -0.1]]).T # transition function constant coefficients beta = np.array([[-0.5, 0.2], [0.3, -0.4]]) # transition function state coefficients gamma = np.array([[-0.1, 0.0]]).T # transition function action coefficients omega = np.identity(2) # central banker's preference weights sbar = np.array([[1, 0]]).T # equilibrium targets sigma = 0.08 * np.identity(2), # shock covariance matrix delta = 0.9 # discount factor # Continuous State Shock Distribution m = [3, 3] # number of shocks mu = [0, 0] # means of shocks [e, w] = qnwnorm(m, mu, sigma) # shocks and probabilities # Approximation Structure n = 21 # number of collocation coordinates, per dimension smin = [-2, -3] # minimum states smax = [2, 3] # maximum states basis = BasisChebyshev(n, smin, smax, method='complete', labels=['GDP gap', 'inflation']) # basis functions print(basis)