Business-US_Amort
view release on metacpan or search on metacpan
lib/Business/US_Amort.pm view on Meta::CPAN
# now
return 1;
}
#===========================================================================
=item $loan->dump_table
This method dumps a few fields selected from snapshots in the C<table>
of the given object. It's here more as example code than as anything
particularly useful. See the source. You should be able to use this
as a basis for making code of your own that dumps relevant fields from
the contents of snapshots of loan objects.
=cut
sub dump_table {
my $this = $_[0];
return unless ref $this->{'table'}; # no table!
foreach my $line (@{$this->{'table'}}) {
# iterate over snapshots
printf
"%s (#% 4d) | % 12.2f || % 10.2f | % 10.2f || % 12.2f\n",
map($line->{$_},
'_date',
'_month_count',
'_old_amount',
'_h',
'_c',
'_remainder'
)
;
}
return;
}
#===========================================================================
=back
=head1 REMEMBER
When in panic or in doubt, run in circles, scream and shout.
Or read the source. I really suggest the latter, actually.
=head1 WARNINGS
* There's little or no sanity checking in this class. If you want
to amortize a loan for $2 at 1% interest over ten million years,
this class won't stop you.
* Perl is liable to produce tiny math errors, like just about any
other language that does its math in binary but has to convert to and
from decimal for purposes of human interaction. I've seen this
surface as tiny discrepancies in loan calculations -- "tiny" as in
less than $1 for even multi-million-dollar loans amortized over
decades.
* Moreover, oddities may creep in because of round-off errors. This
seems to result from the fact that the formula that takes term,
interest rate, and principal, and returns the monthly payment, doesn't
know that a real-world monthly payment of "$1020.309" is impossible --
and so that ninth of a cent difference can add up across the months.
At worst, this may cause a 30-year-loan loan coming to term in 30
years and 1 month, with the last payment being needed to pay off a
balance of two dollars, or the like.
These errors have never been a problem for any purpose I've
put this class to, but be on the look out.
=head1 DISCLAIMER
This program is distributed in the hope that it will be useful,
but B<without any warranty>; without even the implied warranty of
B<merchantability> or B<fitness for a particular purpose>.
But let me know if it gives you any problems, OK?
=head1 COPYRIGHT
Copyright 1999-2002, Sean M. Burke C<sburke@cpan.org>, all rights
reserved. This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.
=head1 AUTHOR
Sean M. Burke C<sburke@cpan.org>
=cut
# stuff...
sub __date_now {
my $now;
$now = @ARGV ? $_[0] : $^T;
my($m, $y) = (localtime($now))[4,5];
return sprintf("%04d-%02d", $y + 1900, $m + 1);
}
#===========================================================================
sub __inc_date {
my $in_date = $_[0];
my($year, $month);
return "2000-01" unless $in_date =~ /^(\d\d\d\d)-(\d\d)/s;
($year, $month) = ($1, $2);
if(++$month > 12) {
$month = 1;
$year++;
}
return sprintf("%04d-%02d", $year, $month);
}
#===========================================================================
1;
__END__
( run in 0.887 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )