@@ -3,8 +3,10 @@ jupytext:
33 text_representation :
44 extension : .md
55 format_name : myst
6+ format_version : 0.13
7+ jupytext_version : 1.16.1
68kernelspec :
7- display_name : Python 3
9+ display_name : Python 3 (ipykernel)
810 language : python
911 name : python3
1012---
@@ -26,12 +28,10 @@ kernelspec:
2628
2729In addition to what's in Anaconda, this lecture will need the following libraries:
2830
29- ``` {code-cell} ipython
30- ---
31- tags: [hide-output]
32- ---
31+ ``` {code-cell} ipython3
32+ :tags: [hide-output]
33+
3334!pip install --upgrade quantecon
34- !pip install interpolation
3535!conda install -y -c plotly plotly plotly-orca
3636```
3737
@@ -703,15 +703,14 @@ Parameters include:
703703- $\beta$: Discount factor. Default value is 0.96.
704704- bound: Bound for truncated normal distribution. Default value is 3.
705705
706- ``` {code-cell} ipython
706+ ``` {code-cell} ipython3
707707import numpy as np
708708from scipy.stats import truncnorm
709709from scipy.integrate import quad
710710from numba import njit
711- from interpolation import interp
712711```
713712
714- ``` {code-cell} python3
713+ ``` {code-cell} ipython3
715714class BCG_incomplete_markets:
716715
717716 # init method or constructor
@@ -784,7 +783,7 @@ class BCG_incomplete_markets:
784783 rv = truncnorm(ta, tb, loc=𝜇, scale=𝜎)
785784 𝜖_range = np.linspace(ta, tb, 1000000)
786785 pdf_range = rv.pdf(𝜖_range)
787- self.g = njit(lambda 𝜖: interp(𝜖_range, pdf_range, 𝜖 ))
786+ self.g = njit(lambda 𝜖: np. interp(𝜖, 𝜖_range, pdf_range ))
788787
789788
790789 #*************************************************************
@@ -1206,14 +1205,14 @@ Below we show some examples computed with the class `BCG_incomplete markets`.
12061205In the first example, we set up an instance of the BCG incomplete
12071206markets model with default parameter values.
12081207
1209- ``` {code-cell} python3
1210- :tags: [" hide-output" ]
1208+ ``` {code-cell} ipython3
1209+ :tags: [hide-output]
12111210
12121211mdl = BCG_incomplete_markets()
12131212kss,bss,Vss,qss,pss,c10ss,c11ss,c20ss,c21ss,𝜃1ss = mdl.solve_eq(print_crit=False)
12141213```
12151214
1216- ``` {code-cell} python3
1215+ ``` {code-cell} ipython3
12171216print(-kss+qss+pss*bss)
12181217print(Vss)
12191218print(𝜃1ss)
@@ -1229,7 +1228,7 @@ Thus, let’s see if the firm is actually maximizing its firm value given
12291228the equilibrium pricing function $q(k,b)$ for equity and
12301229$p(k,b)$ for bonds.
12311230
1232- ``` {code-cell} python3
1231+ ``` {code-cell} ipython3
12331232kgrid, bgrid, Vgrid, Qgrid, Pgrid = mdl.eq_valuation(c10ss, c11ss, c20ss, c21ss,N=30)
12341233
12351234print('Maximum valuation of the firm value in the (k,B) grid: {:.5f}'.format(Vgrid.max()))
@@ -1246,7 +1245,7 @@ Below we will plot the firm’s value as a function of $k,b$.
12461245We’ll also plot the equilibrium price functions $q(k,b)$ and
12471246$p(k,b)$.
12481247
1249- ``` {code-cell} python3
1248+ ``` {code-cell} ipython3
12501249from IPython.display import Image
12511250import matplotlib.pyplot as plt
12521251from mpl_toolkits import mplot3d
13671366
13681367The function also outputs agent 1’s bond holdings $\xi_1$.
13691368
1370- ``` {code-cell} python3
1369+ ``` {code-cell} ipython3
13711370def off_eq_check(mdl,kss,bss,e=0.1):
13721371 # Big K and big B
13731372 k = kss
@@ -1603,7 +1602,7 @@ structure for the firm.
16031602We first check the case in which $b^{** } = b^* - e$ where
16041603$e = 0.1$:
16051604
1606- ``` {code-cell} python3
1605+ ``` {code-cell} ipython3
16071606#====================== Experiment 1 ======================#
16081607Ve1,ke1,be1,pe1,qe1,c10e1,c11e1,c20e1,c21e1,𝜉1e1 = off_eq_check(mdl,
16091608 kss,
@@ -1655,7 +1654,7 @@ Therefore, $(k^*,b^{*}-e)$ would not be an equilibrium.
16551654
16561655Next, we check for $b^{** } = b^* + e$.
16571656
1658- ``` {code-cell} python3
1657+ ``` {code-cell} ipython3
16591658#====================== Experiment 2 ======================#
16601659Ve2,ke2,be2,pe2,qe2,c10e2,c11e2,c20e2,c21e2,𝜉1e2 = off_eq_check(mdl,
16611660 kss,
@@ -1708,7 +1707,7 @@ want to hold corporate debt.
17081707
17091708For example, $\xi^1 > 0$:
17101709
1711- ``` {code-cell} python3
1710+ ``` {code-cell} ipython3
17121711print('Bond holdings of agent 1: {:.3f}'.format(𝜉1e2))
17131712```
17141713
@@ -1726,7 +1725,7 @@ It is also interesting to look at the equilibrium price functions
17261725$q(k,b)$ and $p(k,b)$ faced by firms in our rational
17271726expectations equilibrium.
17281727
1729- ``` {code-cell} python3
1728+ ``` {code-cell} ipython3
17301729# Equity Valuation
17311730fig = go.Figure(data=[go.Scatter3d(x=[kss],
17321731 y=[bss],
@@ -1756,7 +1755,7 @@ Image(fig.to_image(format="png"))
17561755# code locally
17571756```
17581757
1759- ``` {code-cell} python3
1758+ ``` {code-cell} ipython3
17601759# Bond Valuation
17611760fig = go.Figure(data=[go.Scatter3d(x=[kss],
17621761 y=[bss],
18151814The function ` valuations_by_agent ` is used in calculating these
18161815valuations.
18171816
1818- ``` {code-cell} python3
1819- :tags: [" hide-output" ]
1817+ ``` {code-cell} ipython3
1818+ :tags: [hide-output]
18201819
18211820# Lists for storage
18221821wlist = []
@@ -1864,7 +1863,7 @@ for i in range(10):
18641863 p2list.append(P2)
18651864```
18661865
1867- ``` {code-cell} python3
1866+ ``` {code-cell} ipython3
18681867# Plot
18691868fig, ax = plt.subplots(3,2,figsize=(12,12))
18701869ax[0,0].plot(wlist,klist)
@@ -1909,7 +1908,7 @@ Now let’s see how the two types of agents value bonds and equities,
19091908keeping in mind that the type that values the asset highest determines
19101909the equilibrium price (and thus the pertinent set of Big $C$’s).
19111910
1912- ``` {code-cell} python3
1911+ ``` {code-cell} ipython3
19131912# Comparing the prices
19141913fig, ax = plt.subplots(1,3,figsize=(16,6))
19151914
0 commit comments