Spaces:
Sleeping
Sleeping
File size: 1,796 Bytes
25f8624 748fc1b 25f8624 748fc1b b2166b2 950d72f 25f8624 748fc1b b2166b2 748fc1b 530e736 748fc1b 25f8624 748fc1b 25f8624 748fc1b 25f8624 748fc1b 530e736 748fc1b 530e736 748fc1b df9501e 748fc1b effc78f 748fc1b b876a81 effc78f b876a81 effc78f 6810c87 25f8624 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
st.title("Investment app 🦥")
A = st.number_input(
"Insert the initial investment (in $): "
)
r = st.number_input(
"Insert the interest rate (nominal in %): "
)
T = st.number_input(
"Insert the number of months of your investment: ",
step=1
)
# Numpy array with the months
t = np.arange(T + 1)
# Numpy array for the interest rate
r_list = np.array([r] * len(t))
# Numpy array with the returns for each month in t
y = A * (1 + (r_list / (12*100)))**t
# Numpy array with the continuously compunded returns
y_c = A * np.exp(r_list * t / (12*100))
# Create the investment dictionary
inv_dict = {"Month": t,
"Rate": r_list,
"Returns": y,
"Continuous returns": y_c}
# Create the investment dataframe
inv_df = pd.DataFrame(inv_dict)
inv_df.columns = inv_dict.keys()
st.write(f"Table with returns at an interest rate of {r}")
new_df = st.data_editor(inv_df)
new_y = [A]
new_y_c = [A]
for i in range(1, len(t)):
r_temp = new_df["Rate"].values[i]
# New numpy array with the returns for each month in t
val = new_y[i-1] * (1 + r_temp / (12*100))
new_y.append(val)
# New numpy array with the continuously compunded returns
val_c = new_y_c[i-1] * np.exp(r_temp / (12*100))
new_y_c.append(val_c)
new_df["Returns"] = new_y
new_df["Continuous returns"] = new_y_c
new_df["Actual returns"] = 100 * (new_df["Continuous returns"] - new_df["Continuous returns"].shift(1)) / new_df["Continuous returns"].shift(1)
st.dataframe(new_df)
fig, ax = plt.subplots()
ax.set_title("Investment returns plot")
ax.set_xlabel("Months")
ax.set_ylabel("Actual returns")
ax.plot(new_df["Month"], new_df["Actual returns"])
st.pyplot(fig)
|