Spaces:
Sleeping
Sleeping
import streamlit as st | |
import numpy as np | |
import plotly.graph_objects as go | |
# Title | |
st.title("Financial Modeling App") | |
# Tab setup | |
tabs = st.tabs(["Time Value of Money", "Consistent Cash Flow Investment", "Monte Carlo Simulation"]) | |
# --- Time Value of Money --- | |
with tabs[0]: | |
st.header("Time Value of Money") | |
a = st.number_input("Base Amount (a)", min_value=0.0, value=1000.0) | |
r = st.number_input("Annual Return Rate (r)", min_value=0.0, value=0.05) | |
T = st.number_input("Number of Years (T)", min_value=0, value=10) | |
future_value = a * ((1 + r) ** T) | |
st.write(f"Future Value = {a} * (1 + {r})^{T} = **{future_value:,.2f}**") | |
# --- Consistent Cash Flow Investment --- | |
with tabs[1]: | |
st.header("Consistent Cash Flow Investment") | |
a_cf = st.number_input("Annual Cash Flow (a)", min_value=0.0, value=1000.0) | |
r_cf = st.number_input("Annual Return Rate (r)", min_value=0.0, value=0.05) | |
T_cf = st.number_input("Number of Years (T)", min_value=0, value=10) | |
if r_cf > 0: | |
fv_cf = a_cf * (((1 + r_cf) ** T_cf - 1) / r_cf) | |
else: | |
fv_cf = a_cf * T_cf | |
st.write(f"Future Value of Cash Flows = **{fv_cf:,.2f}**") | |
# --- Monte Carlo Simulation --- | |
with tabs[2]: | |
st.header("Monte Carlo Simulation") | |
mean_return = st.number_input("Mean Annual Return", value=0.07) | |
std_dev = st.number_input("Standard Deviation", value=0.15) | |
years = st.slider("Number of Years", 1, 100, 30) | |
simulations = 50 | |
# Simulate paths | |
np.random.seed(42) | |
results = np.zeros((simulations, years)) | |
for i in range(simulations): | |
returns = np.random.normal(loc=mean_return, scale=std_dev, size=years) | |
results[i] = np.cumprod(1 + returns) | |
# Plot | |
fig = go.Figure() | |
for i in range(simulations): | |
fig.add_trace(go.Scatter(y=results[i], mode='lines', name=f'Sim {i+1}', line=dict(width=1))) | |
fig.update_layout(title="Monte Carlo Simulations of Portfolio Growth", | |
xaxis_title="Years", | |
yaxis_title="Portfolio Value (normalized)", | |
showlegend=False) | |
st.plotly_chart(fig) |