How to Calculate Home Loan Approvals and Prices with Python!

LeMaster Tech
183 followers
27 Video Views·Apr 23, 2025
Prepare for a technical interview, practice building an app or get ready for an upcoming test or quiz with these sample projects! This episode covers creating a home loan approval estimator based off of salary and approximate interest rates and down payments! This is great practice for designing code to model real world scenarios.
This is episode 3 in a Python beginner project series coming from LeMaster Tech.
Be sure to give us a like, drop a comment, or subscribe to the channel for more content like this!
The previous video:
https://www.youtube.com/watch?v=k9IhIKvYPak&t=3s
python download:
https://www.python.org/downloads/
pycharm download for windows:
https://www.jetbrains.com/pycharm/dow...
hello and welcome back to the channel
today's episode will be episode three in
our beginner python projects uh tutorial
series on the channel
and um we are gonna be covering some
things assuming you have some pretty
basic understanding of python already
so there is a tutorial
on this channel as well a tutorial
series if you have no exposure to python
that's the best place to start for
beginners
but without any further ado let's go
ahead and dive into this project
so when applying for home loans uh
typically the most
that you'll be able to get approved for
is 28 of your pre-tax income on housing
that's a fairly typical mark that banks
aim for um but again this is just kind
of a practice in taking a real world
scenario and figuring out how you would
model that in code
so there are a lot of variables that go
into home loans like credit and location
and things like that but we're going to
kind of simplify it for today's code
and really shoot for focus on this 28 of
your pre-tax income
so
the
the formula for
um calculating a
estimated home loan is is pretty
straightforward um
but the way we're gonna do it we're
gonna start with our function define
uh calculate
max
home loan
and we don't have to pass any parameters
into this thing because we're going to
handle getting the parameters inside our
function
so we'll start by saying salary and
let's get the user input from them on
what their annual
household income is and let's say
it's going to be a float and then we ask
them
what is your
household
pre
tax
annual
income
and there we go that's going to be an
input that's going to
ask users to enter their salary info
and then let's say rate
is
float
input
let's ask them to estimate
their
estimate
you're we're talking to them
expected
interest rate
so we're gonna kind of ask the user to
do a little homework here because this
is something where you should be able to
punch in your credit and punch in the
region that you live in and get an idea
for approximately what a housing
rate is today i mean those things
fluctuate so much based on the economy
and based on location that we can ask
the user to just kind of estimate on
their own
and then let's figure out what they have
in mind for down payment so
that's kind of something we'll get into
later
it's not directly related in getting
approved but sometimes the amount that
you pay
will go up significantly if you can't
get to a 20 down payment so let's just
ask them
how much do you have available
as
down payment
okay so we're getting three useful
inputs there and let's go ahead and
start using that
so let's say the max
monthly payment you could make based on
our estimate of 28
of your salary is what you'd get
approved for
let's say that would be your salary
times
0.28
and
let's what divide that by 12. so that's
a monthly payment
and then
let's
print that out so that's just kind of
first thing
the maximum
monthly
payment would be around
and again these are estimates we're
trying to give a potential user an idea
of what they could expect
so let's round that we don't really care
about to the thousands of cents let's
just say max monthly
and to two decimal places
and
so i mean if we run this right now we're
not doing anything with rate or down yet
oh this is still from our previous
example let's run
so
oh we forgot to call the function
calculate silly there we go
so let's just say we make
sixty thousand dollars a year we're
expecting a six percent rate we're not
doing anything with the these two values
yet but so there's they're telling us on
an income of sixty thousand the max
monthly payment we'd be allowed to pay
would be around fourteen hundred a month
and these are pre-tax
numbers but so that's kind of cool we
got to a maximum allowable monthly but
now we have to actually calculate well
what would that come out to in terms of
total value of the home
so there's a factor that's pretty
important in calculating this that we'll
call interest variable because it gets
used twice in the greater
and the greater formula for it
but that looks like
1
plus the rate that got entered as a
decimal
over
100 times 12
because
this is asking for
this is asking for monthly rate and this
is entered as a percentage so to get
from percentage to decimal you divide by
a hundred and then to get from that
number to monthly because that's annual
you divide by 12. so we'll actually
instead of saying 100 times 12
we'll say 1200 i just want you to know
where that value is coming from
and then i'm actually going to put that
whole thing inside another set of
parentheses because the power that we're
raising it to
is going to be
360.
so this is i'm calling it the interest
variable
um this 360 is number of payment periods
and we'll just do it assuming you're
getting a 30 year fixed rate mortgage so
that would be
12 monthly payments for 30 years that's
where the 360 is coming from
and i mean you can find this formula
online if you want
but
or you can just follow along and say
we're taking a real world scenario and
we're modeling code after it so
for the rate math it it comes out to
interest variable
divided by
and then you'll kind of see right away
why it was more useful to write that
code as a variable it's divided by
interest variable minus one so we're
getting it as a ratio
and then that whole thing
is multiplied
times the rate again divided by 1200 so
um i mean you could even make a case
that like breaking it into rate divided
by 1200 as its own variable could have
been useful as well
but this is how we get the rate math and
then the maximum loan
that you typically would get approved
for
i'm not sure why my indentation got
jacked up there
but the max actual loan
would be a function of your maximum
monthly payment which we've calculated
out
divided by
the rate math
and i'm getting quite a few
red lines
so what have i done
unexpected syntax
um
curious well we'll keep going and see if
this runs
so then after we've gotten the max loan
let's go ahead and print
i really gotta figure out what is going
on in these lines
let's go ahead and
try that again
spelled down incorrectly
did i newline this am i oh i might be
one i was stupid
so i was one
parentheses short on closing that
function out
which is syntax is the least fun part of
code always
but then once we get the max alone let's
go ahead and print
the max
you are likely to be
approved
for
is
around
and we want to say around because we're
not promising them anything we're not a
bank we're just trying to give them an
idea of what they could get
and then we will
round the max loan we just calculated
and we will throw a caveat in here based
on
just
salary
so that's pretty cool but let's go ahead
and do a second thing as well and just
tell them like we're acting in their
best interest
however
to avoid
pmi which is the added expense if you're
not up to a 20 down payment
and have a
20
down payment
the max
you
would want to borrow
would be
and then let's say
round
our down payment times five right
because we want to keep it at twenty
percent
and
let's round that to two decimal places
go ahead and close that out and let's
see if this works uh we did that kind of
fast i made a few mistakes but let's
see what we get so household
say we're doing pretty well making 100
grand
and we're expecting a 3 interest rate
rates are super low right now
and sure we have
20 000 as a down payment
so they're saying you know you probably
would get approved for a monthly payment
of around 2300 which is a house around
fifty five hundred i mean or fifty five
thousand five hundred and fifty thousand
goodness um purely based on salary but
if all you have is uh twenty grand for a
down payment then you might want to
shoot for a mortgage more around a
hundred grand otherwise you're paying a
couple hundred bucks a month in pmi so
let's try running that again
and say okay well we've got
a hundred grand we're expecting a four
percent rate
but we're doing a little better on down
payment i mean we've got saved up to 60
grand and let's see what comes with that
so same monthly payment as before but
you can see just by increasing the
interest rate that's actually going to
give us less of a total loan because
more of that monthly payment would be
interest
um and then again if we want to have a
20 down payment then the max we might
want to take out would actually be 300
grand to avoid pmi so
this is kind of a useful tool um i mean
these numbers are pretty close i can
tell you as someone who recently bought
a house but even if you don't care so
much about calculating a home loan this
is a pretty useful example of taking a
real world scenario and figuring out how
to model it inside of code and that's
basically all writing code is so
hopefully you found this project
informative and useful if you have any
questions or you would have done
something differently than how i did it
feel free to let me know in the comments
and i'll try to get back to you as soon
as possible
and if you found this content or
anything on the channel uh helpful then
go ahead and
leave a like and subscribe i really
appreciate it and as always thanks for
checking out the channel and good luck
with your code thanks bye
