Spaces:
Runtime error
Runtime error
File size: 1,835 Bytes
66ce26b 0c25188 4e82292 66ce26b cb09453 ec48dca 3fb1c64 0c25188 7b87879 3fb1c64 0c25188 27b0db3 0c25188 9c6a1e8 0c25188 ec48dca 9c6a1e8 ec48dca 0c25188 9c6a1e8 0c25188 c20d7b1 5c369cd 8740d6f 885e0f7 8740d6f 885e0f7 acc0e2a 885e0f7 69d70df 8740d6f 885e0f7 8740d6f 885e0f7 c20d7b1 4ca7b64 ad74d3b b3d6778 5c369cd 3fb1c64 f188b57 4e82292 f188b57 4e82292 |
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 |
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.write("Table with variable rates")
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)
|