Solving Bansal Yaron by Interpolation Methods


In [1]:
include("bansal_yaron_parameters.jl")
include("bansal_yaron_interpolation.jl")


LoadError: UndefVarError: EpsteinZin not defined
while loading /home/john/sync_dir/papers/recursive_utility/code/bansal_yaron_interpolation.jl, in expression starting on line 10

Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:569
 [2] include(::String) at ./sysimg.jl:14
 [3] include_string(::String, ::String) at ./loading.jl:515

In [20]:
using PyPlot
plt = PyPlot


Out[20]:
PyPlot

In [21]:
ez = EpsteinZinBY()
sv = StochasticVolatilityBY()


Out[21]:
StochasticVolatility{Float64}(0.979, 0.044, 0.987, 7.909200000000006e-7, 2.3e-6)

In [22]:
ez.θ


Out[22]:
-26.999999999999996

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]:
-0.015:0.0027272727272727275:0.015

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]:
7067

In [42]:
error


Out[42]:
9.983702038374176e-5

In [40]:
w = w.^(1 / (1 - 1 / ez.ψ))


Out[40]:
12×12 Array{Float64,2}:
  98.5504   98.7422   99.3195  100.18   …  104.286  104.442  104.246  103.689
 111.818   112.038   112.699   113.689     118.508  118.727  118.55   117.966
 126.886   127.137   127.896   129.035     134.608  134.877  134.697  134.057
 144.006   144.294   145.168   146.483     152.902  153.218  153.024  152.308
 163.47    163.801   164.812   166.333     173.696  174.061  173.846  173.04 
 185.62    186.006   187.178   188.928  …  197.338  197.757  197.517  196.604
 210.903   211.34    212.673   214.664     224.231  224.707  224.434  223.396
 239.821   240.305   241.793   244.028     254.839  255.375  255.059  253.874
 272.809   273.351   275.013   277.521     289.683  290.276  289.902  288.541
 310.409   311.021   312.883   315.695     329.355  329.996  329.541  327.969
 353.252   353.943   356.038   359.19   …  374.475  375.151  374.584  372.749
 402.05    402.831   405.188   408.711     425.505  426.164  425.421  423.247

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 [ ]: