GitHub

@@ -3,8 +3,10 @@ jupytext:

33

text_representation:

44

extension: .md

55

format_name: myst

6+

format_version: 0.13

7+

jupytext_version: 1.14.5

68

kernelspec:

7-

display_name: Python 3

9+

display_name: Python 3 (ipykernel)

810

language: python

911

name: python3

1012

---

@@ -652,7 +654,7 @@ approximations, under different values of $T$, and $g$ and $r$ in Python.

652654

First we plot the true finite stream present-value after computing it

653655

below

654656655-

```{code-cell} python3

657+

```{code-cell} ipython3

656658

# True present value of a finite lease

657659

def finite_lease_pv_true(T, g, r, x_0):

658660

G = (1 + g)

@@ -679,7 +681,13 @@ Now that we have defined our functions, we can plot some outcomes.

679681680682

First we study the quality of our approximations

681683682-

```{code-cell} python3

684+

```{code-cell} ipython3

685+

---

686+

mystnb:

687+

figure:

688+

caption: "Finite lease present value $T$ periods ahead"

689+

name: finite_lease_present_value

690+

---

683691

def plot_function(axes, x_vals, func, args):

684692

axes.plot(x_vals, func(*args), label=func.__name__)

685693

@@ -694,10 +702,9 @@ our_args = (T, g, r, x_0)

694702

funcs = [finite_lease_pv_true,

695703

finite_lease_pv_approx_1,

696704

finite_lease_pv_approx_2]

697-

## the three functions we want to compare

705+

# the three functions we want to compare

698706699707

fig, ax = plt.subplots()

700-

ax.set_title('Finite Lease Present Value $T$ Periods Ahead')

701708

for f in funcs:

702709

plot_function(ax, T, f, our_args)

703710

ax.legend()

@@ -713,12 +720,17 @@ However, holding $g$ and r fixed, our approximations deteriorate as $T$ increase

713720

Next we compare the infinite and finite duration lease present values

714721

over different lease lengths $T$.

715722716-

```{code-cell} python3

723+

```{code-cell} ipython3

724+

---

725+

mystnb:

726+

figure:

727+

caption: "Infinite and finite lease present value $T$ periods ahead"

728+

name: infinite_and_finite_lease_present_value

729+

---

717730

# Convergence of infinite and finite

718731

T_max = 1000

719732

T = np.arange(0, T_max+1)

720733

fig, ax = plt.subplots()

721-

ax.set_title('Infinite and Finite Lease Present Value $T$ Periods Ahead')

722734

f_1 = finite_lease_pv_true(T, g, r, x_0)

723735

f_2 = np.full(T_max+1, infinite_lease(g, r, x_0))

724736

ax.plot(T, f_1, label='T-period lease PV')

@@ -736,11 +748,16 @@ perpetual lease.

736748

Now we consider two different views of what happens as $r$ and

737749

$g$ covary

738750739-

```{code-cell} python3

751+

```{code-cell} ipython3

752+

---

753+

mystnb:

754+

figure:

755+

caption: "Value of lease of length $T$"

756+

name: value_of_lease

757+

---

740758

# First view

741759

# Changing r and g

742760

fig, ax = plt.subplots()

743-

ax.set_title('Value of lease of length $T$')

744761

ax.set_ylabel('Present Value, $p_0$')

745762

ax.set_xlabel('$T$ periods ahead')

746763

T_max = 10

@@ -765,9 +782,15 @@ graph.

765782

If you aren't enamored of 3-d graphs, feel free to skip the next

766783

visualization!

767784768-

```{code-cell} python3

785+

```{code-cell} ipython3

786+

---

787+

mystnb:

788+

figure:

789+

caption: "Three period lease PV with varying $g$ and $r$"

790+

name: three_period_lease_PV

791+

---

769792

# Second view

770-

fig = plt.figure()

793+

fig = plt.figure(figsize = [16, 5])

771794

T = 3

772795

ax = plt.subplot(projection='3d')

773796

r = np.arange(0.01, 0.99, 0.005)

@@ -785,8 +808,7 @@ fig.colorbar(surf, shrink=0.5, aspect=5)

785808

ax.set_xlabel('$r$')

786809

ax.set_ylabel('$g$')

787810

ax.set_zlabel('Present Value, $p_0$')

788-

ax.view_init(20, 10)

789-

ax.set_title('Three Period Lease PV with Varying $g$ and $r$')

811+

ax.view_init(20, 8)

790812

plt.show()

791813

```

792814

@@ -803,7 +825,7 @@ represents our present value formula for an infinite lease.

803825804826

After that, we'll use SymPy to compute derivatives

805827806-

```{code-cell} python3

828+

```{code-cell} ipython3

807829

# Creates algebraic symbols that can be used in an algebraic expression

808830

g, r, x0 = sym.symbols('g, r, x0')

809831

G = (1 + g)

@@ -814,13 +836,13 @@ print('Our formula is:')

814836

p0

815837

```

816838817-

```{code-cell} python3

839+

```{code-cell} ipython3

818840

print('dp0 / dg is:')

819841

dp_dg = sym.diff(p0, g)

820842

dp_dg

821843

```

822844823-

```{code-cell} python3

845+

```{code-cell} ipython3

824846

print('dp0 / dr is:')

825847

dp_dr = sym.diff(p0, r)

826848

dp_dr

@@ -839,7 +861,13 @@ We will now go back to the case of the Keynesian multiplier and plot the

839861

time path of $y_t$, given that consumption is a constant fraction

840862

of national income, and investment is fixed.

841863842-

```{code-cell} python3

864+

```{code-cell} ipython3

865+

---

866+

mystnb:

867+

figure:

868+

caption: "Path of aggregate output tver time"

869+

name: path_of_aggregate_output_over_time

870+

---

843871

# Function that calculates a path of y

844872

def calculate_y(i, b, g, T, y_init):

845873

y = np.zeros(T+1)

@@ -857,7 +885,6 @@ y_init = 0

857885

T = 100

858886859887

fig, ax = plt.subplots()

860-

ax.set_title('Path of Aggregate Output Over Time')

861888

ax.set_xlabel('$t$')

862889

ax.set_ylabel('$y_t$')

863890

ax.plot(np.arange(0, T+1), calculate_y(i_0, b, g_0, T, y_init))

@@ -873,11 +900,16 @@ We now examine what will

873900

happen if we vary the so-called **marginal propensity to consume**,

874901

i.e., the fraction of income that is consumed

875902876-

```{code-cell} python3

903+

```{code-cell} ipython3

904+

---

905+

mystnb:

906+

figure:

907+

caption: "Changing consumption as a fraction of income"

908+

name: changing_consumption_as_fraction_of_income

909+

---

877910

bs = (1/3, 2/3, 5/6, 0.9)

878911879912

fig,ax = plt.subplots()

880-

ax.set_title('Changing Consumption as a Fraction of Income')

881913

ax.set_ylabel('$y_t$')

882914

ax.set_xlabel('$t$')

883915

x = np.arange(0, T+1)

@@ -893,7 +925,13 @@ path of output over time.

893925894926

Now we will compare the effects on output of increases in investment and government spending.

895927896-

```{code-cell} python3

928+

```{code-cell} ipython3

929+

---

930+

mystnb:

931+

figure:

932+

caption: "Different increase on output"

933+

name: different_increase_on_output

934+

---

897935

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(6, 10))

898936

fig.subplots_adjust(hspace=0.3)

899937

Read the original on github.com ↗