| 1 | package Finance::GeniusTrader::Indicators::KirshenbaumBands; | ||
| 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 | # original base date 24 Apr 2005 3206 bytes | ||
| 9 | # $Id$ | ||
| 10 | |||
| 11 | # Standards-Version: 1.0 | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 15 | |||
| 16 | use Finance::GeniusTrader::Indicators; | ||
| 17 | use Finance::GeniusTrader::Indicators::EMA; | ||
| 18 | use Finance::GeniusTrader::Indicators::StandardError; | ||
| 19 | use Finance::GeniusTrader::Prices; | ||
| 20 | |||
| 21 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 22 | @NAMES = ("KB[#1,#3]","KBSup[#1,#2,#3]","KBInf[#1,#2,#3]"); | ||
| 23 | @DEFAULT_ARGS = (20, 1.75, "{I:Prices CLOSE}"); | ||
| 24 | |||
| 25 | =head1 Finance::GeniusTrader::Indicators::KirshenbaumBands | ||
| 26 | |||
| 27 | =head2 Overview | ||
| 28 | |||
| 29 | Kirshenbaum Bands are similar to Bollinger Bands, in that they measure | ||
| 30 | market volatility. However, rather than use Standard Deviation of | ||
| 31 | a moving average for band with, they use Standard Error of linear | ||
| 32 | regression lines of the Close. This has the effect of measuring | ||
| 33 | volatility around the current trend, instead of measuring volatility for | ||
| 34 | changes in trend. | ||
| 35 | |||
| 36 | =head2 Author | ||
| 37 | |||
| 38 | Paul Kirshenbaum, a money manager and mathematician with PhD in economics | ||
| 39 | from NYU, submitted this rather unique trading band which is "de-trended". | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | sub initialize { | ||
| 44 | my $self = shift; | ||
| 45 | |||
| 46 | $self->{'ema'} = Finance::GeniusTrader::Indicators::EMA->new([ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(3) ]); | ||
| 47 | $self->{'standard_error'} = Finance::GeniusTrader::Indicators::StandardError->new( | ||
| 48 | [ $self->{'args'}->get_arg_names(1), $self->{'args'}->get_arg_names(3) ]); | ||
| 49 | |||
| 50 | $self->add_indicator_dependency($self->{'ema'}, 1); | ||
| 51 | $self->add_indicator_dependency($self->{'standard_error'}, 1); | ||
| 52 | $self->add_prices_dependency($self->{'args'}->get_arg_constant(1)); | ||
| 53 | } | ||
| 54 | |||
| 55 | =head2 Finance::GeniusTrader::Indicators::KirshenbaumBands::calculate($calc, $day) | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | sub calculate { | ||
| 60 | my ($self, $calc, $i) = @_; | ||
| 61 | my $indic = $calc->indicators; | ||
| 62 | my $ema_name = $self->{'ema'}->get_name; | ||
| 63 | my $se_name = $self->{'standard_error'}->get_name; | ||
| 64 | my $kb_name = $self->get_name(0); | ||
| 65 | my $kbsup_name = $self->get_name(1); | ||
| 66 | my $kbinf_name = $self->get_name(2); | ||
| 67 | my $n = $self->{'args'}->get_arg_values($calc, $i, 2); | ||
| 68 | |||
| 69 | return if ($indic->is_available($kb_name, $i) && | ||
| 70 | $indic->is_available($kbsup_name, $i) && | ||
| 71 | $indic->is_available($kbinf_name, $i)); | ||
| 72 | return if (! $self->check_dependencies($calc, $i)); | ||
| 73 | |||
| 74 | # Calculate and get the P-Period EMA value | ||
| 75 | my $ema_value = $indic->get($ema_name, $i); | ||
| 76 | |||
| 77 | # Calculate and get Standard Error value | ||
| 78 | my $se_value = $indic->get($se_name, $i); | ||
| 79 | |||
| 80 | # Kirshenbaum Band Sup is equal to the value of the exponential moving | ||
| 81 | # average + standard error | ||
| 82 | my $kbsup_value = $ema_value + ($n * $se_value); | ||
| 83 | |||
| 84 | # Kirshenbaum Band Inf is equal to the value of the exponential moving | ||
| 85 | # average - standard error | ||
| 86 | my $kbinf_value = $ema_value - ($n * $se_value); | ||
| 87 | |||
| 88 | # Return the results | ||
| 89 | $indic->set($kb_name, $i, $ema_value); | ||
| 90 | $indic->set($kbsup_name, $i, $kbsup_value); | ||
| 91 | $indic->set($kbinf_name, $i, $kbinf_value); | ||
| 92 | } | ||
| 93 | |||
| 94 | 1; |