GeniusTrader/Analyzers/BuyAndHold.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 43 CC 4 SCAR 22.2
CC
4
Cov
0%
calculate
20.0
initialize
2.0
BEGIN
2.0
CRAP 9.2
1 package Finance::GeniusTrader::Analyzers::BuyAndHold;
2  
3 # Copyright 2003 Oliver Bossert
4 # This file is distributed under the terms of the General Public License
5 # version 2 or (at your option) any later version.
6  
7 # Standards-Version: 1.0
8  
9 use strict;
10 use vars qw(@ISA @NAMES @DEFAULT_ARGS);
11  
12 use Finance::GeniusTrader::Analyzers;
13 use Finance::GeniusTrader::Calculator;
14 use Finance::GeniusTrader::Prices;
15  
16 @ISA = qw(Finance::GeniusTrader::Analyzers);
17 @NAMES = ("BuyAndHold[#*]");
18 @DEFAULT_ARGS = ();
19  
20 =head1 NAME
21  
22 Finance::GeniusTrader::Analyzers::AvgCosts - Average Costs per trade
23  
24 =head1 DESCRIPTION
25  
26 The mean performance of the portfolio
27  
28 =head2 Parameters
29  
30 none
31  
32 =cut
33  
34 sub initialize {
35 1;
36 }
37  
38 sub calculate {
39 my ($self, $calc, $last, $first, $portfolio) = @_;
40 my $name = $self->get_name;
41  
42 if ( !defined($portfolio) ) {
43 $portfolio = $calc->{'pf'};
44 }
45 if ( !defined($first) ) {
46 $first = $calc->{'first'};
47 }
48 if ( !defined($last) ) {
49 $last = $calc->{'last'};
50 }
51  
52 my $buyhold = $calc->prices->at($last)->[$LAST] /
53 $calc->prices->at($first)->[$LAST] - 1;
54  
55 $calc->indicators->set($name, $last, $buyhold);
56 }
57  
58 1;