investment_simulator/mortgage.py

93 lines
4.2 KiB
Python
Raw Normal View History

2024-08-08 08:24:44 +10:00
import matplotlib.pyplot as plt
periods_per_year = 12
loan_duration_years = 30
nominal_annual_interest_rate = 6.6 / 100
loan_principal = 600000
deposit = 32500
additional_upront_costs = 11356
annual_appreciation_rate = 5 / 100
initial_annual_rental_income = 14400
rental_income_annual_growth_rate = 6 / 100
baseline_annual_yield = 9 / 100 # ETF
rental_cost_annual_growth_rate = 6 / 100 # If I don't buy a PPOR
initial_annual_rental_cost = 20400 # Living in carlton
initial_property_value = loan_principal + deposit
period_interest_rate = nominal_annual_interest_rate / periods_per_year
total_loan_periods = periods_per_year * loan_duration_years
period_appreciation_rate = (1 + annual_appreciation_rate) ** (1 / periods_per_year) - 1
period_rental_income_growth_rate = (1 + rental_income_annual_growth_rate) ** (1 / periods_per_year) - 1
initial_period_rental_income = initial_annual_rental_income / periods_per_year
baseline_period_yield = (1 + baseline_annual_yield) ** (1 / periods_per_year) - 1 # ETF
period_rental_cost_growth_rate = (1 + rental_cost_annual_growth_rate) ** (1 / periods_per_year) - 1 # Renting
initial_period_rental_cost = initial_annual_rental_cost / periods_per_year
period_payment = (loan_principal * (period_interest_rate * (1 + period_interest_rate) ** total_loan_periods) /
((1 + period_interest_rate) ** total_loan_periods - 1))
property_value = initial_property_value
property_values = [property_value]
remaining_loan = loan_principal
remaining_loans = [remaining_loan]
equity = deposit
equities = [equity]
total_payments = 0
total_payments_list = [total_payments]
total_interest_paid = 0
total_interest_paid_list = [total_interest_paid]
total_rental_income = 0
total_rental_income_list = [total_rental_income]
rental_income_period = initial_period_rental_income
net_worth = deposit - additional_upront_costs
net_worths = [net_worth]
total_baseline_value = deposit + additional_upront_costs # ETF initial investment of all property upfront costs
total_baseline_values = [total_baseline_value]
rental_cost_period = initial_period_rental_cost # renting
for period in range(total_loan_periods):
total_payments += period_payment
interest_paid_period = remaining_loan * period_interest_rate
total_interest_paid += interest_paid_period
principal_paid_period = period_payment - interest_paid_period
remaining_loan -= principal_paid_period
appreciation_period = property_value * (1 + period_appreciation_rate) - property_value
property_value += appreciation_period
equity += principal_paid_period + appreciation_period
rental_income_period *= 1 + period_rental_income_growth_rate
total_rental_income += rental_income_period
cashflow_period = rental_income_period - interest_paid_period
net_worth += cashflow_period + appreciation_period + principal_paid_period
rental_cost_period *= 1 + period_rental_cost_growth_rate # My rent keeps increasing :((
total_baseline_value = total_baseline_value * (1 + baseline_period_yield) + max(period_payment - rental_cost_period, 0) # ETF grows from compounding and deposit. Assuming that deposit is equal to what would otherwise be building equity in a property - expense of rent
property_values.append(property_value)
remaining_loans.append(remaining_loan)
equities.append(equity)
total_payments_list.append(total_payments)
total_interest_paid_list.append(total_interest_paid)
total_rental_income_list.append(total_rental_income)
net_worths.append(net_worth)
total_baseline_values.append(total_baseline_value)
plt.figure(figsize=(14, 8))
plt.plot(property_values, label='Property Value', color='blue')
plt.plot(remaining_loans, label='Remaining Loan', color='red')
plt.plot(equities, label='Equity', color='green')
plt.plot(net_worths, label='Net Worth', color='purple')
plt.plot(total_payments_list, label='Total Payments', color='orange')
plt.plot(total_interest_paid_list, label='Total Interest Paid', color='brown')
plt.plot(total_rental_income_list, label='Total Rental Income', color='teal')
plt.plot(total_baseline_values, label='Total Baseline Value (ETF)', color='black')
plt.title('Financial Metrics and ETF Comparison over the Loan Term')
plt.xlabel('Months')
plt.ylabel('Dollar Amount')
plt.legend()
plt.grid(True)
plt.show()