Link to home
Start Free TrialLog in
Avatar of perkley
perkley

asked on

Anybody know of financial code?

I am in need of some code that will give me the Interest Rate.

All I have is the Present Value, Payment Amount, Term of payments, and I need to know how to program Delphi to get the Interest Rate.  I am in need of other financial stuff like this also, so if you have any source code that you know of, I would be happy to see it.
Avatar of simonet
simonet
Flag of Brazil image

Math.pas (or math.dcu) has all this.

Alex
Avatar of perkley
perkley

ASKER

Great, I am happy to see that the math.pas has these functions.  However, it does not seem to work.  I am trying the following in Delphi 5 Professional.

procedure TForm1.Button1Click(Sender: TObject);
var
    IntRate: Extended;
begin
    IntRate := InterestRate(60,956,43225,57360,ptEndOfPeriod);
    Label1.Caption := FloatToStr(IntRate);
end;

I get this error:  Why?

EInvalidArgument with message "InterestRate".
Have you added the Math unit to the uses clause of the unit that calls it?

Alex
Avatar of perkley

ASKER

Yes, it compiles fine, it just won't run fine.  It says in the help file that this error mainly comes from the financial functions because it has data that it cannot calculate.  Well, I have tried all sorts of easy ones, and nothing seems to work.  Am I writing it wrong?
I found out what the error is:

Delphi uses the direct application of the formula, which gives different signs on PV and FV. Thus, the code below compiles and runs fine:

procedure TForm1.Button1Click(Sender: TObject);
var
    IntRate: Extended;
begin
    IntRate := InterestRate(60,956,-43225,57360,ptEndOfPeriod);
    Label1.Caption := FloatToStr(IntRate);
end;

Note that PV must be -43225, not 43225.

I checked the returned value 2.45595% against the financial functions of my HP48G and the values match.

Yours,

Alex
Avatar of perkley

ASKER

I will accept your comment if I get what I want, but this is my problem.  I have these variables:

Term: 60 months
Original Loan: $43,225
Payments: $956

I need to be getting a value of 11.75 as the Interest Rate, at least that is what this Financial Calculator (HP12C) is getting.  How can I get that?
Avatar of perkley

ASKER

How I came up with the $57,360 from this:

$956 x 60 = $57,360 - I am just guessing that this is the Future Value.  Am I wrong?
ASKER CERTIFIED SOLUTION
Avatar of simonet
simonet
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of perkley

ASKER

Comment accepted as answer
Avatar of perkley

ASKER

Thank you very much.  I have never been very good at finacial stuff, and all of this was just giving me a headache.
No problem. Thank you.

Alex