Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
QuantEcon/test-markov_asset
Browse files Browse the repository at this point in the history
Test "Asset Pricing I: Finite State Models"
  • Loading branch information
Nosferican committed Sep 24, 2018
2 parents 4a14960 + 5c946bb commit 63274ef
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion rst_files/markov_asset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,15 @@ The next figure shows a simulation, where

* :math:`g_t = \exp(X_t)`, so that :math:`\ln g_t = X_t` is the growth rate

.. code-block:: julia
:class: test
using Test
.. code-block:: julia
using QuantEcon, Plots, LaTeXStrings
using QuantEcon, Plots, LaTeXStrings, Random
Random.seed!(42) # For reproducible results.
n = 25
mc = tauchen(n, 0.96, 0.25)
Expand All @@ -338,6 +342,15 @@ The next figure shows a simulation, where
labels = [L"$X_t$" L"$g_t$" L"$d_t$" L"$log (d_t)$"]
plot(series, layout = 4, labels = labels)
.. code-block:: julia
:class: test
@testset begin
@test x_series[4] ≈ -0.669642857142857
@test g_series[5] ≈ 0.4094841251523643
@test d_series[9] ≈ 0.03514706070454392 # Near the inflection point.
@test log.(d_series)[72] ≈ -29.24107142857142 # Something near the end.
end
Pricing
^^^^^^^^^^^^
Expand Down Expand Up @@ -436,6 +449,13 @@ Here's the code, including a test of the spectral radius condition
alpha = 0.7,
label = L"$v$")
.. code-block:: julia
:class: test
@testset begin
@test v[5] ≈ 4.526909446326235
@test K[8] ≈ 8.887213530262768e-10
end
Why does the price-dividend ratio increase with the state?

Expand Down Expand Up @@ -653,6 +673,16 @@ with a positively correlated Markov process and :math:`g(x) = \exp(x)`
ylabel = "price-dividend ratio",
xlabel = "state")
.. code-block:: julia
:class: test
@testset begin
@test lines[2][4] ≈ 33.36574362637905
@test lines[3][12] ≈ 28.52560591264372
@test lines[4][18] ≈ 22.38597470787489
@test lines[5][24] ≈ 15.81947255704859
end
Notice that :math:`v` is decreasing in each case

Expand Down Expand Up @@ -881,6 +911,13 @@ Here's a plot of :math:`w` compared to the consol price when :math:`P_S = 40`
plot(x, p, color = "blue", lw = 2, xlabel = "state", label = "consol price")
plot!(x, w, color = "green", lw = 2, label = "value of call option")
.. code-block:: julia
:class: test
@testset begin
@test p[17] ≈ 9.302197030956606
@test w[20] ≈ 0.46101660813737866
end
In large states the value of the option is close to zero

Expand Down Expand Up @@ -1068,6 +1105,13 @@ Next we'll create an instance of `AssetPriceModel` to feed into the functions.
w = call_option(ap, ζ, p_s)
.. code-block:: julia
:class: test
@testset begin
@test w[1] ≈ 603.8710047641985
@test v_consol[3] ≈ 148.67554548466475
end
Exercise 3
----------
Expand Down Expand Up @@ -1112,6 +1156,13 @@ Here's a suitable function:
end
plot(lines, labels = reshape(labels, 1, length(labels)))
.. code-block:: julia
:class: test
@testset begin
@test lines[1][4] ≈ 29.859285398252347
@test lines[2][2] ≈ 147.00074548801277
end
Not surprisingly, the option has greater value with larger :math:`k`.
This is because the owner has a longer time horizon over which he or she
Expand Down

0 comments on commit 63274ef

Please sign in to comment.