Introduction
I know, this is probably not very exciting stuff, but may turn useful
for some of you one day� Maybe for calculating your car / house repayments, or
maybe writing a program that needs to calculate this.
The basis for this set of function is derived from the Microsoft Excel
formula documentation on the subject and with lots of help of our own in house
�Math teacher� (thanks Andrew) we managed to put this together for the
benefit of the community and as our humble contribution to the forum.
Firstly � here is the Excel formula in its raw format

Now to some relevant terminology�
A �loan� is made up of several elements, each playing a different role in
the equation. At times, you may need to know different things about the loan;
therefore I provided here several functions.
| NPV |
or Net Present Value, this is the amount of the loan |
| FV |
or Future Value (or sometime known as Residual, or �Pay-Out�) is
the amount of money that will still be outstanding as the final payment
AFTER all the payments are made. |
| NumPay |
Number of Payments / Installments, for example if a monthly payment is
made for a period of 5 years, this will equal 60. |
| IntRate |
Interest Rate, expressed as say 10.00 (for 10%) |
| bStart |
this should be a 0 or 1, if 0, each repayment is made at the end of
the period (end of month) otherwise, payments are made ahead of each
period. |
OK � enough of that blurb� here are the actual functions:
double MKCalcPayment(int NumPay, double IntRate, double NPV, double FV,
BOOL bStart)
{
IntRate /= 1200.00;
double P = (- NPV * pow(1+IntRate,NumPay) + FV) /
((1 + IntRate * bStart)*((pow((1 + IntRate),NumPay) - 1) /
IntRate));
return P * (-1);
}
double MKCalcInterest(double NumPay, double Payment, double NPV, double FV,
BOOL bStart)
{
double IntRate = 1.00 / 1200.00;
NPV *= (-1);
double iPer = log((Payment + Payment*IntRate*bStart - FV*IntRate) /
(NPV*IntRate + Payment + Payment*IntRate*bStart) ) /
log (1 + IntRate);
if (iPer > NumPay)
{
while (iPer > NumPay)
{
IntRate -= 0.000001;
iPer = log((Payment + Payment*IntRate*bStart - FV*IntRate) /
(NPV*IntRate + Payment + Payment*IntRate*bStart) ) /
log (1 + IntRate);
}
}
else
{
while (iPer < NumPay)
{
IntRate += 0.000001;
iPer = log((Payment + Payment*IntRate*bStart - FV*IntRate) /
(NPV*IntRate + Payment + Payment*IntRate*bStart) ) /
log (1 + IntRate);
}
}
return IntRate * 1200.00;
}
double MKCalcPeriods(double Payment, double IntRate, double NPV, double FV,
BOOL bStart)
{
IntRate /= 1200.00;
NPV *= (-1);
return log((Payment + Payment*IntRate*bStart - FV*IntRate) /
(NPV*IntRate + Payment + Payment*IntRate*bStart) ) /
log (1 + IntRate);
}
double MKCalcResidual(double Payment, int NumPay, double IntRate, double NPV,
BOOL bStart)
{
IntRate /= 1200.00;
return -Payment * ((1 + IntRate * bStart)*((pow((1 + IntRate),NumPay) - 1)
/ IntRate)) + (NPV * pow(1+IntRate,NumPay));
}
All of the above functions are arithmetic juggling of the original formula,
with the exception of the one named MKCalcInterest which does a bit
of �Guessing� as to what the Interest rate is for a set of given arguments.
If you read the Excel on line help you will see that there is no direct way of
finding the answer otherwise.
So now � lets look at some examples
- I want a loan of $25,000 for a 5-year period with monthly repayments and
an annual compound interest rate of 10% and ZERO residual at the end.
Calling the
MKCalcPayment function results in $531.18 per
month.
- If on the other end, I can afford to pay only $400.00 and on the same
amount I wish to borrow (at the same interest rate) how long will it take me
to repay this? Calling the
MKCalcPeriods shows that we now have
to pay 88.65 payments instead of 60�
- Well now � what if I want to stay with the 60 instalments, but I can
only afford that same $400.00 a month � there will obviously be some left
over (residual) � calling the
MKCalcResidual returns
this to be equal to $10,157.89. Well it seems you cant have it all � you
either pay more each month, or you pay for a longer period, or you are left
out with something to pay at the end�
- Finally, what if I want to find out � what will be the actual effective
/ compound annual interest rate on that same amount � if I borrow it for a
60 month period, pay $550.00 per month and call the
MKCalcInterest
function � the answer is 11.52% per annum� This means that you should be
paying less than 60 installments � otherwise you are paying too much. See
why by looking at the 1st example.
Well, I am just about done, you can play with more examples � paying ahead
or in arrears, with or without a residual etc..
Have fun
| You must Sign In to use this message board. |
|
|
 |
