@@ -3,8 +3,10 @@ jupytext:
3
3
text_representation :
4
4
extension : .md
5
5
format_name : myst
6
+ format_version : 0.13
7
+ jupytext_version : 1.16.1
6
8
kernelspec :
7
- display_name : Python 3
9
+ display_name : Python 3 (ipykernel)
8
10
language : python
9
11
name : python3
10
12
---
@@ -26,12 +28,10 @@ kernelspec:
26
28
27
29
In addition to what's in Anaconda, this lecture will need the following libraries:
28
30
29
- ``` {code-cell} ipython
30
- ---
31
- tags: [hide-output]
32
- ---
31
+ ``` {code-cell} ipython3
32
+ :tags: [hide-output]
33
+
33
34
!pip install --upgrade quantecon
34
- !pip install interpolation
35
35
!conda install -y -c plotly plotly plotly-orca
36
36
```
37
37
@@ -703,15 +703,14 @@ Parameters include:
703
703
- $\beta$: Discount factor. Default value is 0.96.
704
704
- bound: Bound for truncated normal distribution. Default value is 3.
705
705
706
- ``` {code-cell} ipython
706
+ ``` {code-cell} ipython3
707
707
import numpy as np
708
708
from scipy.stats import truncnorm
709
709
from scipy.integrate import quad
710
710
from numba import njit
711
- from interpolation import interp
712
711
```
713
712
714
- ``` {code-cell} python3
713
+ ``` {code-cell} ipython3
715
714
class BCG_incomplete_markets:
716
715
717
716
# init method or constructor
@@ -784,7 +783,7 @@ class BCG_incomplete_markets:
784
783
rv = truncnorm(ta, tb, loc=𝜇, scale=𝜎)
785
784
𝜖_range = np.linspace(ta, tb, 1000000)
786
785
pdf_range = rv.pdf(𝜖_range)
787
- self.g = njit(lambda 𝜖: interp(𝜖_range, pdf_range, 𝜖 ))
786
+ self.g = njit(lambda 𝜖: np. interp(𝜖, 𝜖_range, pdf_range ))
788
787
789
788
790
789
#*************************************************************
@@ -1206,14 +1205,14 @@ Below we show some examples computed with the class `BCG_incomplete markets`.
1206
1205
In the first example, we set up an instance of the BCG incomplete
1207
1206
markets model with default parameter values.
1208
1207
1209
- ``` {code-cell} python3
1210
- :tags: [" hide-output" ]
1208
+ ``` {code-cell} ipython3
1209
+ :tags: [hide-output]
1211
1210
1212
1211
mdl = BCG_incomplete_markets()
1213
1212
kss,bss,Vss,qss,pss,c10ss,c11ss,c20ss,c21ss,𝜃1ss = mdl.solve_eq(print_crit=False)
1214
1213
```
1215
1214
1216
- ``` {code-cell} python3
1215
+ ``` {code-cell} ipython3
1217
1216
print(-kss+qss+pss*bss)
1218
1217
print(Vss)
1219
1218
print(𝜃1ss)
@@ -1229,7 +1228,7 @@ Thus, let’s see if the firm is actually maximizing its firm value given
1229
1228
the equilibrium pricing function $q(k,b)$ for equity and
1230
1229
$p(k,b)$ for bonds.
1231
1230
1232
- ``` {code-cell} python3
1231
+ ``` {code-cell} ipython3
1233
1232
kgrid, bgrid, Vgrid, Qgrid, Pgrid = mdl.eq_valuation(c10ss, c11ss, c20ss, c21ss,N=30)
1234
1233
1235
1234
print('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$.
1246
1245
We’ll also plot the equilibrium price functions $q(k,b)$ and
1247
1246
$p(k,b)$.
1248
1247
1249
- ``` {code-cell} python3
1248
+ ``` {code-cell} ipython3
1250
1249
from IPython.display import Image
1251
1250
import matplotlib.pyplot as plt
1252
1251
from mpl_toolkits import mplot3d
1367
1366
1368
1367
The function also outputs agent 1’s bond holdings $\xi_1$.
1369
1368
1370
- ``` {code-cell} python3
1369
+ ``` {code-cell} ipython3
1371
1370
def off_eq_check(mdl,kss,bss,e=0.1):
1372
1371
# Big K and big B
1373
1372
k = kss
@@ -1603,7 +1602,7 @@ structure for the firm.
1603
1602
We first check the case in which $b^{** } = b^* - e$ where
1604
1603
$e = 0.1$:
1605
1604
1606
- ``` {code-cell} python3
1605
+ ``` {code-cell} ipython3
1607
1606
#====================== Experiment 1 ======================#
1608
1607
Ve1,ke1,be1,pe1,qe1,c10e1,c11e1,c20e1,c21e1,𝜉1e1 = off_eq_check(mdl,
1609
1608
kss,
@@ -1655,7 +1654,7 @@ Therefore, $(k^*,b^{*}-e)$ would not be an equilibrium.
1655
1654
1656
1655
Next, we check for $b^{** } = b^* + e$.
1657
1656
1658
- ``` {code-cell} python3
1657
+ ``` {code-cell} ipython3
1659
1658
#====================== Experiment 2 ======================#
1660
1659
Ve2,ke2,be2,pe2,qe2,c10e2,c11e2,c20e2,c21e2,𝜉1e2 = off_eq_check(mdl,
1661
1660
kss,
@@ -1708,7 +1707,7 @@ want to hold corporate debt.
1708
1707
1709
1708
For example, $\xi^1 > 0$:
1710
1709
1711
- ``` {code-cell} python3
1710
+ ``` {code-cell} ipython3
1712
1711
print('Bond holdings of agent 1: {:.3f}'.format(𝜉1e2))
1713
1712
```
1714
1713
@@ -1726,7 +1725,7 @@ It is also interesting to look at the equilibrium price functions
1726
1725
$q(k,b)$ and $p(k,b)$ faced by firms in our rational
1727
1726
expectations equilibrium.
1728
1727
1729
- ``` {code-cell} python3
1728
+ ``` {code-cell} ipython3
1730
1729
# Equity Valuation
1731
1730
fig = go.Figure(data=[go.Scatter3d(x=[kss],
1732
1731
y=[bss],
@@ -1756,7 +1755,7 @@ Image(fig.to_image(format="png"))
1756
1755
# code locally
1757
1756
```
1758
1757
1759
- ``` {code-cell} python3
1758
+ ``` {code-cell} ipython3
1760
1759
# Bond Valuation
1761
1760
fig = go.Figure(data=[go.Scatter3d(x=[kss],
1762
1761
y=[bss],
1815
1814
The function ` valuations_by_agent ` is used in calculating these
1816
1815
valuations.
1817
1816
1818
- ``` {code-cell} python3
1819
- :tags: [" hide-output" ]
1817
+ ``` {code-cell} ipython3
1818
+ :tags: [hide-output]
1820
1819
1821
1820
# Lists for storage
1822
1821
wlist = []
@@ -1864,7 +1863,7 @@ for i in range(10):
1864
1863
p2list.append(P2)
1865
1864
```
1866
1865
1867
- ``` {code-cell} python3
1866
+ ``` {code-cell} ipython3
1868
1867
# Plot
1869
1868
fig, ax = plt.subplots(3,2,figsize=(12,12))
1870
1869
ax[0,0].plot(wlist,klist)
@@ -1909,7 +1908,7 @@ Now let’s see how the two types of agents value bonds and equities,
1909
1908
keeping in mind that the type that values the asset highest determines
1910
1909
the equilibrium price (and thus the pertinent set of Big $C$’s).
1911
1910
1912
- ``` {code-cell} python3
1911
+ ``` {code-cell} ipython3
1913
1912
# Comparing the prices
1914
1913
fig, ax = plt.subplots(1,3,figsize=(16,6))
1915
1914
0 commit comments