Skip to content

Commit

Permalink
add loan payoff calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
gknauth committed Aug 19, 2019
1 parent 65c9d70 commit e96f373
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions loan.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#lang racket

(provide compute-payment
compute-monthly-payment
compute-remaining-monthly-payment
compute-remaining-daily-payment)

(define (compute-payment initial-balance
annual-interest-rate
payments-per-year
total-number-of-payments)
(let ([i (/ (if (> annual-interest-rate 0)
annual-interest-rate
0.0000001)
payments-per-year)])
(/ (* i initial-balance)
(- 1 (expt (+ 1 i) (- total-number-of-payments))))))

(define (compute-monthly-payment initial-balance
annual-interest-rate
months-to-pay)
(compute-payment initial-balance annual-interest-rate 12 months-to-pay))

(define (compute-remaining-monthly-payment initial-balance
annual-interest-rate
months-to-pay
already-paid-this-month)
(- (compute-monthly-payment initial-balance
annual-interest-rate
months-to-pay)
already-paid-this-month))

(define average-days-in-month
(/ (+ 31 28.25 31 30 31 30 31 31 30 31 30 31) 12))

(define (compute-remaining-daily-payment initial-balance
annual-interest-rate
months-to-pay
already-paid-this-month)
(/ (compute-remaining-monthly-payment initial-balance
annual-interest-rate
months-to-pay
already-paid-this-month)
average-days-in-month))

0 comments on commit e96f373

Please sign in to comment.