|
 |
I was looking for logic of Excel RATE function.your MKCalcInterest is going to save a lot of time for me. Nice helper functions.
Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
no equations given, when I used the established equations to cross check I get different result. No method to calculate NPV
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Because you have to divide the Annual Interest Rate by 12 to get the monthly/periodic interest rate, and then you have to divide that by 100 to get the actual decimal number...
Example: 12% / 12 = 1% periodic rate, and 1% / 100 = .01 (the actual decimal form which can be used for mathematical calculation -- or you could have just divided 12% by 1200 and skipped straight to the .01
In business, if two people always agree, one of them is unnecessary.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
i need to calculate monthly installment amount of a loan. This is employees housebuilding loan. and is appropiate only for employees. installment amount will be fixed. loan will be given with a fixed rate of interest. installment amount will only deduct from principal amount untill principal amount will zero. then installment amount will deduct from cumulative interest untill pricipal amount will be zero. no interest will calculated for the interest amount, interest is appropiate only for pricipal amount only.
How i can calculate it
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
Well, the code here is the basis for this kind of thing, you just have to use it in a WHILE loop to produce the series of payments until the balance is zero and the loan is amortized.
Cheers
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Which of these functions would help me know what part (dollary amount) of the payment when to interest and what part paid down the principle?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Rick
There are two possible answers here, one which is simple, the other one I don't know how to calculate it. Th simple one is
Take the same sample with the calculate monthly repayment of $531.18 Subtruct from it the principal part ($25,000 / 60 = $416.67) - you get $114.51 which on the simple way - the amount of interest.
BUT, in reality - the repayments cover at first mostly interest and over time the principal, I don't know how to calculate this.
I will be glad to know if you find out, let me know please
Cheers
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks... I've tried to find a simple explaination that I could convert to code a few years ago, with now luck. I did have some Basic code for the calculation, but it was for the old Comodore machines and I couldn't figure just what they were doing.
I may look again and see if I can do better this time... or maybe someone how know amortization will help us out on this thread.
Thanks again!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I think this is Java... does this help?
function calcPayment() { this.Payment = (this.Amount*((this.Rate/(this.Periods*100))/(1-(Math.pow(1+(this.Rate/(this.Periods*100)),((this.Term*this.Periods)*-1)))))) } function calcInterest() { this.Interest = ((this.Payment*(this.Term*this.Periods))-this.Amount) }
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
 | NPV  bruno leclerc | 23:47 11 Mar '03 |
|
|
 |
|
 |
Hi Bruno
You could probably do it, just twist the formula around - like I did wiith the rest of it, simple exercise.
Have fun Alex
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
 | :)  DanYELL | 17:01 11 Mar '03 |
|
 |
I like the article alot. Its not sexy, but useful.
Got any more related calculations hiding on your hard drive that you could share? Id honestly love to see it. Please let me know.
Sincerely, Danielle
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
 | Re: :)  Alex Evans | 16:44 12 Mar '03 |
|
 |
Hi Danielle
Thanks for the comment, sexy is for something else. Anyway - what other calculations do you have in mind?
What will you do with this one anyway - do you have a loan program?
Cheers Alex
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|