File size: 2,126 Bytes
5987a94
ce81efb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)