# Build My First Mortgage Calculator by Numpy in Colab

`!pip install numpy-financialimport numpy as npimport numpy_financial as npf`

# Slider Inputs

`#@title MORTGAGE CALCULATOR - INPUT DATAmort_rate = 2.55 #@param {type:"slider", min:0.00, max:10.00, step:0.05}loan_amt = 700000 #@param {type:"slider", min:100000, max:1500000, step:10000}repay_yr = 30 #@param {type:"slider", min:1, max:40, step:1}`

# Calculate Monthly Repayment Amount

`#Mortgage Calculator - monthly repayment amountrate_x = mort_rate/1200 #monthly mortgage rate in 2 decimal places, 2% -> 0.02nper_x = repay_yr*12 #duration of loan in number of monthspv_x = -1*loan_amt #loan principle amount in NZD as negative cash flowpmt_x1 = npf.pmt(rate_x, nper_x, pv_x) #monthly mortgage repayment amountprint("Monthly Repayment Amount: NZD", np.round(pmt_x1,2))`
`Monthly Repayment Amount: NZD 2784.08`

# Amortization Schedule:

`#Amortization Table - mortgage interest and principle repayment scheduleper_x = np.arange(nper_x) + 1ipmt_x = npf.ipmt(rate_x, per_x, nper_x, pv_x) #monthly mortgage interest amountppmt_x = npf.ppmt(rate_x, per_x, nper_x, pv_x) #monthly mortgage principle amountfmt = '{0:2d} {1:8.2f} {2:8.2f} {3:8.2f} {4:8.2f}'#format for paymentno in per_x:   index = paymentno - 1   pmt_x = ipmt_x + ppmt_x   pv_x = pv_x + ppmt_x[index]   print(fmt.format(paymentno, ppmt_x[index], ipmt_x[index], pmt_x[index], pv_x))`
`#Total Amount of Interest totint_x = np.sum(ipmt_x) print("Total Amount of Interest Paid: NZD", np.round(totint_x, 2))`
`Total Amount of Interest Paid: NZD 302268.02`
`whatif_pmt_x = 4000whatif_nper = npf.nper(rate_x, whatif_pmt_x, pv_x)print("New Repayment Period - Number of Months:", np.round(whatif_nper,0))New Repayment Period - Number of Months: 219.0`