File Coverage

blib/lib/Algorithm/Kelly.pm
Criterion Covered Total %
statement 15 15 100.0
branch 2 2 100.0
condition 12 12 100.0
subroutine 5 5 100.0
pod 1 1 100.0
total 35 35 100.0


line stmt bran cond sub pod time code
1 1     1   24219 use strict;
  1         1  
  1         37  
2 1     1   5 use warnings;
  1         1  
  1         60  
3             package Algorithm::Kelly;
4             $Algorithm::Kelly::VERSION = '0.01';
5             # ABSTRACT: calculates the fraction of of your bankroll to bet using the Kelly formula
6              
7             BEGIN
8             {
9 1     1   5 require Exporter;
10 1     1   6 use base 'Exporter';
  1         5  
  1         110  
11 1         100 our @EXPORT = 'optimal_f';
12             }
13              
14              
15              
16             sub optimal_f
17             {
18 9     9 1 1698 my ($probability, $payoff) = @_;
19              
20 9 100 100     77 unless (defined $probability
      100        
      100        
      100        
21             && $probability >= 0
22             && $probability <= 1
23             && $payoff
24             && $payoff > 0)
25             {
26 6         33 die "optimal_f() requires 2 args: probability (0-1) and payoff\n";
27             }
28              
29 3         18 ($probability * $payoff - (1 - $probability)) / $payoff;
30             }
31              
32             1;
33              
34             __END__