Utility Plots in the Bansal Yaron (and BKY) Model


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


WARNING: replacing docs for 'compute_spec_rad :: Tuple{Array{T,2} where T}' in module 'Main'.
WARNING: replacing docs for 'EpsteinZin :: Union{}' in module 'Main'.
WARNING: replacing docs for 'EpsteinZin :: Tuple{Any,Any,Any}' in module 'Main'.
WARNING: replacing docs for 'compute_spec_rad :: Tuple{Array{T,2} where T}' in module 'Main'.
WARNING: replacing docs for 'EpsteinZin :: Union{}' in module 'Main'.
WARNING: replacing docs for 'EpsteinZin :: Tuple{Any,Any,Any}' in module 'Main'.
WARNING: replacing docs for 'StochasticVolatility :: Union{}' in module 'Main'.
WARNING: replacing docs for 'multi_from_single :: Tuple{Any,Any}' in module 'Main'.
WARNING: replacing docs for 'discretize_sv :: Tuple{StochasticVolatility,Integer,Integer}' in module 'Main'.
WARNING: replacing docs for 'EpsteinZinBY :: Tuple{}' in module 'Main'.
WARNING: replacing docs for 'EpsteinZinBKY :: Tuple{}' in module 'Main'.
Out[1]:
compute_fp_bansal_yaron

In [2]:
using PyPlot
plt = PyPlot


Out[2]:
PyPlot

Spectral Radius Plot, Bansal--Yaron Parameters


In [3]:
I=14
J=24
L=20


Out[3]:
20

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


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

In [6]:
σ_vals, z_vals, W = compute_fp_bansal_yaron(ez, sv, I=I, J=J, L=L);


MethodError: no method matching discretize_sv(::StochasticVolatility{Float64}, ::Int64, ::Int64; verbose=true)
Closest candidates are:
  discretize_sv(::StochasticVolatility, ::Integer, ::Integer; fail_with_neg_σ) at /home/john/sync_dir/papers/recursive_utility/code/bansal_yaron_consumption.jl:79 got unsupported keyword argument "verbose"

Stacktrace:
 [1] (::#kw##discretize_sv)(::Array{Any,1}, ::#discretize_sv, ::StochasticVolatility{Float64}, ::Int64, ::Int64) at ./<missing>:0
 [2] #compute_fp_bansal_yaron#16(::Float64, ::Int64, ::Int64, ::Int64, ::Float64, ::Int64, ::Function, ::EpsteinZin{Float64}, ::StochasticVolatility{Float64}) at /home/john/sync_dir/papers/recursive_utility/code/bansal_yaron_discretized.jl:68
 [3] (::#kw##compute_fp_bansal_yaron)(::Array{Any,1}, ::#compute_fp_bansal_yaron, ::EpsteinZin{Float64}, ::StochasticVolatility{Float64}) at ./<missing>:0

In [7]:
size(W)


Out[7]:
(14, 20)

In [8]:
σ_vals


Out[8]:
14-element Array{Float64,1}:
 0.00304014
 0.00414494
 0.00501185
 0.0057495 
 0.00640272
 0.0069952 
 0.00754128
 0.00805041
 0.00852919
 0.00898249
 0.00941399
 0.00982656
 0.0102225 
 0.0106037 

In [11]:
using QuantEcon: meshgrid

fig = figure(figsize=(8,6))
ax = fig[:gca](projection="3d")
ax[:view_init](40, 230)

xgrid, ygrid = meshgrid(z_vals, σ_vals)

ctr1 = ax[:plot_surface](xgrid, 
                         ygrid, 
                         W,
                         cmap=ColorMap("jet"),
                         alpha=0.7,
                         rstride=1, cstride=1,
                         linewidth=0.5)

#plt.clabel(ctr1, inline=1, fontsize=13)
#plt.colorbar(ctr1, ax=ax)

ax[:set_zlabel]("V", labelpad=10)
ax[:set_xlabel]("z", labelpad=10, fontsize=14)
ax[:set_ylabel]("σ", labelpad=10, fontsize=12)

#plt.savefig("foo.pdf")
plt.show()



In [10]:
fig, ax = plt.subplots(figsize=(10, 5.7))

cs1 = ax[:contourf](σ_vals, 
                    z_vals, 
                    W',
                    alpha=0.6)
                    #levels=lvs,


ctr1 = ax[:contour](σ_vals, 
                    z_vals, 
                    W')

plt.clabel(ctr1, inline=1, fontsize=13)
plt.colorbar(cs1, ax=ax)

ax[:set_title]("Utility")
ax[:set_xlabel]("σ", fontsize=16)
ax[:set_ylabel]("z", fontsize=16)

#plt.savefig("foo.pdf")
plt.show()


Utility Plot with BKY Parameters


In [10]:
ez = EpsteinZinBKY()
sv = StochasticVolatilityBKY()


Out[10]:
StochasticVolatility{Float64}(0.975, 0.038, 0.999, 5.1840000000000046e-8, 2.8e-6)

In [11]:
σ_vals, z_vals, W = compute_fp_by(ez, sv, I=I, J=J, L=L);


Iteration converged after 6179 iterations

In [12]:
fig, ax = plt.subplots(figsize=(10, 5.7))

cs1 = ax[:contourf](σ_vals, 
                    z_vals, 
                    W',
                    alpha=0.6)
                    #levels=lvs,


ctr1 = ax[:contour](σ_vals, 
                    z_vals, 
                    W')

plt.clabel(ctr1, inline=1, fontsize=13)
plt.colorbar(cs1, ax=ax)

ax[:set_title]("Utility")
ax[:set_xlabel]("σ", fontsize=16)
ax[:set_ylabel]("z", fontsize=16)

#plt.savefig("foo.pdf")
plt.show()



In [13]:
fig = figure(figsize=(8,6))
ax = fig[:gca](projection="3d")
ax[:view_init](40, 230)

xgrid, ygrid = meshgrid(σ_vals, z_vals)

ctr1 = ax[:plot_surface](xgrid, 
                         ygrid, 
                         cmap=ColorMap("jet"),
                         alpha=0.7,
                         rstride=1, cstride=1,
                         linewidth=0.5,
                         W')

#plt.clabel(ctr1, inline=1, fontsize=13)
#plt.colorbar(ctr1, ax=ax)

ax[:set_zlabel]("V", labelpad=10)
ax[:set_xlabel]("σ", labelpad=10, fontsize=14)
ax[:set_ylabel]("z", labelpad=10, fontsize=12)

#plt.savefig("foo.pdf")
plt.show()



In [ ]: