first pass print statements
This commit is contained in:
parent
a57a6b6ce7
commit
2af870cde5
143
demo.ipynb
143
demo.ipynb
|
@ -2,29 +2,154 @@
|
|||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from dataclasses import dataclass\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class PropertyParams:\n",
|
||||
" \"\"\"Tunable parameters that describe a property.\"\"\"\n",
|
||||
"class PropertyFinanceParams:\n",
|
||||
" \"\"\"Tunable parameters that describe the finances of a property.\"\"\"\n",
|
||||
" purchase_price: float\n",
|
||||
" deposit_percentage: float\n",
|
||||
" deposit_guarantor: bool\n",
|
||||
" rental_income: float\n",
|
||||
" ongoing_costs: float\n"
|
||||
" deposit_amount: float\n",
|
||||
" loan_duration_years: int\n",
|
||||
" lmi_amount: float\n",
|
||||
" annual_rental_income: float\n",
|
||||
" annual_interest_rate: float\n",
|
||||
" annual_growth_rate: float"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from transitions import Machine"
|
||||
"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",
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Upfront Costs: 31045.00 = 30000.00 deposit + 0.00 LMI + 1045.00 stamp duty\n",
|
||||
"Annual Mortgage Payment: 44102.58\n",
|
||||
"\n",
|
||||
"Total Paid: 1323077.38\n",
|
||||
"Property Value: 2593165.43\n",
|
||||
"Total Interest Paid: 753077.38\n",
|
||||
"Total Rental Income: 900000.00\n",
|
||||
"\n",
|
||||
"Total Paid (10yr): 441025.79\n",
|
||||
"Property Value (10yr): 977336.78\n",
|
||||
"Total Interest Paid (10yr): 353134.02\n",
|
||||
"Total Principal Paid (10yr): 87891.78\n",
|
||||
"Total Rental Income (10yr): 300000.00\n",
|
||||
"Net Cash Position (10yr): -141025.79\n",
|
||||
"Loan Balance (10yr): 482108.22\n",
|
||||
"Total Equity (10yr): 495228.55\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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",
|
||||
" stamp_duty = calculate_stamp_duty(property_finance_params.purchase_price, first_home=True)\n",
|
||||
" 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",
|
||||
"\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",
|
||||
" 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",
|
||||
" print(f\"Total Rental Income: {property_finance_params.annual_rental_income * property_finance_params.loan_duration_years:.2f}\")\n",
|
||||
"\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",
|
||||
" print(f\"Total Rental Income (10yr): {property_finance_params.annual_rental_income * 10:.2f}\")\n",
|
||||
" print(f\"Net Cash Position (10yr): {(property_finance_params.annual_rental_income * 10) - (annual_mortgage_payment * 10):.2f}\")\n",
|
||||
" 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",
|
||||
" 600000,\n",
|
||||
" 30000,\n",
|
||||
" 30,\n",
|
||||
" 0,\n",
|
||||
" 30000,\n",
|
||||
" 0.066,\n",
|
||||
" 0.05)\n",
|
||||
")"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue
Block a user