« GeniusTrader/Graphics/DataSource/GenericIndicatorResults.pm
↑ Summary
GeniusTrader/Indicators/ROC.pm »
| 1 | package Finance::GeniusTrader::Indicators::MaxDrawDown; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 4 | # standards upgrade Copyright 2005 Thomas Weigert | ||
| 5 | # This file is distributed under the terms of the General Public License | ||
| 6 | # version 2 or (at your option) any later version. | ||
| 7 | |||
| 8 | # $Id$ | ||
| 9 | |||
| 10 | # Standards-Version: 1.0 | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 14 | |||
| 15 | use Finance::GeniusTrader::Indicators; | ||
| 16 | |||
| 17 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 18 | @NAMES = ("MaxDrawDown[#1]"); | ||
| 19 | @DEFAULT_ARGS = ("{I:Prices CLOSE}"); | ||
| 20 | |||
| 21 | =pod | ||
| 22 | |||
| 23 | =head1 Finance::GeniusTrader::Indicators::MaxDrawDown | ||
| 24 | |||
| 25 | =head2 Overview | ||
| 26 | |||
| 27 | Calculate the MaxDrawDown, which is the worst percentage loss after reaching a maximum. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub initialize { | ||
| 32 | my ($self) = @_; | ||
| 33 | |||
| 34 | $self->add_prices_dependency(2); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub calculate { | ||
| 38 | my ($self, $calc, $i) = @_; | ||
| 39 | my $name = $self->get_name; | ||
| 40 | my $current_draw_down = 0; | ||
| 41 | my $max_draw_down = 0; | ||
| 42 | |||
| 43 | return if (! $self->check_dependencies($calc, $i)); | ||
| 44 | |||
| 45 | my $high = $self->{'args'}->get_arg_values($calc, 0, 1); | ||
| 46 | |||
| 47 | for (my $n = 0; $n <= $i; $n++) { | ||
| 48 | |||
| 49 | if ($self->{'args'}->get_arg_values($calc, $n, 1) > $high) { | ||
| 50 | $high = $self->{'args'}->get_arg_values($calc, $n, 1); | ||
| 51 | } else { | ||
| 52 | $current_draw_down = ($high - $self->{'args'}->get_arg_values($calc, $n, 1)) * 100 / $high; | ||
| 53 | } | ||
| 54 | if ($current_draw_down > $max_draw_down) { | ||
| 55 | $max_draw_down = $current_draw_down; | ||
| 56 | } | ||
| 57 | |||
| 58 | } | ||
| 59 | $calc->indicators()->set($name, $i, $max_draw_down); | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; |