@@ -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
68kernelspec :
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.
652654First we plot the true finite stream present-value after computing it
653655below
654656
655- ``` {code-cell} python3
657+ ``` {code-cell} ipython3
656658# True present value of a finite lease
657659def 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.
679681
680682First we study the quality of our approximations
681683
682- ``` {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+ ---
683691def 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)
694702funcs = [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
698706
699707fig, ax = plt.subplots()
700- ax.set_title('Finite Lease Present Value $T$ Periods Ahead')
701708for f in funcs:
702709 plot_function(ax, T, f, our_args)
703710ax.legend()
@@ -713,12 +720,17 @@ However, holding $g$ and r fixed, our approximations deteriorate as $T$ increase
713720Next we compare the infinite and finite duration lease present values
714721over different lease lengths $T$.
715722
716- ``` {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
718731T_max = 1000
719732T = np.arange(0, T_max+1)
720733fig, ax = plt.subplots()
721- ax.set_title('Infinite and Finite Lease Present Value $T$ Periods Ahead')
722734f_1 = finite_lease_pv_true(T, g, r, x_0)
723735f_2 = np.full(T_max+1, infinite_lease(g, r, x_0))
724736ax.plot(T, f_1, label='T-period lease PV')
@@ -736,11 +748,16 @@ perpetual lease.
736748Now we consider two different views of what happens as $r$ and
737749$g$ covary
738750
739- ``` {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
742760fig, ax = plt.subplots()
743- ax.set_title('Value of lease of length $T$')
744761ax.set_ylabel('Present Value, $p_0$')
745762ax.set_xlabel('$T$ periods ahead')
746763T_max = 10
@@ -765,9 +782,15 @@ graph.
765782If you aren't enamored of 3-d graphs, feel free to skip the next
766783visualization!
767784
768- ``` {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] )
771794T = 3
772795ax = plt.subplot(projection='3d')
773796r = np.arange(0.01, 0.99, 0.005)
@@ -785,8 +808,7 @@ fig.colorbar(surf, shrink=0.5, aspect=5)
785808ax.set_xlabel('$r$')
786809ax.set_ylabel('$g$')
787810ax.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)
790812plt.show()
791813```
792814
@@ -803,7 +825,7 @@ represents our present value formula for an infinite lease.
803825
804826After that, we'll use SymPy to compute derivatives
805827
806- ``` {code-cell} python3
828+ ``` {code-cell} ipython3
807829# Creates algebraic symbols that can be used in an algebraic expression
808830g, r, x0 = sym.symbols('g, r, x0')
809831G = (1 + g)
@@ -814,13 +836,13 @@ print('Our formula is:')
814836p0
815837```
816838
817- ``` {code-cell} python3
839+ ``` {code-cell} ipython3
818840print('dp0 / dg is:')
819841dp_dg = sym.diff(p0, g)
820842dp_dg
821843```
822844
823- ``` {code-cell} python3
845+ ``` {code-cell} ipython3
824846print('dp0 / dr is:')
825847dp_dr = sym.diff(p0, r)
826848dp_dr
@@ -839,7 +861,13 @@ We will now go back to the case of the Keynesian multiplier and plot the
839861time path of $y_t$, given that consumption is a constant fraction
840862of national income, and investment is fixed.
841863
842- ``` {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
844872def calculate_y(i, b, g, T, y_init):
845873 y = np.zeros(T+1)
@@ -857,7 +885,6 @@ y_init = 0
857885T = 100
858886
859887fig, ax = plt.subplots()
860- ax.set_title('Path of Aggregate Output Over Time')
861888ax.set_xlabel('$t$')
862889ax.set_ylabel('$y_t$')
863890ax.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
873900happen if we vary the so-called ** marginal propensity to consume** ,
874901i.e., the fraction of income that is consumed
875902
876- ``` {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+ ---
877910bs = (1/3, 2/3, 5/6, 0.9)
878911
879912fig,ax = plt.subplots()
880- ax.set_title('Changing Consumption as a Fraction of Income')
881913ax.set_ylabel('$y_t$')
882914ax.set_xlabel('$t$')
883915x = np.arange(0, T+1)
@@ -893,7 +925,13 @@ path of output over time.
893925
894926Now we will compare the effects on output of increases in investment and government spending.
895927
896- ``` {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+ ---
897935fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(6, 10))
898936fig.subplots_adjust(hspace=0.3)
899937
0 commit comments