File Coverage

lib/Spreadsheet/Engine/Function/PV.pm
Criterion Covered Total %
statement 15 15 100.0
branch 3 6 50.0
condition 1 2 50.0
subroutine 4 4 100.0
pod 1 1 100.0
total 24 28 85.7


line stmt bran cond sub pod time code
1             package Spreadsheet::Engine::Function::PV;
2              
3 28     28   155 use strict;
  28         55  
  28         969  
4 28     28   146 use warnings;
  28         54  
  28         752  
5              
6 28     28   183 use base 'Spreadsheet::Engine::Fn::investment';
  28         47  
  28         7726  
7              
8             sub calculate {
9 11     11 1 528 my ($self, $rate, $n, $payment, $fv, $type) = @_;
10 11   50     43 $fv ||= 0;
11 11 50       30 $type = $type ? 1 : 0;
12              
13 11 50       31 die Spreadsheet::Engine::Error->div0 if $rate == -1;
14 11 50       35 return -$fv - ($payment * $n) if $rate == 0;
15             return (
16 11         343 -$fv - $payment * (1 + $rate * $type) * ((1 + $rate)**$n - 1) / $rate) /
17             ((1 + $rate)**$n);
18             }
19              
20             1;
21              
22             __END__