Solutions for http://quant-econ.net/markov_asset.html
In [1]:
%matplotlib inline
In [2]:
from __future__ import division # Omit for Python 3.x
import numpy as np
import matplotlib.pyplot as plt
from quantecon import AssetPrices
In [3]:
"""
Authors: David Evans, John Stachurski and Thomas J. Sargent
"""
# == Define primitives == #
n = 5
P = 0.0125 * np.ones((n, n))
P += np.diag(0.95 - 0.0125 * np.ones(5))
s = np.array([1.05, 1.025, 1.0, 0.975, 0.95])
gamma = 2.0
beta = 0.94
zeta = 1.0
ap = AssetPrices(beta, P, s, gamma)
v = ap.tree_price()
print "Lucas Tree Prices: ", v
v_consol = ap.consol_price(zeta)
print "Consol Bond Prices: ", v_consol
P_tilde = P * s**(1-gamma)
temp = beta * P_tilde.dot(v) - beta * P_tilde.dot(np.ones(n))
print "Should be 0: ", v - temp
p_s = 150.0
w_bar, w_bars = ap.call_option(zeta, p_s, T = [10,20,30])
In [4]:
from quantecon import lucas_tree, compute_lt_price
fig, ax = plt.subplots(figsize=(10,7))
ax.set_xlabel(r'$y$', fontsize=16)
ax.set_ylabel(r'price', fontsize=16)
for beta in (.95, 0.98):
tree = lucas_tree(gamma=2, beta=beta, alpha=0.90, sigma=0.1)
grid, price_vals = compute_lt_price(tree)
label = r'$\beta = {}$'.format(beta)
ax.plot(grid, price_vals, lw=2, alpha=0.7, label=label)
ax.legend(loc='upper left')
ax.set_xlim(min(grid), max(grid))
Out[4]:
In [ ]: