Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Calculate Mortgage Payment

by true (Pilgrim)
on Dec 13, 2005 at 21:18 UTC ( [id://516433]=CUFP: print w/replies, xml ) Need Help??

Here's a little diddy i wrote last night to calculate a mortgage payment. You can see the script in it's full glory on my Mortgage Calulator.
my %IN; $IN{'AMOUNT'} = 100000;#as in $100,000 loan $IN{'RATE'} = 6;##as in 6% interest $IN{'YEARS'} = 30;## 30 years or 15 years etc my $payment = &ComputePayment(%IN); sub ComputePayment{ my %LOAN = @_; my $years = $LOAN{'YEARS'}; my $interest = $LOAN{'RATE'}; my $principle = $LOAN{'AMOUNT'}; my $ttlmonths = $years*12; my $iv = $interest/1200; my $tmp = (1 + $iv) ** -$ttlmonths; my $payment = 0; if ($tmp < 1){ $payment = ($principle * $iv) / (1 - $tmp); }else{ $payment = $principle / $ttlmonths; } return sprintf("%10.2f",$payment); }########end SubRoutine

Replies are listed 'Best First'.
Re: Calculate Mortgage Payment
by Happy-the-monk (Canon) on Dec 14, 2005 at 10:43 UTC

    The Mortgage Calculator dies with internal server error if you leave the "Years" field empty. You might want to do some error processing there.

    Alternatively, the way I think about paying mortgages I say I want to pay a monthly amount X, for how many years and months will I have to pay it off?
    You could offer that as an alternative, too.

    Cheers, Sören

      And, just for enjoy, another quests are
      - calculate remaining payments when some payments are fixed (in time and in value, too)
      - calculate interest rate when all but non-equal payments are known, specially, when price is split into more than one payment... a little bit tricky, more than one interest rate can be the solution :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://516433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found