From user-return-21641-apmail-commons-user-archive=commons.apache.org@commons.apache.org Sun Aug 17 00:11:12 2008
Return-Path:
Delivered-To: apmail-commons-user-archive@www.apache.org
Received: (qmail 2127 invoked from network); 17 Aug 2008 00:11:12 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
by minotaur.apache.org with SMTP; 17 Aug 2008 00:11:12 -0000
Received: (qmail 64104 invoked by uid 500); 17 Aug 2008 00:11:07 -0000
Delivered-To: apmail-commons-user-archive@commons.apache.org
Received: (qmail 64025 invoked by uid 500); 17 Aug 2008 00:11:07 -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 64014 invoked by uid 99); 17 Aug 2008 00:11:07 -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 17:11:07 -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; Sun, 17 Aug 2008 00:10:11 +0000
Received: from mailanyone.net
by smtp-gw78.mailanyone.net with esmtpa (MailAnyone extSMTP david.hoffer@issinc.com)
id 1KUVqw-00031g-Ch
for user@commons.apache.org; Sat, 16 Aug 2008 19:10:39 -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> <000601c8fff6$52d64170$4100a8c0@issinc.com> <48A76367.7000802@free.fr>
Subject: RE: commons-math usage to calculate APR?
Date: Sat, 16 Aug 2008 18:10:34 -0600
Message-ID: <000801c8fffd$abcd0cd0$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/+Fhk7KLaTKYJRci5e6/zt1HnyAABQ2bQ
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
In-Reply-To: <48A76367.7000802@free.fr>
X-Virus-Checked: Checked by ClamAV on apache.org
My mistake; I had the formula wrong, the part I thought was in the
denominator actually divides one of the other factors. The right =
formula
is:
(x * Math.pow(1 + x, numMonths))/((Math.pow(1 + x, numMonths) - 1)) -
(pPrime / loanAmount);
Thanks for your help, it works great!
-Dave
-----Original Message-----
From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr]=20
Sent: Saturday, August 16, 2008 5:32 PM
To: Commons Users List
Subject: Re: commons-math usage to calculate APR?
David Hoffer a =E9crit :
> Well I am getting close with your suggestions. =20
>=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
Only for the sake of solving the equation.
Solving A/B =3D 0 or solving A =3D 0 leads to the same result.
>=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).
You can check that the computed value really solves the equation by
printing f(apr).
If it is not almost zero, it means the convergence settings are too
loose. Look at the convergence threshold, or max number of iterations.
The javadoc for BrentSolver explains the different settings you can =
change.
If the result is almost zero, it means the initial equation does not
compute what you want.
Luc
>=20
> -Dave=20
>=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?
>=20
> 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).
>>
>> I think it is something like:
>>
>> P' =3D (P+E)I(1+i)^n/(1+i)^n
>>
>> Then you solve for APR with the non-linear function which is =
something
> like:
>> ((a(1+a)^n)-(P'/P))/((1+a)^n-1) =3D 0
>>
>> Where a=3DARR/12
>=20
> In order to solve this, you can first drop the denominator (which is =
non
> null if a is non null). You end up with:
>=20
> a(1+a)^n - P'/P =3D 0
>=20
>=20
> Solving this using for any commons-math solver (for example =
BrentSolver)
> could probably be done as follows:
>=20
> 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);
>=20
> 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.
>=20
>=20
> 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
>>
>> -Dave
>>
>> -----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?
>>
>> There are closed-form expressions for that, although I don't have =
them=20
>> off the top of my head. Something like
>>
>> m =3D P / (1 - i)^n
>>
>> or maybe
>>
>> m =3D P / ((1 + i)^n - 1)
>>
>> 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.
>>
>> Bear
>>
>> 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
>> ---------------------------------------------------------------------
>> 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
>>
>>
>=20
>=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
---------------------------------------------------------------------
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