eagle0504 commited on
Commit
ce81efb
·
verified ·
1 Parent(s): bb52d15

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +58 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,59 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import numpy as np
3
+ import plotly.graph_objects as go
4
+
5
+ # Title
6
+ st.title("Financial Modeling App")
7
+
8
+ # Tab setup
9
+ tabs = st.tabs(["Time Value of Money", "Consistent Cash Flow Investment", "Monte Carlo Simulation"])
10
+
11
+ # --- Time Value of Money ---
12
+ with tabs[0]:
13
+ st.header("Time Value of Money")
14
+ a = st.number_input("Base Amount (a)", min_value=0.0, value=1000.0)
15
+ r = st.number_input("Annual Return Rate (r)", min_value=0.0, value=0.05)
16
+ T = st.number_input("Number of Years (T)", min_value=0, value=10)
17
+
18
+ future_value = a * ((1 + r) ** T)
19
+ st.write(f"Future Value = {a} * (1 + {r})^{T} = **{future_value:,.2f}**")
20
+
21
+ # --- Consistent Cash Flow Investment ---
22
+ with tabs[1]:
23
+ st.header("Consistent Cash Flow Investment")
24
+ a_cf = st.number_input("Annual Cash Flow (a)", min_value=0.0, value=1000.0)
25
+ r_cf = st.number_input("Annual Return Rate (r)", min_value=0.0, value=0.05)
26
+ T_cf = st.number_input("Number of Years (T)", min_value=0, value=10)
27
+
28
+ if r_cf > 0:
29
+ fv_cf = a_cf * (((1 + r_cf) ** T_cf - 1) / r_cf)
30
+ else:
31
+ fv_cf = a_cf * T_cf
32
+
33
+ st.write(f"Future Value of Cash Flows = **{fv_cf:,.2f}**")
34
+
35
+ # --- Monte Carlo Simulation ---
36
+ with tabs[2]:
37
+ st.header("Monte Carlo Simulation")
38
+ mean_return = st.number_input("Mean Annual Return", value=0.07)
39
+ std_dev = st.number_input("Standard Deviation", value=0.15)
40
+ years = st.slider("Number of Years", 1, 100, 30)
41
+ simulations = 50
42
+
43
+ # Simulate paths
44
+ np.random.seed(42)
45
+ results = np.zeros((simulations, years))
46
+ for i in range(simulations):
47
+ returns = np.random.normal(loc=mean_return, scale=std_dev, size=years)
48
+ results[i] = np.cumprod(1 + returns)
49
+
50
+ # Plot
51
+ fig = go.Figure()
52
+ for i in range(simulations):
53
+ fig.add_trace(go.Scatter(y=results[i], mode='lines', name=f'Sim {i+1}', line=dict(width=1)))
54
+ fig.update_layout(title="Monte Carlo Simulations of Portfolio Growth",
55
+ xaxis_title="Years",
56
+ yaxis_title="Portfolio Value (normalized)",
57
+ showlegend=False)
58
+
59
+ st.plotly_chart(fig)