Skip to content

Instantly share code, notes, and snippets.

@jawad360
Created August 13, 2025 19:38
Show Gist options
  • Save jawad360/4503e197c62d74065e4f1c9569bfdb43 to your computer and use it in GitHub Desktop.
Save jawad360/4503e197c62d74065e4f1c9569bfdb43 to your computer and use it in GitHub Desktop.
Investment+Return
# Withdrawal Calculator
def calculate_remaining_balance(principal, annual_rate, withdraw, annual_increase, no_of_years):
# Annual compounding interest rate
rate = annual_rate / 100
for year in range(1, no_of_years + 1):
# Compound the interest annually
principal *= (1 + rate)
# Withdraw monthly for the year
for month in range(12):
principal -= withdraw
# Increase the monthly withdrawal by the annual increase rate
withdraw *= (1 + annual_increase / 100)
return principal
# Example Inputs
principal = 50000000 # Starting amount (1 million)
annual_rate = 12 # Annual interest rate (14%)
withdraw = 320000 # Initial monthly withdrawal amount
annual_increase = 6 # Withdrawal increase percentage per year
no_of_years = 25 # Number of years to calculate for
# Calculate the remaining balance after the given years
remaining_balance = calculate_remaining_balance(principal, annual_rate, withdraw, annual_increase, no_of_years)
print("Balance: ", remaining_balance)
# Investment Calculator
def calculate_investment_balance(principal, annual_rate, monthly_installment, raise_percentage, no_of_years):
rate = annual_rate / 100
total_balance = principal
# Monthly rate for compounding
monthly_rate = (1 + rate) ** (1/12) - 1
for year in range(1, no_of_years + 1):
# Compound the principal at the end of the year
total_balance *= (1 + rate)
# Add the monthly installments for the year
for month in range(12):
total_balance += monthly_installment * (1 + monthly_rate) ** (12 - month) # Each month grows
# Increase the monthly installment after each year
monthly_installment *= (1 + raise_percentage / 100)
return total_balance
# Example Inputs
principal = 4000000 # Starting amount (1 million)
annual_rate = 12 # Annual interest rate (14%)
monthly_installment = 10000 # Initial monthly installment amount
raise_percentage = 5 # Increase in monthly installment per year (6%)
no_of_years = 20 # Number of years to calculate for
# Calculate the final balance after the given number of years
final_balance = calculate_investment_balance(principal, annual_rate, monthly_installment, raise_percentage, no_of_years)
print("Investment: ", final_balance)
@jawad360
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment