<jupyter_start><jupyter_text>Interest Rate---Suppose $W(t)$ is the wealth at time $t$ ($t\geqq 0$) and $r$ is an interest rate.+ **Simple interest rate**$$ W(t) = (1+rt)W(0).$$+ **One-year compound interest rate**$$ W(t) = (1+r)^t W(0).$$+ **$\frac1{M}$-year compound interest rate**$$ W(t) = \left(1+\frac{r}{M}\right)^{Mt} W(0).$$+ **Continuous compoud interest rate**$$ W(t) = e^{rt}W(0).$$  Python Code: Simple Rate vs. Compounding Rate---The following command enables plotting within cells.<jupyter_code>%matplotlib inline<jupyter_output><empty_output><jupyter_text>`import` literally imports a package named NumPy in Python. NumPy enable us to use vectors and matrices in Python. It also comes with numerous functions for mathematical computation. `as np` means that we use `np` as a abbreviation of `numpy`.<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>This line imports PyPlot, a collection of functions for 2D/3D graphics.<jupyter_code>import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>`r` is the interest rate. `Maturity` is the number of years until the end of the investment period.<jupyter_code>r = 0.2
Maturity = 10<jupyter_output><empty_output><jupyter_text>`Simple_Rate` contains the amount of wealth at each year when we invest funds with simple interest rate.<jupyter_code>Simple_Rate = 1.0 + r * np.linspace(0, Maturity, Maturity + 1)<jupyter_output><empty_output><jupyter_text>`linspace(0, Maturity, Maturity + 1)` creates a vector of grid points. The first number in `linspace(0, Maturity, Maturity + 1)` is the starting point, the second is the end point, and the third is the number of grid points. `print` show the content of the object.<jupyter_code>print(np.linspace(0, Maturity, Maturity + 1))
print(Simple_Rate)<jupyter_output>[1.  1.2 1.4 1.6 1.8 2.  2.2 2.4 2.6 2.8 3. ]<jupyter_text>`Compound_1year` contains the amount of wealth at each year when we invest funds with one-year compound interest rate.<jupyter_code>Compound_1year = np.hstack((1.0, np.cumprod(np.tile(1.0 + r, Maturity))))<jupyter_output><empty_output><jupyter_text>`tile` creates a larger vector/matrix by tiling the same vector/matrix.<jupyter_code>print(np.tile(1.0 + r, Maturity))<jupyter_output>[1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2]<jupyter_text>`cumprod` computes *cumulative products*, i.e.,<jupyter_code>print(np.cumprod(np.tile(1.0 + r, Maturity)))<jupyter_output>[1.2        1.44       1.728      2.0736     2.48832    2.985984
 3.5831808  4.29981696 5.15978035 6.19173642]<jupyter_text>`hstack` creates a larger vector/matrix by putting vectors/matrices together horizontally.<jupyter_code>print(Compound_1year)<jupyter_output>[1.         1.2        1.44       1.728      2.0736     2.48832
 2.985984   3.5831808  4.29981696 5.15978035 6.19173642]<jupyter_text>`Comound_6month` contains the amount of wealth at each year when we invest funds with six-month compound interest rate.<jupyter_code>Compound_6month = np.hstack((1.0, np.cumprod(np.tile((1.0 + r/2.0)**2, Maturity))))<jupyter_output><empty_output><jupyter_text>`Continuous_Rate` contains the amount of wealth at each year when we invest funds with continuous compound interest rate.<jupyter_code>Continuous_Rate = np.exp(r*np.linspace(0, Maturity, Maturity + 1))<jupyter_output><empty_output><jupyter_text>The following cell creates a figure.<jupyter_code>fig1 = plt.figure(num=1, facecolor='w')
plt.plot(Simple_Rate, 'b-')
plt.plot(Compound_1year, 'r--')
plt.plot(Compound_6month, 'g-.')
plt.plot(Continuous_Rate, 'm:')
plt.legend(['simple', '1-year compound', '6-month compound', 'continuous'],
           loc='upper left', frameon=False)
plt.xlabel('t')
plt.ylabel('W(t)/W(0)')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13713980789754535, 'fraction_numerical': 0.05816435432230523, 'mean_word_length': 5.452667814113597, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '582885', 'license': 'MIT', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1357, 'n_words': 355, 'path': 'notebook/ges_interest.ipynb', 'repo_name': 'nakatsuma/GES-PEARL', 'size': '3748'}