2024-06-29 13:54:51 +10:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2024-08-08 08:24:44 +10:00
|
|
|
"execution_count": 2,
|
2024-06-29 13:54:51 +10:00
|
|
|
"metadata": {},
|
2024-06-29 21:21:35 +10:00
|
|
|
"outputs": [],
|
2024-06-29 13:54:51 +10:00
|
|
|
"source": [
|
|
|
|
"from dataclasses import dataclass\n",
|
|
|
|
"\n",
|
|
|
|
"@dataclass\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
"class PropertyFinanceParams:\n",
|
|
|
|
" \"\"\"Tunable parameters that describe the finances of a property.\"\"\"\n",
|
2024-06-29 13:54:51 +10:00
|
|
|
" purchase_price: float\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
" deposit_amount: float\n",
|
|
|
|
" loan_duration_years: int\n",
|
|
|
|
" lmi_amount: float\n",
|
|
|
|
" annual_rental_income: float\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" annual_rental_growth_rate: float\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
" annual_interest_rate: float\n",
|
|
|
|
" annual_growth_rate: float"
|
2024-06-29 21:21:35 +10:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2024-08-08 08:24:44 +10:00
|
|
|
"execution_count": 3,
|
2024-06-29 21:21:35 +10:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2024-06-30 09:56:09 +10:00
|
|
|
"def calculate_stamp_duty(purchase_price: float, first_home: bool) -> float:\n",
|
|
|
|
" if first_home:\n",
|
|
|
|
" if purchase_price < 600000:\n",
|
|
|
|
" return 0\n",
|
|
|
|
" elif purchase_price < 605000:\n",
|
|
|
|
" return 1045\n",
|
|
|
|
" elif purchase_price < 625000:\n",
|
|
|
|
" return 5428\n",
|
|
|
|
" elif purchase_price < 650000:\n",
|
|
|
|
" return 11356\n",
|
|
|
|
" elif purchase_price < 675000:\n",
|
|
|
|
" return 17785\n",
|
|
|
|
" elif purchase_price < 700000:\n",
|
|
|
|
" return 24713\n",
|
|
|
|
" elif purchase_price < 725000:\n",
|
|
|
|
" return 32141\n",
|
|
|
|
" elif purchase_price < 745000:\n",
|
|
|
|
" return 38444\n",
|
|
|
|
" else:\n",
|
|
|
|
" return\n",
|
|
|
|
" else:\n",
|
|
|
|
" if purchase_price < 25000:\n",
|
|
|
|
" return purchase_price * 0.014\n",
|
|
|
|
" elif purchase_price < 130000:\n",
|
|
|
|
" return 350 + (purchase_price - 25000) * 0.024\n",
|
|
|
|
" elif purchase_price < 960000:\n",
|
|
|
|
" return 2870 + (purchase_price - 130000) * 0.06\n",
|
|
|
|
" elif purchase_price < 2000000:\n",
|
|
|
|
" return purchase_price * 0.055\n",
|
|
|
|
" else:\n",
|
|
|
|
" return 110000 + (purchase_price - 2000000) * 0.065\n",
|
|
|
|
" \n",
|
|
|
|
"def calculate_annual_repayments(principal: float, annual_interest_rate: float, loan_duration_years: int):\n",
|
|
|
|
" return (principal * annual_interest_rate * (1 + annual_interest_rate) ** loan_duration_years) / ((1 + annual_interest_rate) ** loan_duration_years - 1)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2024-08-08 08:24:44 +10:00
|
|
|
"execution_count": 4,
|
2024-06-30 09:56:09 +10:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
2024-08-08 08:24:44 +10:00
|
|
|
"Upfront Costs: 321500.00 = 250000.00 deposit + 0.00 LMI + 71500.00 stamp duty\n",
|
|
|
|
"Annual Mortgage Payment: 81241.59\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
"\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
"Total Paid: 2437247.81\n",
|
|
|
|
"Property Value: 9895931.56\n",
|
|
|
|
"Total Interest Paid: 1387247.81\n",
|
|
|
|
"Total Rental Income: 116762.31\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
"\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
"Total Paid (10yr): 812415.94\n",
|
|
|
|
"Property Value (10yr): 2557296.76\n",
|
|
|
|
"Total Interest Paid (10yr): 650510.03\n",
|
|
|
|
"Total Principal Paid (10yr): 161905.91\n",
|
|
|
|
"Total Rental Income (10yr): 432219.86\n",
|
|
|
|
"Net Cash Position (10yr): -380196.08\n",
|
|
|
|
"Loan Balance (10yr): 888094.09\n",
|
|
|
|
"Total Equity (10yr): 1669202.67\n"
|
2024-06-30 09:56:09 +10:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"def run_simulation(property_finance_params: PropertyFinanceParams):\n",
|
|
|
|
" initial_loan_amount = property_finance_params.purchase_price - property_finance_params.deposit_amount\n",
|
|
|
|
" yearly_loan_balance = [initial_loan_amount]\n",
|
|
|
|
"\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" stamp_duty = calculate_stamp_duty(property_finance_params.purchase_price, first_home=False)\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
" upfront_costs = stamp_duty + property_finance_params.deposit_amount + property_finance_params.lmi_amount\n",
|
|
|
|
"\n",
|
|
|
|
" print(f\"Upfront Costs: {upfront_costs:.2f} = {property_finance_params.deposit_amount:.2f} deposit + {property_finance_params.lmi_amount:.2f} LMI + {stamp_duty:.2f} stamp duty\")\n",
|
|
|
|
"\n",
|
|
|
|
" annual_mortgage_payment = calculate_annual_repayments(initial_loan_amount, property_finance_params.annual_interest_rate, \n",
|
|
|
|
" property_finance_params.loan_duration_years)\n",
|
|
|
|
" \n",
|
|
|
|
" print(f\"Annual Mortgage Payment: {annual_mortgage_payment:.2f}\")\n",
|
|
|
|
"\n",
|
|
|
|
" yearly_interest_paid = []\n",
|
|
|
|
" yearly_principal_paid = []\n",
|
|
|
|
" yearly_property_value = [property_finance_params.purchase_price]\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" yearly_rental_income = [property_finance_params.annual_rental_income]\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
"\n",
|
|
|
|
" for year in range(property_finance_params.loan_duration_years):\n",
|
|
|
|
" interest_paid = yearly_loan_balance[-1] * property_finance_params.annual_interest_rate\n",
|
|
|
|
" yearly_interest_paid.append(interest_paid)\n",
|
|
|
|
" yearly_principal_paid.append(annual_mortgage_payment - interest_paid)\n",
|
|
|
|
"\n",
|
|
|
|
" yearly_loan_balance.append(yearly_loan_balance[-1] - yearly_principal_paid[-1])\n",
|
|
|
|
"\n",
|
|
|
|
" yearly_property_value.append(yearly_property_value[-1] * (1 + property_finance_params.annual_growth_rate))\n",
|
|
|
|
"\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" yearly_rental_income.append(yearly_rental_income[-1] * (1 + property_finance_params.annual_rental_growth_rate))\n",
|
|
|
|
"\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
" if yearly_loan_balance[-1] <= 0:\n",
|
|
|
|
" break # Loan fully paid off\n",
|
|
|
|
"\n",
|
|
|
|
" print()\n",
|
|
|
|
"\n",
|
|
|
|
" print(f\"Total Paid: {annual_mortgage_payment * property_finance_params.loan_duration_years:.2f}\")\n",
|
|
|
|
" print(f\"Property Value: {yearly_property_value[-1]:.2f}\")\n",
|
|
|
|
" print(f\"Total Interest Paid: {sum(yearly_interest_paid):.2f}\")\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" print(f\"Total Rental Income: {yearly_rental_income[-1]:.2f}\")\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
"\n",
|
|
|
|
" print()\n",
|
|
|
|
"\n",
|
|
|
|
" print(f\"Total Paid (10yr): {annual_mortgage_payment * 10:.2f}\")\n",
|
|
|
|
" print(f\"Property Value (10yr): {yearly_property_value[10]:.2f}\")\n",
|
|
|
|
" print(f\"Total Interest Paid (10yr): {sum(yearly_interest_paid[:10]):.2f}\")\n",
|
|
|
|
" print(f\"Total Principal Paid (10yr): {sum(yearly_principal_paid[:10]):.2f}\")\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" print(f\"Total Rental Income (10yr): {sum(yearly_rental_income[:10]):.2f}\")\n",
|
|
|
|
" print(f\"Net Cash Position (10yr): {sum(yearly_rental_income[:10]) - (annual_mortgage_payment * 10):.2f}\")\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
" print(f\"Loan Balance (10yr): {yearly_loan_balance[10]:.2f}\")\n",
|
|
|
|
" print(f\"Total Equity (10yr): {yearly_property_value[10] - yearly_loan_balance[10]:.2f}\")\n",
|
|
|
|
"\n",
|
|
|
|
"\n",
|
|
|
|
"run_simulation(\n",
|
|
|
|
" PropertyFinanceParams(\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" 1300000,\n",
|
|
|
|
" 250000,\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
" 30,\n",
|
|
|
|
" 0,\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" 36000,\n",
|
|
|
|
" 0.04,\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
" 0.066,\n",
|
2024-08-08 08:24:44 +10:00
|
|
|
" 0.07)\n",
|
2024-06-30 09:56:09 +10:00
|
|
|
")"
|
2024-06-29 13:54:51 +10:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
|
|
|
"display_name": "investment-simulator-KPfGkdIO-py3.12",
|
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
2024-08-08 08:24:44 +10:00
|
|
|
"version": "3.12.0"
|
2024-06-29 13:54:51 +10:00
|
|
|
},
|
|
|
|
"orig_nbformat": 4
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 2
|
|
|
|
}
|