File Coverage

blib/lib/Finance/Loan/Private.pm
Criterion Covered Total %
statement 12 24 50.0
branch n/a
condition n/a
subroutine 4 6 66.6
pod 2 2 100.0
total 18 32 56.2


line stmt bran cond sub pod time code
1             package Finance::Loan::Private;
2              
3 2     2   40467 use warnings;
  2         9  
  2         76  
4 2     2   12 use strict;
  2         4  
  2         76  
5 2     2   10 use base qw(Exporter);
  2         7  
  2         230  
6 2     2   15614 use DateTime;
  2         719183  
  2         603  
7             our @EXPORT_OK=qw(premium sorter);
8              
9             =head1 NAME
10              
11             Finance::Loan::Private - Private loan under UK tax law.
12              
13             =head1 VERSION
14              
15             Version 0.01
16              
17             =cut
18              
19             our $VERSION = '0.01';
20              
21              
22             =head1 SYNOPSIS
23              
24             This script calculates the repayment schedule and tax deductions for a private loan under UK tax law.
25              
26             Perhaps a little code snippet.
27              
28             use Finance::Loan::Private;
29              
30             my $foo = Finance::Loan::Private->new();
31             ...
32              
33             =head1 EXPORT
34              
35             premium
36              
37             =head1 SUBROUTINES/METHODS
38              
39             =head2 premium($principal, $rate, $years)
40              
41             Calculates a conventional monthly mortgage premium. The calculated figure is slightly too high for our
42             purposes as it does not take account of the tax deductions.
43              
44             =over
45              
46             =item $principal
47              
48             The amount of the loan.
49              
50             =item $rate
51              
52             The interest rate as a percentage.
53              
54             =item $years
55              
56             The period of the loan in years
57              
58             =item Returns
59              
60             A monthly premium
61              
62             =back
63              
64             =cut
65              
66             sub premium {
67 0     0 1   my $principal= shift;
68 0           my $rate = shift;
69 0           my $years = shift;
70 0           my $periods = 12*$years;
71 0           my $r = $rate/1200.0;
72 0           my $logr1 = log($r+1.0);
73 0           my $mult = exp($periods*$logr1);
74 0           my $payment = $r*$mult*$principal/($mult-1);
75 0           return $payment;
76             }
77              
78              
79             =head2 sorter($list)
80              
81             Sorts a list of hashrefs each of which contains a 'date' key. The value of the date key is a
82             ISO8601 date in the form yyyy-mm-dd.
83             Used for sorting lists of advances on the loan, changes of tax rate etc.
84              
85             =over
86              
87             =item $list
88              
89             An arrayref of hashrefs. Each hashref must contain a 'date' key whose value is a ISO8601 date.
90              
91             =item Returns
92              
93             A list (not a list ref) of sorted hashref.
94              
95             =back
96              
97             =cut
98              
99             sub sorter {
100 0     0 1   my $list = shift;
101 0           return sort {($a->{date} cmp $b->{date});} @$list;
  0            
102             }
103              
104             =head1 AUTHOR
105              
106             Raphael Mankin, C<< >>
107              
108             =head1 BUGS
109              
110             Please report any bugs or feature requests to C, or through
111             the web interface at L. I will be notified, and then you'll
112             automatically be notified of progress on your bug as I make changes.
113              
114              
115              
116              
117             =head1 SUPPORT
118              
119             You can find documentation for this module with the perldoc command.
120              
121             perldoc Finance::Loan::Private
122              
123              
124             You can also look for information at:
125              
126             =over 4
127              
128             =item * RT: CPAN's request tracker
129              
130             L
131              
132             =item * AnnoCPAN: Annotated CPAN documentation
133              
134             L
135              
136             =item * CPAN Ratings
137              
138             L
139              
140             =item * Search CPAN
141              
142             L
143              
144             =back
145              
146              
147             =head1 ACKNOWLEDGEMENTS
148              
149              
150             =head1 LICENSE AND COPYRIGHT
151              
152             Copyright 2012 Raphael Mankin.
153              
154             This program is free software; you can redistribute it and/or modify it
155             under the terms of either: the GNU General Public License as published
156             by the Free Software Foundation; or the Artistic License.
157              
158             See http://dev.perl.org/licenses/ for more information.
159              
160              
161             =cut
162              
163             1; # End of Finance::Loan::Private