In [1]:
include("bansal_yaron_parameters.jl")
include("bansal_yaron_interpolation.jl")
In [20]:
using PyPlot
plt = PyPlot
Out[20]:
In [21]:
ez = EpsteinZinBY()
sv = StochasticVolatilityBY()
Out[21]:
In [22]:
ez.θ
Out[22]:
In [23]:
σ_min, σ_max, σ_gridsize = 1e-6, 0.015, 12
z_min, z_max, z_gridsize = -0.015, 0.015, 12
σ_grid = linspace(σ_min, σ_max, σ_gridsize)
z_grid = linspace(z_min, z_max, z_gridsize)
Out[23]:
In [43]:
shock_size = 50
η_vec = randn(shock_size)
ω_vec = randn(shock_size)
w_in = ones(z_gridsize, σ_gridsize) * 100
w_out = similar(w_in)
tol = 1e-4
error = tol + 1
max_iter = 8000
iter = 0
while error > tol && iter < max_iter
T_interp(ez, sv, w_in, w_out, z_grid, σ_grid, η_vec, ω_vec)
error = maximum(abs, w_in - w_out)
copy!(w_in, w_out)
iter += 1
end
In [24]:
iter
Out[24]:
In [42]:
error
Out[42]:
In [40]:
w = w.^(1 / (1 - 1 / ez.ψ))
Out[40]:
In [80]:
using QuantEcon: meshgrid
fig = figure(figsize=(8,6))
ax = fig[:gca](projection="3d")
ax[:view_init](40, 230)
xgrid, ygrid = meshgrid(z_grid, σ_grid)
ax[:plot_surface](xgrid,
ygrid,
w',
rstride=2, cstride=2,
cmap=ColorMap("jet"),
alpha=0.7,
linewidth=0.25)
#ax[:set_zlim](-0.5, 1.0)
ax[:set_zlabel]("V", labelpad=10)
ax[:set_xlabel]("z", labelpad=10, fontsize=14)
ax[:set_ylabel]("σ", labelpad=10, fontsize=12)
plt.show()
In [65]:
m = 10
x = linspace(0, 1, m)
y = linspace(0, 2, m)
z = Array{Float64}(m, m)
for i in 1:m
for j in 1:m
z[i, j] = x[i] - y[j]
end
end
fig = figure(figsize=(8,6))
ax = fig[:gca](projection="3d")
ax[:view_init](40, 230)
xgrid, ygrid = meshgrid(x, y)
ax[:plot_surface](xgrid,
ygrid,
z',
rstride=2, cstride=2,
alpha=0.7,
linewidth=0.25)
#ax[:set_zlim](-0.5, 1.0)
ax[:set_zlabel]("V", labelpad=10)
ax[:set_xlabel]("x", labelpad=10, fontsize=14)
ax[:set_ylabel]("y", labelpad=10, fontsize=12)
plt.show()
In [ ]: