mortgagepy is a python library used to work out common mortgage calculations including captial repayments, total cost of ownership and single month interest.
NOTE: This repository is still in development and the primary purpose is to understand good python packaging practices.
To install mortgagepy use the following command:
pip install git+https://github.com/charlieb954/mortgagepy.gitCreate a mortgage object and use it to compare against other mortgages.
Initialise a mortgage object.
>>> from mortgagepy import CapitalRepaymentMortgage
>>> my_mortgage = CapitalRepaymentMortgage(
property_value=280000, mortgage=210000, term_months=300, interest_rate=1.8
)Get a summary of the mortgage.
>>> my_mortgage.summarise(printed=True)
Capital Repayment Mortgage Summary
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ ┃ ┃ ┃ Monthly ┃ ┃ ┃ ┃ ┃
┃ Property ┃ Mortgage ┃ Loan To ┃ Repayment ┃ Term ┃ Interest ┃ Interest ┃ Total Cost ┃
┃ Value (£) ┃ (£) ┃ Value (%) ┃ (£) ┃ (Months) ┃ Rate (%) ┃ Paid (£) ┃ (£) ┃
┣━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━━━━┫
┃ 280000.0 ┃ 210000.0 ┃ 75 ┃ 869.79 ┃ 300.0 ┃ 1.8 ┃ 50937.0 ┃ 260937.0 ┃
┗━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┛Calculate overpayment impact of the mortgage.
>>> my_mortgage.overpayment_projection(monthly_overpayment=100)
{
'time to repay (months)': 263,
'time saved (months)': 37.0,
'total interest paid (%)': 23811.59,
'interest saved (£)': 3617.41
}Access individual attributes such as monthly repayments or LTV.
>>> my_mortgage.monthly_repayment()
869.79>>> my_mortgage.ltv()
75Calculate the monthly repayment for a capital payment mortgage.
>>> from mortgagepy.calculator import monthly_capital_repayment
>>> monthly_capital_repayment(
mortgage=130_500, interest_rate=6.89, mortgage_length_months=300
)
913.21Work out the total cost of a mortgage.
>>> from mortgagepy.calculator import total_cost_of_mortgage
>>> total_cost_of_mortgage(
mortgage=130_500, interest_rate=6.89, mortgage_length_months=300
)
273_963.0Calculate repayments for an interest only mortgage.
>>> from mortgagepy.calculator import monthly_interest_only
>>> monthly_interest_only_repayment(
mortgage=130_500, interest_rate=3.89
)
423.04Calculate the loan-to-value as a percentage given a deposit and property value.
>>> from mortgagepy.calculator import ltv
>>> ltv(
property_value=200_000, deposit=50_000
)
75Calculate the monthly interest to be paid on a mortgage.
>>> from mortgagepy.calculator import monthly_interest
>>> monthly_interest(
balance_at_previous_month=98_868.70, interest_rate=1.89, month=10, year=2023
)
158.7Calulate the time saved by overpaying on your mortgage.
>>> from mortgagepy.calculator import capital_overpayment
>>> capital_overpayment(
mortgage=200000, interest_rate=3.5, mortgage_length_months=300, monthly_overpayment=100
)
{
'time to repay (months)": 262,
'time saved (months)': 38,
'total interest paid (£)': 87992.71
}Compare the cost of two interest rates for a capital repayment mortgage.
>>> from mortgagepy.compare import compare_capital_repayment_rates
>>> compare_capital_repayment_rates(
mortgage=130_500, interest_rates=[1, 2], mortgage_length_months=300
)
[
{'interest_rate': 1, 'repayment': 491.82},
{'interest_rate': 2, 'repayment': 553.13}
]Compare the cost of two interest rates for an interest only mortgage.
>>> from mortgagepy.compare import compare_interest_only_rates
>>> compare_interest_only_rates(
mortgage=130_500, interest_rates=[1, 2]
)
[
{'interest_rate': 1, 'repayment': 108.75},
{'interest_rate': 2, 'repayment': 217.5}
]