Jump to content
Sign in to follow this  
B3EAST

Loan amortization

Recommended Posts

B3EAST

I need some help with this and it is driving me crazy. I know there are probably about 50 different ways to make this but i really would like this way to work. When it is ran it starts out with 208.82 for the Interest paid and it should be 208.81 so it throws all the calculations off and it ends up giving a -4.06 balance at the end.

If someone would please take a look and see if i have done something completely wrong or if the rounding needs to be done in a specific spot. I have tried just about everything i can think of.

Thanks for any help

B

;Found formula here http://www.hughchou.org/calc/formula.html

$TA = 200000  ;Total loan amount
$I = 5.75     ;Interest percent
$L = 30      ;Length in years

$N = $L*12          ;chages length from years to months
$J = $I/(12*100)    ;Changes interest to decimal
;MsgBox(0,"",$J)
$M = $TA * ( $J / ( 1 - (( 1 + $J ) ^ -$N)))
;MsgBox(0,"",$M)

For $s = $N to 1 Step -1        ;tells total number of payments based on length $L
$IP = Round($TA * $J, 2)        ;Interest paid
$PP = Round($M - $IP, 2)        ;Principal Paid
$RB = Round($TA - $PP, 2)       ;Remaining Balance
FileWrite("test.txt", $PP & "   |   " & $IP & " |   " & $RB & @CRLF)
 $TA = $RB                      ;Sets original loan amount to RB for next calculation
Next

Share this post


Link to post
Share on other sites
JohnOne

$TA = 200000  ;Total loan amount
$I = 5.75     ;Interest percent
$L = 30      ;Length in years

$N = $L*12          ;chages length from years to months
$J = $I/(12*100)    ;Changes interest to decimal
;MsgBox(0,"",$J)
$M = $TA * ( $J / ( 1 - (( 1 + $J ) ^ -$N)))
;MsgBox(0,"",$M)

For $s = $N to 1 Step -1        ;tells total number of payments based on length $L
$IP = ($TA * $J)        ;Interest paid
$PP = Round($M - $IP, 2)        ;Principal Paid
$RB = Round($TA - $PP, 2)       ;Remaining Balance
FileWrite("test.txt", $PP & "   |   " & $IP & " |   " & $RB & @CRLF)
 $TA = $RB                      ;Sets original loan amount to RB for next calculation
Next


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
B3EAST

$TA = 200000  ;Total loan amount
$I = 5.75     ;Interest percent
$L = 30      ;Length in years

$N = $L*12          ;chages length from years to months
$J = $I/(12*100)    ;Changes interest to decimal
;MsgBox(0,"",$J)
$M = $TA * ( $J / ( 1 - (( 1 + $J ) ^ -$N)))
;MsgBox(0,"",$M)

For $s = $N to 1 Step -1        ;tells total number of payments based on length $L
$IP = ($TA * $J)        ;Interest paid
$PP = Round($M - $IP, 2)        ;Principal Paid
$RB = Round($TA - $PP, 2)       ;Remaining Balance
FileWrite("test.txt", $PP & "   |   " & $IP & " |   " & $RB & @CRLF)
 $TA = $RB                      ;Sets original loan amount to RB for next calculation
Next

So is there a way to make the interest rate round out when it writes to a file without messing up the final result? Was hoping there was a opt that made all the numbers go 2 decimal places but no such thing.

Share this post


Link to post
Share on other sites
AdmiralAlkex

So is there a way to make the interest rate round out when it writes to a file without messing up the final result? Was hoping there was a opt that made all the numbers go 2 decimal places but no such thing.

You answered your own question there. Use Round().

Share this post


Link to post
Share on other sites
B3EAST

You answered your own question there. Use Round().

But did you see what the first post did it comes out with a -4.06 instead of 0.00 so you cant round it out without getting a bogus answer. That is why i was asking if there is a way around it. I guess you will have to take the number and round it after the calculation is performed to get it to work and give the correct balance of 0.00

I would really like it to round out to the 2 decimal place on everything but it just appears it si not going to happen in autoit unless im missing something...

Share this post


Link to post
Share on other sites
B3EAST

Use Round() in the FileWrite, not in the calculation :)

Thanks man i have just being tearing my hair out working on this and was about ready to throw a monitor or keyboard out the window for fun :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.