GarGerry commited on
Commit
90d4958
·
verified ·
1 Parent(s): 2f4b84b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+
6
+ def calculate_investment(initial_deposit, years, rate, contribution, freq):
7
+ months = years * 12
8
+ rate_monthly = (rate / 100) / 12
9
+ balance = [initial_deposit]
10
+
11
+ for i in range(1, months + 1):
12
+ new_balance = balance[-1] * (1 + rate_monthly) + (contribution if freq == 'Monthly' else 0)
13
+ if i % 12 == 0 and freq == 'Annually':
14
+ new_balance += contribution
15
+ balance.append(new_balance)
16
+
17
+ return balance
18
+
19
+ # Streamlit UI
20
+ st.title("Investment Calculator")
21
+
22
+ # User Inputs
23
+ initial_deposit = st.number_input("Initial Deposit ($)", min_value=1, value=1000)
24
+ years = st.number_input("Years of Growth", min_value=1, max_value=50, value=10)
25
+ estimated_rate = st.number_input("Estimated Annual Rate of Return (%)", min_value=0.0, value=5.0)
26
+ contribution = st.number_input("Contribution Amount ($)", min_value=0, value=100)
27
+ contribution_freq = st.radio("Contribution Frequency", ("Monthly", "Annually"))
28
+
29
+ if st.button("Calculate"):
30
+ balances = calculate_investment(initial_deposit, years, estimated_rate, contribution, contribution_freq)
31
+
32
+ # Plot results
33
+ plt.figure(figsize=(8,5))
34
+ plt.plot(range(len(balances)), balances, label="Total Balance", color='green')
35
+ plt.xlabel("Months")
36
+ plt.ylabel("Balance ($)")
37
+ plt.title("Investment Growth Over Time")
38
+ plt.legend()
39
+ st.pyplot(plt)
40
+
41
+ st.success(f"Final Balance: ${balances[-1]:,.2f}")