quant-econ Solutions: Default Risk and Income Fluctuations


In [3]:
using QuantEcon, QuantEcon.Models
using Gadfly, Compose, ColorTypes, DataFrames

Compute the value function, policy and equilibrium prices


In [4]:
ae = ArellanoEconomy(β=.953,     # time discount rate
                     γ=2.,       # risk aversion
                     r=0.017,    # international interest rate
                     ρ=.945,     # persistence in output 
                     η=0.025,    # st dev of output shock
                     θ=0.282,    # prob of regaining access 
                     ny=21,      # number of points in y grid
                     nB=251)     # number of points in B grid

# now solve the model on the grid. 
vfi!(ae)


Finished iteration 25 with dist of 0.3424484168091517
Finished iteration 50 with dist of 0.0982039407428843
Finished iteration 75 with dist of 0.029158662291511206
Finished iteration 100 with dist of 0.008729266837647742
Finished iteration 125 with dist of 0.002618400938121823
Finished iteration 150 with dist of 0.0007857709211798181
Finished iteration 175 with dist of 0.0002358324600919559
Finished iteration 200 with dist of 7.078195654486308e-5
Finished iteration 225 with dist of 2.1244388765495614e-5
Finished iteration 250 with dist of 6.376267929653068e-6
Finished iteration 275 with dist of 1.9137668516577833e-6
Finished iteration 300 with dist of 5.743961750681592e-7
Finished iteration 325 with dist of 1.7239873884022927e-7
Finished iteration 350 with dist of 5.174360495630026e-8
Finished iteration 375 with dist of 1.5530293495658043e-8

Compute the bond price schedule as seen in figure 3 of Arellano (2008)


In [6]:
# Create "Y High" and "Y Low" values as 5% devs from mean
high, low = mean(ae.ygrid)*1.05, mean(ae.ygrid)*.95
iy_high, iy_low = map(x->searchsortedfirst(ae.ygrid, x), (high, low))

# Extract a suitable plot grid
x = Float64[]
q_low = Float64[]
q_high = Float64[]
for i=1:ae.nB
    b = ae.Bgrid[i]
    if -0.35 <= b <= 0  # To match fig 3 of Arellano
        push!(x, b)
        push!(q_low, ae.q[i, iy_low])
        push!(q_high, ae.q[i, iy_high])
    end
end

# generate plot
plot(x=repeat(x, outer=[2]), y=[q_low; q_high], 
     color=repeat([:Low, :High], inner=[length(x)]),
     Guide.title("Bond price schedule q(y, B')"),
     Guide.xlabel("B'"), Guide.ylabel("q"),
     Guide.colorkey("y"), Geom.line)


Out[6]:
B' -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 -1.0 -0.5 0.0 0.5 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 Low High y -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 -1 0 1 2 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 q Bond price schedule q(y, B')

Draw a plot of the value functions


In [7]:
plot(x=repeat(ae.Bgrid, outer=[2]), 
     y=vec(ae.vf[:, [iy_low, iy_high]]),
     color=repeat([:Low, :High], inner=[length(ae.Bgrid)]),
     Guide.title("Value functions"),
     Guide.xlabel("B"), Guide.ylabel("V(y,B)"),
     Guide.colorkey("y"), Geom.line)


Out[7]:
B -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 -1.25 -1.20 -1.15 -1.10 -1.05 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 -2 -1 0 1 2 -1.25 -1.20 -1.15 -1.10 -1.05 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 Low High y -24.5 -24.0 -23.5 -23.0 -22.5 -22.0 -21.5 -21.0 -20.5 -20.0 -19.5 -19.0 -18.5 -18.0 -17.5 -24.0 -23.9 -23.8 -23.7 -23.6 -23.5 -23.4 -23.3 -23.2 -23.1 -23.0 -22.9 -22.8 -22.7 -22.6 -22.5 -22.4 -22.3 -22.2 -22.1 -22.0 -21.9 -21.8 -21.7 -21.6 -21.5 -21.4 -21.3 -21.2 -21.1 -21.0 -20.9 -20.8 -20.7 -20.6 -20.5 -20.4 -20.3 -20.2 -20.1 -20.0 -19.9 -19.8 -19.7 -19.6 -19.5 -19.4 -19.3 -19.2 -19.1 -19.0 -18.9 -18.8 -18.7 -18.6 -18.5 -18.4 -18.3 -18.2 -18.1 -18.0 -24 -22 -20 -18 -24.0 -23.8 -23.6 -23.4 -23.2 -23.0 -22.8 -22.6 -22.4 -22.2 -22.0 -21.8 -21.6 -21.4 -21.2 -21.0 -20.8 -20.6 -20.4 -20.2 -20.0 -19.8 -19.6 -19.4 -19.2 -19.0 -18.8 -18.6 -18.4 -18.2 -18.0 V(y,B) Value functions

Draw a heat map for default probability


In [8]:
plot(x_min=repeat(ae.Bgrid[1:end-1], inner=[ae.ny-1]),
     x_max=repeat(ae.Bgrid[2:end], inner=[ae.ny-1]),
     y_min=repeat(ae.ygrid[1:end-1], outer=[ae.nB-1]),
     y_max=repeat(ae.ygrid[2:end], outer=[ae.nB-1]),
     color=clamp(vec(ae.defprob[1:end-1, 1:end-1]'), 0, 1), 
     Geom.rectbin,
     Guide.xlabel("B'"), Guide.ylabel("y"), 
     Guide.title("Probability of default"), Geom.rectbin,
     Scale.y_continuous(minvalue=0.8, maxvalue=1.2),
     Scale.x_continuous(minvalue=minimum(ae.Bgrid), maxvalue=0.0),
     Scale.color_continuous(minvalue=0, maxvalue=1))


Out[8]:
B' -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 -0.82 -0.80 -0.78 -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54 -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 -1.0 -0.5 0.0 0.5 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 1.0 0.0 Color