Loan Amortization

May 12, 2009

My daughter, a freshman in high school, is just completing her first programming class, using Java. Her final assignment was to write a program to print a loan amortization table, given an initial balance, annual interest rate, term in months, and monthly payment.

Your task is to write that program (you are not restricted to Java), then print the amortization table for a three-year car loan of $10,000 at 7% (it’s an old textbook). When you are finished, you are welcome to read a suggested solution, or to post your solution or discuss the exercise in the comments below.

About these ads

Pages: 1 2

5 Responses to “Loan Amortization”

  1. [...] Praxis – Loan Amortization By Remco Niemeijer Today’s Programming Praxis problem is about loan amortization. For those of you who, like me, had no idea [...]

  2. Remco Niemeijer said

    My Haskell solution (see http://bonsaicode.wordpress.com/2009/05/12/programming-praxis-loan-amortization/ for a version with comments):

    import Text.Printf
    
    amortize :: Float -> Float -> Int -> [(Int, Float, Float, Float)]
    amortize _ _ 0 = []
    amortize b r l = (l - 1, prn, int, b') : amortize b' r (l - 1)
                     where int = b * r
                           prn = int / (1 - (1 + r) ^^ (-l)) - int
                           b' = b - prn
    
    amortization :: Float -> Float -> Int -> IO ()
    amortization b r l = do
        putStrLn "Left Principal Interest   Balance"
        mapM_ table $ (l, 0, 0, b) : amortize b (r / 12 / 100) l
        where table (m, p, i, t) = printf "%4d %9.2f %8.2f %9.2f\n" m p i t
    
    main :: IO ()
    main = amortization 10000 7 36
    
  3. grettke said

    A Solution in PLT Scheme.

    This is the first Scheme program I had ever wrote; and its present form is the result of many kind folks helping me out :)

    #lang scheme
    
    (define mamort
     (lambda (bal pcnt pay)
       (format "Payment #,Payment Amount,Interest Paid,Principle
    Paid,Balance,Total Interest~%")
       (amort bal pcnt pay 12)))
    
    (define amort
     (lambda (bal pcnt pay freq)
       (let loop ((bal bal) (tot-int 0) (pmt 1))
         (let* ((int (* pcnt bal (/ freq)))
                (prin (min (- pay int) bal))
                (new-bal (- bal prin))
                (new-int (+ int tot-int))
                (done (< (+ int prin) pay)))
           (if done
               (printf "~s,~s,~s,~s,~s,~s~n"
                       pmt (+ int prin) int prin new-bal new-int)
               (begin
                 (printf "~s,~s,~s,~s,~s,~s~n"
                         pmt pay int prin new-bal new-int)
                 (loop new-bal new-int (+ 1 pmt))))))))
    
    (mamort 10000 .12 350)
    
  4. Kathryn Bewig said

    This is my favorite posting yet, Dad. :)

  5. Hi there, I discovered your web site via Google while searching for a similar subject, your website got here up, it looks good.
    I have bookmarked it in my google bookmarks.
    Hello there, just became alert to your weblog through Google, and found that it’s truly informative.
    I’m going to be careful for brussels. I’ll be grateful for those who proceed this in future.
    Many people will be benefited out of your writing. Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 577 other followers

%d bloggers like this: