Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Annual percentage rate calculation

Status
Not open for further replies.

genoah

Programmer
Nov 1, 2001
24
0
0
US
Does anyone have the formula to calculate annual percentage rate in Delphi. I have looked eveywhere and can not seem to find it.

Thanks ahead of time.

 
What country are you from?

The reason I ask is that different countries have slightly different legal requirements with regard to the factors involved in the calculation.

I can provide the approved UK method.


Hope this helps.
 
Sorry i gave you a VB link. I used them times ago while developing a web page.
 
USA - I have that calculator downloaded already, but it is not quite what I need. The calculation is off. Does anyone have the actual mathmatical formula that you would use a pencil and a paper to figure out? Thanks for your help!
 
The calculation is off".

Perchance is this because you are using single, double, or real for your decimals and getting floating point errors?

Delphi is *NOT* the language suited to do any kind of accurate floating point math due to the lack of fixed point precision integer math in decimal types.

But it can be done, though:
1) Use currency types if you don't need any precision beyond 4 places.
2) You have to be really careful regarding your results. My tip in having done a program with a large amount of these calculations myself is to stick a "write" with the results of each calculation and step through each calculation with your pen and paper. Any discrepancy requires an adjustment, whether you have the math right or not.

You have a hard row ahead of you to get this done and get it right. The before mentioned program I did took about 100000% more effort than I figured it would going into it - actually I ended up writing an fixed point integer math routine to handle what I needed before I was able to tweak the program to work using native Delphi.

If it helps you, here's the Delphized version of the code necessary to calculate the monthly payment given the loan amount, APR, and periods in the loan (that should be step 1 anyhow):

Code:
function power(x, y: double): double;
  begin
    power := exp(y*ln(x));
  end;

apr := t/100/12;
loan_payment := loan_amount/((1-(1/power(1+apr,number_periods)))/apr);
 
Thanks, this will be a big help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top