Saurabh502 commited on
Commit
6a3b396
·
verified ·
1 Parent(s): aaaf3de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -76,11 +76,16 @@ with tab1:
76
  with tab2:
77
  st.header("SWP Calculator")
78
 
79
- def calculate_swp(initial_investment, monthly_withdrawal, annual_rate, years):
 
 
80
  monthly_rate = annual_rate / 12 / 100
 
 
81
  num_months = years * 12
82
 
83
  balance = float(initial_investment) # Use float for precision
 
84
  total_interest_earned = 0.0
85
  total_withdrawn = 0.0
86
 
@@ -91,10 +96,13 @@ with tab2:
91
  monthly_withdrawals = [0.0] # Withdrawal made *during* month i is stored at index i
92
 
93
  for month in range(1, num_months + 1):
94
- # Determine actual withdrawal amount first
95
- # Using float(monthly_withdrawal) assumes withdrawal continues even if balance is insufficient
96
- actual_withdrawal = float(monthly_withdrawal)
97
- # A more robust approach could be: actual_withdrawal = min(balance, float(monthly_withdrawal))
 
 
 
98
  # but we stick closer to the original implicit logic for now.
99
 
100
  # Subtract withdrawal from the balance
@@ -157,11 +165,15 @@ with tab2:
157
  monthly_withdrawal = st.number_input('Monthly Withdrawal', value=100000, step=1000, format='%d', key="swp_monthly")
158
  annual_rate = st.number_input('Annual Interest Rate (%)', value=8.0, step=0.1, format='%.1f', key="swp_rate")
159
  years = st.number_input('Investment Period (Years)', value=20, step=1, format='%d', key="swp_years")
 
 
 
 
160
 
161
  if st.button('Calculate SWP'):
162
- # Unpack all four return values from the updated function
163
  final_balance_calc, total_interest_calc, total_withdrawal_calc, df = calculate_swp(
164
- initial_investment, monthly_withdrawal, annual_rate, years
165
  )
166
 
167
  st.subheader('SWP Projection')
 
76
  with tab2:
77
  st.header("SWP Calculator")
78
 
79
+ # Add inflation_rate and withdrawal_increase_rate parameters
80
+ # Add inflation_rate and withdrawal_increase_rate parameters
81
+ def calculate_swp(initial_investment, monthly_withdrawal, annual_rate, years, inflation_rate, withdrawal_increase_rate):
82
  monthly_rate = annual_rate / 12 / 100
83
+ # Convert percentage rate to decimal for calculation
84
+ withdrawal_increase_rate_decimal = withdrawal_increase_rate / 100.0
85
  num_months = years * 12
86
 
87
  balance = float(initial_investment) # Use float for precision
88
+ current_monthly_withdrawal = float(monthly_withdrawal) # Start with the initial withdrawal amount
89
  total_interest_earned = 0.0
90
  total_withdrawn = 0.0
91
 
 
96
  monthly_withdrawals = [0.0] # Withdrawal made *during* month i is stored at index i
97
 
98
  for month in range(1, num_months + 1):
99
+ # Increase withdrawal amount at the start of each year (after the first year)
100
+ if month > 1 and (month - 1) % 12 == 0:
101
+ current_monthly_withdrawal *= (1 + withdrawal_increase_rate_decimal)
102
+
103
+ # Determine actual withdrawal amount first using the current (potentially increased) amount
104
+ actual_withdrawal = current_monthly_withdrawal
105
+ # A more robust approach could be: actual_withdrawal = min(balance, current_monthly_withdrawal)
106
  # but we stick closer to the original implicit logic for now.
107
 
108
  # Subtract withdrawal from the balance
 
165
  monthly_withdrawal = st.number_input('Monthly Withdrawal', value=100000, step=1000, format='%d', key="swp_monthly")
166
  annual_rate = st.number_input('Annual Interest Rate (%)', value=8.0, step=0.1, format='%.1f', key="swp_rate")
167
  years = st.number_input('Investment Period (Years)', value=20, step=1, format='%d', key="swp_years")
168
+ # Add new input fields
169
+ inflation_rate = st.number_input('Expected Inflation Rate (%)', value=6.0, step=0.1, format='%.1f', key="swp_inflation")
170
+ withdrawal_increase_rate = st.number_input('Annual Withdrawal Increase (%)', value=0.0, step=0.1, format='%.1f', key="swp_increase")
171
+
172
 
173
  if st.button('Calculate SWP'):
174
+ # Pass the new input values to the function
175
  final_balance_calc, total_interest_calc, total_withdrawal_calc, df = calculate_swp(
176
+ initial_investment, monthly_withdrawal, annual_rate, years, inflation_rate, withdrawal_increase_rate
177
  )
178
 
179
  st.subheader('SWP Projection')