| 1 | package Finance::GeniusTrader::Analyzers::DrawDown; | ||
| 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 = ("DrawDown[#*]"); | ||
| 17 | @DEFAULT_ARGS = ("{A:NetGain}", "{A:InitSum}", "{A:Max {A:NetGain}}"); | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | Finance::GeniusTrader::Analyzers::DrwaDown - The Drawdown of the portfolio | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | The Drawdown of the portfolio: The maximum Drawdown can be calculated | ||
| 26 | as: {A:Min {A:DrawDown}} | ||
| 27 | |||
| 28 | =head2 Parameters | ||
| 29 | |||
| 30 | =over | ||
| 31 | |||
| 32 | =item NetGain | ||
| 33 | |||
| 34 | =item Initial Sum of Cash | ||
| 35 | |||
| 36 | =item Maximum net gain | ||
| 37 | |||
| 38 | =back | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | sub initialize { | ||
| 43 | 1; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub calculate { | ||
| 47 | my ($self, $calc, $last, $first, $portfolio) = @_; | ||
| 48 | my $name = $self->get_name; | ||
| 49 | |||
| 50 | if ( !defined($portfolio) ) { | ||
| 51 | $portfolio = $calc->{'pf'}; | ||
| 52 | } | ||
| 53 | if ( !defined($first) ) { | ||
| 54 | $first = $calc->{'first'}; | ||
| 55 | } | ||
| 56 | if ( !defined($last) ) { | ||
| 57 | $last = $calc->{'last'}; | ||
| 58 | } | ||
| 59 | |||
| 60 | my $gain = $self->{'args'}->get_arg_values($calc, $last, 1); | ||
| 61 | my $sum = $self->{'args'}->get_arg_values($calc, $last, 2); | ||
| 62 | my $max = $self->{'args'}->get_arg_values($calc, $last, 3); | ||
| 63 | |||
| 64 | my @ret = (); | ||
| 65 | foreach my $f (0..$#{$gain}) | ||
| 66 | { | ||
| 67 | my $tmp = 0; | ||
| 68 | $tmp = 1 - (($sum->[$f] + $gain->[$f]) / ($sum->[$f] + $max )) if (ref($sum) =~/ARRAY/ && | ||
| 69 | $sum->[$f] != 0); | ||
| 70 | $tmp = 1 - (($sum- + $gain->[$f]) / ($sum + $max )) if (ref($sum) !~/ARRAY/ && | ||
| 71 | $sum != 0); | ||
| 72 | push @ret, $tmp; | ||
| 73 | } | ||
| 74 | |||
| 75 | $calc->indicators->set($name, $last, \@ret); | ||
| 76 | |||
| 77 | } | ||
| 78 | |||
| 79 | 1; |