Calculating the monthly mortgage payment
In order to make sure you can afford the home, you will have to calculate the monthly mortgage payment you will have to make on a loan that size.
Now, since you will be paying a monthly mortgage, you will have to convert each of the parameters into their monthly equivalents. Be careful when adjusting the interest rate, which is compounding!
In order to calculate the monthly mortgage payment, you will use the numpy
function .pmt(rate, nper, pv)
where:
rate
= The periodic (monthly) interest ratenper
= The number of payment periods (months) in the lifespan of the mortgage loanpv
= The total value of the mortgage loan
You have been given a 30-year mortgage loan quote for your desired amount at 3.75%. The value of the mortgage loan is available as mortgage_loan
.
The annual mortgage rate is available as mortgage_rate
This exercise is part of the course
Introduction to Financial Concepts in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import numpy as np
# Derive the equivalent monthly mortgage rate from the annual rate
mortgage_rate_periodic = ____
# How many monthly payment periods will there be over 30 years?
mortgage_payment_periods = ____
# Calculate the monthly mortgage payment (multiply by -1 to keep it positive)
periodic_mortgage_payment = -1*np.pmt(____, ____, ____)
print("Monthly Mortgage Payment: " + str(round(periodic_mortgage_payment, 2)))