## DEV Community is a community of 638,230 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

loading... # Mortgage Calculator Python

I've done this portfolio project in Computer Science course CodeAcademy

### Project Objectives:

• Build a terminal program using Python
• Add at least one interactive feature using `input()`
• Use Git version control
• Use the command line and file navigation
• Write a technical blog post on the project

I've chosen to build Mortgage Calculator. It's not so fun but pretty useful.

### Functionality of the terminal program

Take user's input:

• Duration of loan programm
• Loan Amount
• Interest Rate per year

Mortgage calculation Implementation

Output:

• Total Monthly Payment
• Total Interest Paid
• Total of n-months Payments
• Show monthly amortization table.

### Work on the project consists of three parts:

1. Project Brainstorming
2. Exploring subject area
3. Program implementation

The project have been implemented in two versions. With python packages and without it.

In the first version I use numpy_financial 1.0.0 package. It contains a collection of elementary financial functions. In particular pmt() function that computes the payment against loan principal plus interest (a monthly mortgage payment). As well as ipmt() and ppmt(). The interest portion of monthly payment and the payment against loan principal. This two functions return an array of Interest/principal portion of payment for every month.

The total payment is made up of payment against principal plus interest.

pmt = ppmt + ipmt

The second version uses mortgage formula for calculating monthly payment.

Code consists three parts:

• Variables-Input part
• Functions part
• Output part

In Functions part we have paidEveryMonth(interestRate, months, borrowed):

``````def paidEveryMonth(interestRate, months, borrowed):             #fixed monthly payment
return (borrowed * true_rate * ((true_rate + 1)**months)) / ((true_rate + 1)**months - 1)#Mortgage formula
``````

There is the logic of the Mortgage function: def fullReport(total_pem, borrowed) function forms monthly amortization table.

``````def fullReport(total_pem, borrowed):
print("||||||||||||||||||||||||||||||||||||||||")
print("MONTH -> P&I   " + "= PRINCIPAL + INTEREST| PRINCIPAL REMAINING")
fmt = '{0:2d} -> {4:8.2f} = {1:8.2f} + {2:8.2f} | {3:8.2f}' # Format our table
for index in range(1, months + 1):                          #for every month
interest = borrowed * interestRate / 12                 #interest to the end of the month
principal = total_pem - interest                        #principal repayment
borrowed -= principal                                   #balance
print(fmt.format(index, principal, interest, borrowed, total_pem))
``````

A link to my code on GitHub.