Math::Financial - Calculates figures relating to loans and annuities.
$calc = new Math::Financial(fv => 100000, pv => 1000); $calc->set->(pmt => 500, ir => 8);
$calc->compound_interest(find => 'fv');
This package contains solves mathematical problems relating to loans and annuities.
The attributes that are used in the equations may be set on a per-object basis, allowing you to run a set of different calculations using the same numbers, or they may be fed directly to the methods.
The attribute types,
accessed through the
set methods are
Attributes are case-insensitive. The documentation for the individual methods indicates which attributes must be set for those methods.
Calculations are based either on the attributes set with the
or with arguments fed directly to the methods.
This seemed like the least confusing way to make the interface flexible for people who are using the module in different ways.
Also, performing a calculation does not update the attribute of the solution. In other words, if you solve an equation that returns fv, the solution is returned but the internal fv field is unaffected.
Any attempted calculation which cannot be completed -- due to either missing or invalid attributes -- will return
I am interested to hear from people using this module -- let me know what you think about the interface and how it can be improved.
$calc = new Math::Financial();
$calc = new Math::Financial(pv => 10000,
ir => 5,
np = 12)>
See above for a description of the available attributes.
You do not have to set attributes here,
you can also do so using
or feed attributes directly to the methods.
There are no default values for any of the attributes except
TPY (Terms Per Year),
which is 12 by default,
PD which defaults to zero.
If you don't want to use the object-oriented interface, see the EXPORTS section below.
$calc->set(fv => 100000,
pmt => 500)
You can set any of the stored attributes using this method, which is is also called by <new>. Returns the number of attributes set.
$calc->get(field = 'ir')>
$calc->get([qw(ir pmt pv)])
You can get one or several attributes using this method. In the multiple attribute formats, it accepts either a list or a list reference as input.
In single attribute context, returns a scalar. In multiple attribute context, it returns a list or a reference to a list, depending on the calling context.
$calc->compound_interest->(find => 'fv')
Calculates compund interest for an annuity. With any 3 of pv, fv, np, and ir, you can always solve the fourth.
Without arguments, the method will attempt to figure out what you'd like to solve based on what attributes of the object are defined. Usually, you'll probably want to explicitly request what attribute you'd like returned, which you can do using the second or third method.
$calc->funding_annuity->(pmt => 2000,
ir => 6.50,
np => 40,
tpy = 4)>
funding_annuity calculates how much money (
fv ) you will have at the end of
np periods if you deposit
pmt into the account each period and the account earns
ir interest per year.
You may want to set the
tpy attribute here to something other than 12,
while loans usually compound monthly,
annuities rarely do.
$calc->loan_balance->(pmt => 2000,
ir => 6.50,
np => 360,
pd => 12)
loan_balance calculates the balance on a loan that is being made in
np equal payments,
pd payments have already been made.
You can also use this method to determine the amount of money left in an annuity that you are drawing down.
Return the payment amount, per period, of a loan. This is also known as amortizing. The ir, np, and pv fields must be set.
$calc->loan_size->(pmt => 2000,
ir => 6.50,
np => 360)
loan_size calculates the size of loan you can get based on the monthly payment you can afford.
Return the number of payments (term) of a loan given the interest rate
pmt and loan amount
and pv fields must be set.
$calc->simple_interest->(find => 'ir')
This works just like compound interest,
but there is no consideration of
With any 2 of pv,
you can always solve for the third.
Without arguments, the method will attempt to figure out what you'd like to solve based on what attributes of the object have been defined. Usually, you'll probably want to explicitly request what attribute you'd like returned, which you can do using the second or third method.
POSIX -- c_type functions
(c_types might work under Windows. I really don't know. I'd appreciate it if someome would let me know. If they don't, in a future release, I'll provide a runtime replacement for the POSIX functions so it'll work on Win releases. )
By default, nothing.
If you'd like to use a procedural interface,
use Math::Financial qw(:standard).
Then you can call the methods as function, without an object reference, like
$term = loan_term(ir => 6.5,
pmt => 1000,
pv => 200000);
All of the methods are exported in this fashion,
get; this just seemed too confusing.
You can still use the facility of
get with the procedural interface (i.e.,
you can set the attributes and them use them for many different calculations),
but you must call them as
Eric Fixler <firstname.lastname@example.org>, 1999
Add more equations! Send me equations and I'll put them in.
whose Financial Formulas Page
http://ourworld.compuserve.com/homepages/Larry_Freeman/finance.htm was essential for this project.