[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1836.0. "mortgage formula" by POLAR::MOKHTAR () Mon Jan 31 1994 19:43

Hi,

I am trying to write a mortgage calculation program for learning purposes.
I need to know what formula computes the monthly payments as function of 
principle,intereset rate and payment period.

The formula  amount = principle * ( 1 + interest rate ) ^ period  does not 
apply since it does not take into account that payements are being made 
during the loan period.

I think the following is correct :
principle  = principle   - monthly payment + ( principle * interest rate / 12 )
         i            i-1                               i-1 
where i is month index.
However I am not able to solve the equation for payments as function of 
principle.          Help appreciated
T.RTitleUserPersonal
Name
DateLines
1836.1May want to ask the prosVMSDEV::HALLYBFish have no concept of fireTue Feb 01 1994 00:476
    I'm sure this is answered, probably with sample programs, in
    TALLIS::REAL_ESTATE.
    
    Of course, it would also be nice to have the algorithm here, too.
    
      John
1836.2my mortgage.com in dcl !HANNAH::OSMANsee HANNAH::IGLOO$:[OSMAN]ERIC.VT240Tue Feb 01 1994 16:4076
$!
$!	Procedure to calculate monthly payment, in dollars, to pay off
$!	a given loan at a given yearly interest rate for a given number of
$!	years.
$!
$!	Author:   Eric Osman   10-Feb-1993
$!
$ set = "set"
$ set symbol/scope=(nolocal,noglobal)
$ on warning then stop
$ loan = p1
$ if loan .eqs."" then read/prompt="How much is loan (in dollars ONLY) ? " -
    sys$command loan
$ percent = p2
$ if percent .eqs. "" then read/prompt="Percentage rate (decimal point ok) ? " -
    sys$command percent
$ years = p3
$ if years .eqs. "" then read/prompt="How many years (NO decimal point) ? " -
    sys$command years
$ loan = f$int(loan)
$ scale = 0
$ if percent - "." .nes. percent then -
    scale = f$len(percent) - f$loc(".",percent) - 1
$ percent_num = percent - "."
$ percent_den = "1" + f$fao("!#*0",scale)
$ percent_num = f$int(percent_num)
$ percent_den = f$int(percent_den)
$ monthly_installments = years*12
$ low_payment = 0
$ high_payment = 10000
$ months = years*12
$ guess_payment = 0
$ guess_payment = (low_payment+high_payment)/2
$ try_lup:
$ old_guess = guess_payment
$ write sys$output "Trying a payment of $", guess_payment
$ call calculate_installments 'loan' 'guess_payment' 'percent_num' 'percent_den'
$ new_installments = $status/2
$ if new_installments .lt. monthly_installments
$ then
$	high_payment = guess_payment
$	message = "Too much..."
$ endif
$ if new_installments .gt. monthly_installments
$ then
$	low_payment = guess_payment
$	message = "Too little..."
$ endif
$ guess_payment = (low_payment+high_payment)/2
$ if guess_payment .eq. old_guess
$ then
$	write sys$output "That's it !"
$	exit
$ else
$	write sys$output message
$ endif
$ goto try_lup
$ calculate_installments: subroutine
$ on warning then stop
$ owed = f$int(p1)
$ payment = f$int(p2)
$ yearly_percent_num = f$int(p3)
$ yearly_percent_den = f$int(p4)
$ installments = 0
$ new_int = 1000000
$ lup:
$ old_int = new_int
$ installments = installments + 1
$ remaining = owed - payment
$ new_int = remaining*yearly_percent_num/1200/yearly_percent_den
$ if new_int .gt. old_int then exit 10000*2+1
$ owed = remaining + new_int
$ if owed .gt. 0 .and. new_int .gt. 0 then goto lup
$ exit installments*2+1
$ endsubroutine

1836.3not a clean solutionPOLAR::MOKHTARTue Feb 01 1994 19:0713
    
    Thanks for the replies.
    the method used in .2 has the same problem as i mentioned in the base
    note. It does not directly solve an equation for payments as functions
    of principle, rather it iterates guessed values of payments and tests 
    them in the equation i mentioned in .0 ( the equation for principle as 
    function of payments ). I thaught of such method but i prefer a better 
    way.
    
    Is there an equation that directly solves for payments ?                   
    Thanks 
         
    
1836.4AUSSIE::GARSONHotel Garson: No VacanciesTue Feb 01 1994 20:127
re .3
    
>    Is there an equation that directly solves for payments ?
    
    Yes, that mortgage payment recurrence can be solved in closed form i.e.
    down to an exponentiation. I did it about a year ago when I bought my
    house. I'll see whether I can locate the envelope in question.
1836.53D::ROTHGeometry is the real life!Tue Feb 01 1994 23:3615
    If p is the principal q is the payment, and a is the interest
    per payment period (say, annual interest/12) then telescoping the
    expression from one month to the next for n payments would give you

                (1+a)^n
	q = a ----------- p
              (1+a)^n - 1

    to make the final payment finish off the loan.

    So, if you had a 10 year loan with a 6 percent APR, you'd have
    a monthly payment of 11.102050 per thousand dollars, I don't
    know what the policy is for rounding off though.

    - Jim
1836.6POLAR::MOKHTARWed Feb 02 1994 00:565
    
    
    Thanks v much.
    
    mm
1836.7Up.CADSYS::COOPERTopher CooperWed Feb 02 1994 14:0511
RE: .5 (Jim)

>    So, if you had a 10 year loan with a 6 percent APR, you'd have
>    a monthly payment of 11.102050 per thousand dollars, I don't
>    know what the policy is for rounding off though.

    I checked that particular example against a loan amatorization (sp?)
    table and it gave a monthly payment of $11.11 -- i.e., the policy is
    to "round up."

				Topher
1836.8AUSSIE::GARSONHotel Garson: No VacanciesThu Feb 03 1994 00:166
    re .7
    
    ...ignoring rounding in the interest calculation itself (which was not
    accounted for in the previous)
    
    P.S. sp: amortization
1836.9more formulasOUTSRC::HEISERwatchman on the wallWed Feb 28 1996 19:0213
    Here's some more formulas if anyone is interested:
    
    Total Interest for Life of loan = 
    	Period * (Monthly Payment + Extra Payment) - Beginning Principal
    
    Monthly Interest = Balance * Interest Rate
    
    Monthly Principal = (Monthly Payment + Extra Payment) - Monthly Interest
    
    Period = absolute value of ln(1-Principal*(i/Payment)) / ln(1+i)
    
    regards,
    Mike