-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeghna_Python.py
More file actions
75 lines (54 loc) · 2.14 KB
/
Copy pathMeghna_Python.py
File metadata and controls
75 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# coding: utf-8
# In[ ]:
"""
Value Iteration for the One Sector Growth Model with Convex Adjutment Costs(deterministic)
"""
# Log utility
# F(k) = k**alpha
# Convex adjustment costs = phi*i(t)/2*k(t) per unit of i(t)
# Budget Constraint: F(k(t)) = c(t) + (1 + phi*i(t)/2*k(t))*i(t)
# Capital accumulation: k(t+1) = (1 - delta)*k(t) + i(t)
# Total supply: f(k(t)) = F(k(t)) + (1-delta)*k(t)
from scipy import linspace, interp # for grid and linear interpolation
from scipy.optimize import fminbound
import numpy as np
import matplotlib.pyplot as plt
# specify parameters and return (period Utility) function
delta,alpha,beta,phi = 0.3,0.8,0.9,1
# depreciation rate, production exponent, discount factor, coefficient of adjustment costs are above
# the period utility is below, as a function of current capital stock k
# and next period's capital stock y
def U(k,y):
return np.log(k**alpha + (1-delta)*k -(phi/(2*k))*(y - (1- delta)*k)**2 - y)
# specify the steady state capital stock
kstar = ((2 + 2*phi*delta - 2*beta - 2*phi*beta*delta + 2*beta*delta + phi*beta*(delta)**2)/2*beta*alpha)**(1/(alpha-1))
# steady state capital stock has been calculated manually
# at the intersection of q(t+1) - q(t) = k(t+1) - k(t) = 0
# We get qstar = 1 + phi(istar/kstar) = 1 +phi*delta (since at steady state i = delta*k, from k(t+1) = k(t))
#Subsitute qstar and istar into FOC for k(t+1) to get required kstar
# specify grid around steady state capital stock
gridsize=1000
gridmin=1 # so log of this is a positive capital stock
gridmax=1.2*kstar
grid=linspace(gridmin**1e-1,gridmax**1e-1,gridsize)**10
# specify the Bellman operator
def argmax(h,a,b):
return fminbound(lambda x:-h(x),a,b)
def maximum(h,a,b):
return h(fminbound(lambda x:-h(x),a,b))
def bellman(w):
Tw=[]
for k in grid:
rhs = lambda y: U(k,y) + beta*w(y)
Tw.append(maximum(rhs,gridmin,k))
return lambda x:interp(x,grid,Tw)
# specify Value Iteration
valfunc=lambda x: x
tol=0.001
while 1:
plt.plot(grid,valfunc(grid),'r-')
newvalfunc=bellman(valfunc)
if max(abs(newvalfunc(grid)-valfunc(grid))) < tol:
break
valfunc=newvalfunc
plt.show()