From user-return-21639-apmail-commons-user-archive=commons.apache.org@commons.apache.org Sat Aug 16 23:20:38 2008
Return-Path:
Delivered-To: apmail-commons-user-archive@www.apache.org
Received: (qmail 73308 invoked from network); 16 Aug 2008 23:20:37 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
by minotaur.apache.org with SMTP; 16 Aug 2008 23:20:37 -0000
Received: (qmail 47494 invoked by uid 500); 16 Aug 2008 23:20:32 -0000
Delivered-To: apmail-commons-user-archive@commons.apache.org
Received: (qmail 47425 invoked by uid 500); 16 Aug 2008 23:20:32 -0000
Mailing-List: contact user-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: "Commons Users List"
Delivered-To: mailing list user@commons.apache.org
Received: (qmail 47413 invoked by uid 99); 16 Aug 2008 23:20:32 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Aug 2008 16:20:32 -0700
X-ASF-Spam-Status: No, hits=0.0 required=10.0
tests=
X-Spam-Check-By: apache.org
Received-SPF: unknown (athena.apache.org: error in processing during lookup of david.hoffer@issinc.com)
Received: from [208.70.128.104] (HELO smtp-gw78.mailanyone.net) (208.70.128.104)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Aug 2008 23:19:35 +0000
Received: from mailanyone.net
by smtp-gw78.mailanyone.net with esmtpa (MailAnyone extSMTP david.hoffer@issinc.com)
id 1KUV22-0002kd-HR
for user@commons.apache.org; Sat, 16 Aug 2008 18:18:02 -0500
From: "David Hoffer"
To: "'Commons Users List'"
References: <000201c8ffdc$2f0abce0$4100a8c0@issinc.com> <48A73C68.4030906@free.fr> <000301c8ffe3$e4a53330$4100a8c0@issinc.com> <48A74936.7060206@coyotesong.com> <000401c8ffea$76794bb0$4100a8c0@issinc.com> <48A75139.7010809@free.fr>
Subject: RE: commons-math usage to calculate APR?
Date: Sat, 16 Aug 2008 17:17:58 -0600
Message-ID: <000601c8fff6$52d64170$4100a8c0@issinc.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Office Outlook 11
Thread-Index: Acj/7YfBxi9jSteBTZGD4tO49zGVzgABz7rg
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
In-Reply-To: <48A75139.7010809@free.fr>
X-Virus-Checked: Checked by ClamAV on apache.org
Well I am getting close with your suggestions. =20
It seems to be calculating values just a little low. Perhaps my formula =
is
not quite right. Just to be clear, why did you drop the denominator?=20
As an example of current results, if the output should be 5% and then =
get
higher as loanExpenses goes up, it is calculating about 4.7% and then =
gets
higher as loanExpenses go up (but it stays low).
-Dave=20
-----Original Message-----
From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr]=20
Sent: Saturday, August 16, 2008 4:14 PM
To: Commons Users List
Subject: Re: commons-math usage to calculate APR?
David Hoffer a =E9crit :
> Hum, simple I'm sure but perhaps calculating APR is not quite that =
simple;
> you have to factor in loan expenses (that's why APR is not the same as
> interest rate).
>=20
> I think it is something like:
>=20
> P' =3D (P+E)I(1+i)^n/(1+i)^n
>=20
> Then you solve for APR with the non-linear function which is something
like:
>=20
> ((a(1+a)^n)-(P'/P))/((1+a)^n-1) =3D 0
>=20
> Where a=3DARR/12
In order to solve this, you can first drop the denominator (which is non
null if a is non null). You end up with:
a(1+a)^n - P'/P =3D 0
Solving this using for any commons-math solver (for example BrentSolver)
could probably be done as follows:
final double p =3D ...;
final double pPrime =3D ...;
final int n =3D ...;
UnivariateRealFunction equation =3D new UnivariateRealFunction() {
public double value(double x) {
return x * Math.pow(1 + x, n) - pPrime / p;
}
};
UnivariateRealSolver solver =3D new BrentSolver(equation);
double apr =3D solver.solve(0.001, 0.999);
Using final variables for p, pPrime and n allow to refer to them
directly in the anonymous class defined by the new
UnivariateRealFunction call. If you prefer a more elegant solution, you
can create a dedicated class implementing the UnivariateRealFunction and
that would use private fields to hold these values.
Luc
>=20
> Calculating P' is straightforward. Solving for a is where I'm not =
clear,
> plus I'm not certain of the math above.=20
>=20
> -Dave
>=20
> -----Original Message-----
> From: Bear Giles [mailto:bgiles@coyotesong.com]=20
> Sent: Saturday, August 16, 2008 3:40 PM
> To: Commons Users List
> Subject: Re: commons-math usage to calculate APR?
>=20
> There are closed-form expressions for that, although I don't have them =
> off the top of my head. Something like
>=20
> m =3D P / (1 - i)^n
>=20
> or maybe
>=20
> m =3D P / ((1 + i)^n - 1)
>=20
> where m is monthly payment, P is principal, i is monthly interest, n =
is=20
> number of months. It's definitely not very complex for a simple=20
> fixed-term, fixed-rate loan.
>=20
> Bear
>=20
> David Hoffer wrote:
>> My usage is for USA only at this point. =20
>>
>> I have inputs of loanAmount, monthlyInterestRate, numberMonths, =
loanFees;
> so
>> this would be for fixed monthly payments. =20
>>
>> I understand that commons-math doesn't have specific finance methods
> however
>> I think the APR formula is a non-linear equation that I was hoping
>> commons-math could help solve.
>>
>> -Dave
>>
>> -----Original Message-----
>> From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr]=20
>> Sent: Saturday, August 16, 2008 2:45 PM
>> To: Commons Users List
>> Subject: Re: commons-math usage to calculate APR?
>>
>> David Hoffer a =E9crit :
>> =20
>>> Can anyone point me to an example of how to use commons-math to
calculate
>>> APR (Annual Percentage Rate)? =20
>>> =20
>> There are no specific finance related algorithm in commons-math.
>>
>> =20
>>> I think this is solvable using either the NewtonSolver or
BisectionSolver
>>> but I am not sure how to accomplish this. Perhaps a different way =
is
>>> better. =20
>>> =20
>> I think so, but it depends on what you really need. APR computation
>> seems to be slightly different depending on local regulations (for
>> example USA or EU). It also depends on the assumptions you do and the
>> input data. For example you can compute it one way for fixed monthly
>> payments and another way for varying monthly payments.
>>
>> =20
>>> Any help would be greatly appreciated.
>>> =20
>> Could you explain your needs more precisely ?
>>
>> Luc
>> =20
>=20
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>=20
>=20
>=20
>=20
>=20
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>=20
>=20
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org