line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spreadsheet::Engine::Function::RATE; |
2
|
|
|
|
|
|
|
|
3
|
28
|
|
|
28
|
|
154
|
use strict; |
|
28
|
|
|
|
|
63
|
|
|
28
|
|
|
|
|
902
|
|
4
|
28
|
|
|
28
|
|
142
|
use warnings; |
|
28
|
|
|
|
|
58
|
|
|
28
|
|
|
|
|
698
|
|
5
|
|
|
|
|
|
|
|
6
|
28
|
|
|
28
|
|
141
|
use base 'Spreadsheet::Engine::Fn::investment'; |
|
28
|
|
|
|
|
69
|
|
|
28
|
|
|
|
|
3404
|
|
7
|
|
|
|
|
|
|
|
8
|
28
|
|
|
28
|
|
6378
|
use Spreadsheet::Engine::Fn::Approximator 'iterate'; |
|
28
|
|
|
|
|
62
|
|
|
28
|
|
|
|
|
8643
|
|
9
|
|
|
|
|
|
|
|
10
|
45
|
|
|
45
|
1
|
166
|
sub argument_count { -3 => 6 } |
11
|
45
|
|
|
45
|
1
|
430
|
sub signature { 'n', 'n', 'n', 'n', 'n', 'n' } |
12
|
45
|
|
|
45
|
1
|
1679
|
sub result_type { Spreadsheet::Engine::Value->new(type => 'n%') } |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub calculate { |
15
|
45
|
|
|
45
|
1
|
1836
|
my ($self, $n, $payment, $pv, $fv, $paytype, $guess) = @_; |
16
|
45
|
|
100
|
|
|
190
|
$fv ||= 0; |
17
|
45
|
100
|
|
|
|
119
|
$paytype = $paytype ? 1 : 0; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $rate = iterate( |
20
|
|
|
|
|
|
|
max_iterations => 100, |
21
|
|
|
|
|
|
|
initial_guess => $guess || 0.1, |
22
|
|
|
|
|
|
|
function => sub { |
23
|
1392
|
|
|
1392
|
|
1732
|
my $rate = shift; |
24
|
1392
|
|
|
|
|
6741
|
return $fv + $pv * (1 + $rate)**$n + $payment * (1 + $rate * $paytype) * |
25
|
|
|
|
|
|
|
((1 + $rate)**$n - 1) / $rate; |
26
|
|
|
|
|
|
|
}, |
27
|
45
|
|
100
|
|
|
535
|
); |
28
|
45
|
100
|
|
|
|
361
|
die Spreadsheet::Engine::Error->num unless defined $rate; |
29
|
34
|
|
|
|
|
875
|
return $rate; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__END__ |