| 1 | package Finance::GeniusTrader::Indicators::EVWMA; | ||
| 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 | # ras hack based on version dated 24apr05 2780 bytes | ||
| 9 | # includes patches thru 9mar07 | ||
| 10 | # $Id$ | ||
| 11 | |||
| 12 | # Standards-Version: 1.0 | ||
| 13 | |||
| 14 | use strict; | ||
| 15 | use vars qw(@ISA @NAMES @DEFAULT_ARGS); | ||
| 16 | |||
| 17 | use Finance::GeniusTrader::Indicators; | ||
| 18 | use Finance::GeniusTrader::Prices; | ||
| 19 | use Finance::GeniusTrader::MetaInfo; | ||
| 20 | |||
| 21 | @ISA = qw(Finance::GeniusTrader::Indicators); | ||
| 22 | @NAMES = ("EVWMA"); | ||
| 23 | @DEFAULT_ARGS = ("{I:Prices CLOSE}"); | ||
| 24 | |||
| 25 | =head1 Finance::GeniusTrader::Indicators::EVWMA (Elastic Volume Weighted Moving Average) | ||
| 26 | |||
| 27 | =head2 Overview | ||
| 28 | |||
| 29 | The Elastic Volume Weighted Moving Average (eVWMA) differs from usual | ||
| 30 | average in that : | ||
| 31 | |||
| 32 | - It does not refer to any underlying averaging time period (for | ||
| 33 | example, 20 days, 50 days, 200 days). Instead, eVWMA uses share volume | ||
| 34 | to define the period of the averaging. | ||
| 35 | |||
| 36 | - It incorporates information about volume (and possibly time) in a | ||
| 37 | natural and logical way | ||
| 38 | |||
| 39 | - It can be derived from, and seen as an approximation to, a statistical | ||
| 40 | measure and thus has a solid mathematical justification. | ||
| 41 | |||
| 42 | =head2 =====>>>>> SIGNIFICANT USAGE ISSUE <<<<<===== | ||
| 43 | |||
| 44 | to use I:EVWMA one must have a database containing the number of | ||
| 45 | shares floating for each security being analyzed. this shares_float | ||
| 46 | database is only searched for in an xml file at /bourse/metainfo/"$code".xml | ||
| 47 | |||
| 48 | currently the beancounter database doesn't store this security attribute, | ||
| 49 | nor does beancounter fetch this value in the course of a normal daily update. | ||
| 50 | |||
| 51 | yahoo does provide the attribute via 'f6', but how one might create the | ||
| 52 | required xml file based database is not described. | ||
| 53 | |||
| 54 | =head2 Calculation | ||
| 55 | |||
| 56 | eVWMA(0) = Today's Close | ||
| 57 | eVWMA(i) = ( (Number of shares floating - Today's Volume) \ | ||
| 58 | * eVWMA(i-1) + Today's Volume * Today's Close ) \ | ||
| 59 | / Number of shares floating | ||
| 60 | |||
| 61 | =head2 Example | ||
| 62 | |||
| 63 | Finance::GeniusTrader::Indicators::EVWMA->new() | ||
| 64 | |||
| 65 | =head2 Links | ||
| 66 | |||
| 67 | http://www.christian-fries.de/evwma/ | ||
| 68 | http://www.linnsoft.com/tour/techind/evwma.htm | ||
| 69 | |||
| 70 | =head2 Finance::GeniusTrader::Indicators::EVWMA::calculate($calc, $day) | ||
| 71 | |||
| 72 | =cut | ||
| 73 | sub initialize { | ||
| 74 | my ($self) = @_; | ||
| 75 | |||
| 76 | $self->{'metainfo'} = Finance::GeniusTrader::MetaInfo->new(); | ||
| 77 | } | ||
| 78 | |||
| 79 | sub calculate { | ||
| 80 | my ($self, $calc, $i) = @_; | ||
| 81 | my $getvalue = $self->{'_func'}; | ||
| 82 | my $evwma_name = $self->get_name(0); | ||
| 83 | my $prices = $calc->prices; | ||
| 84 | my $evwma = 0; | ||
| 85 | |||
| 86 | # Return if we have already the required data | ||
| 87 | return if ($calc->indicators->is_available($evwma_name, $i)); | ||
| 88 | return if (! $self->check_dependencies($calc, $i)); | ||
| 89 | |||
| 90 | # Return if the metainfo file doesn't exist | ||
| 91 | return if not (-e "/bourse/metainfo/" . $calc->code . ".xml"); | ||
| 92 | |||
| 93 | # Find the number of floating shares | ||
| 94 | $self->{'metainfo'}->load("/bourse/metainfo/" . $calc->code . ".xml"); | ||
| 95 | my $floating_shares = $self->{'metainfo'}->get("floating_shares"); | ||
| 96 | |||
| 97 | for (my $n = 0; $n <= $i; $n++) { | ||
| 98 | |||
| 99 | if ($n == 0) { | ||
| 100 | |||
| 101 | # Set eVWMA(0) as Today's Close | ||
| 102 | $evwma = $self->{'args'}->get_arg_values($calc, $i, $n); | ||
| 103 | |||
| 104 | } else { | ||
| 105 | |||
| 106 | # Calculate the following eVWMA | ||
| 107 | $evwma = (($floating_shares - $prices->at($n)->[$VOLUME]) | ||
| 108 | * $self->{'args'}->get_arg_values($calc, $i, $n - 1) | ||
| 109 | + ($prices->at($n)->[$VOLUME] | ||
| 110 | * $self->{'args'}->get_arg_values($calc, $i, $n))) | ||
| 111 | / $floating_shares; | ||
| 112 | |||
| 113 | } | ||
| 114 | $calc->indicators->set($evwma_name, $i, $evwma); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | 1; |