| 1 | package Finance::GeniusTrader::Analyzers::Performance; | ||
| 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 | |||
| 15 | @ISA = qw(Finance::GeniusTrader::Analyzers); | ||
| 16 | @NAMES = ("Performance[#*]"); | ||
| 17 | @DEFAULT_ARGS = ("{A:NetGainPercent}", "{A:OpenPrice}"); | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | Finance::GeniusTrader::Analyzers::Performance - The Performance of the trades | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | The Performance of the trades | ||
| 26 | |||
| 27 | =head2 Parameters | ||
| 28 | |||
| 29 | =over | ||
| 30 | |||
| 31 | =item The net gain in percent | ||
| 32 | |||
| 33 | =item The price ath the opening of a trade | ||
| 34 | |||
| 35 | =back | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | sub initialize { | ||
| 40 | 1; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub calculate { | ||
| 44 | my ($self, $calc, $last, $first, $portfolio) = @_; | ||
| 45 | my $name = $self->get_name; | ||
| 46 | |||
| 47 | if ( !defined($portfolio) ) { | ||
| 48 | $portfolio = $calc->{'pf'}; | ||
| 49 | } | ||
| 50 | if ( !defined($first) ) { | ||
| 51 | $first = $calc->{'first'}; | ||
| 52 | } | ||
| 53 | if ( !defined($last) ) { | ||
| 54 | $last = $calc->{'last'}; | ||
| 55 | } | ||
| 56 | |||
| 57 | my $gain = $self->{'args'}->get_arg_values($calc, $last, 1); | ||
| 58 | my $sum = $self->{'args'}->get_arg_values($calc, $last, 2); | ||
| 59 | |||
| 60 | my @ret = (); | ||
| 61 | foreach my $f (0..$#{$gain}) | ||
| 62 | { | ||
| 63 | my $tmp = 0; | ||
| 64 | $tmp = $gain->[$f] / $sum->[$f] if (ref($sum) =~/ARRAY/ && $sum->[$f] != 0); | ||
| 65 | $tmp = $gain->[$f] / $sum if (ref($sum) !~/ARRAY/ && $sum != 0); | ||
| 66 | push @ret, $tmp; | ||
| 67 | } | ||
| 68 | |||
| 69 | $calc->indicators->set($name, $last, \@ret); | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; |