mathmatical expressions evaluation
John Machin
sjmachin at lexicon.net
Wed Dec 22 16:01:15 EST 2004
Paul McGuire wrote:
> Here's
> a simple loan amortization schedule generator:
>
> def amortizationSchedule( principal, term, rate ):
> pmt = ( principal * rate * ( 1 + rate)**term ) / (( 1 +
rate)**term - 1)
Simpliciter:
pmt = principal * rate / (1 - (1 + rate)**(-term))
> pmt = round(pmt,2) # people rarely pay in fractional pennies
> remainingPrincipal = principal
> for pd in range(1,term+1):
> if pd < term:
> pdInterest = rate * remainingPrincipal
> pdInterest = round(pdInterest,2)
> pdPmt = pmt
> else:
Huh? You don't charge interest in the last period? I'd like to apply
for a loan of $1B for a term of one month with monthly repayments.
> pdInterest = 0
> pdPmt = remainingPrincipal
> pdPrincipal = pdPmt - pdInterest
> remainingPrincipal -= pdPrincipal
> yield pd, pdPmt, pdInterest, pdPrincipal, remainingPrincipal
>
More information about the Python-list
mailing list