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   20506 use strict;
  1         2  
  1         28  
2 1     1   3 use warnings;
  1         1  
  1         41  
3             package Algorithm::Kelly;
4             $Algorithm::Kelly::VERSION = '0.02';
5             # ABSTRACT: calculates the fraction of of your bankroll to bet using the Kelly formula
6              
7             BEGIN
8             {
9 1     1   7 require Exporter;
10 1     1   4 use base 'Exporter';
  1         4  
  1         79  
11 1         68 our @EXPORT = 'optimal_f';
12             }
13              
14              
15              
16             sub optimal_f
17             {
18 9     9 1 1704 my ($probability, $payoff) = @_;
19              
20 9 100 100     65 unless (defined $probability
      100        
      100        
      100        
21             && $probability >= 0
22             && $probability <= 1
23             && $payoff
24             && $payoff > 0)
25             {
26 6         25 die "optimal_f() requires 2 args: probability (0-1) and payoff\n";
27             }
28              
29 3         13 ($probability * $payoff - (1 - $probability)) / $payoff;
30             }
31              
32             1;
33              
34             __END__