| 1 | package Finance::GeniusTrader::Analyzers::IonDate; | ||
| 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 | use Finance::GeniusTrader::Prices; | ||
| 15 | |||
| 16 | @ISA = qw(Finance::GeniusTrader::Analyzers); | ||
| 17 | @NAMES = ("IonDate[#*]"); | ||
| 18 | @DEFAULT_ARGS = ("{I:SMA}", "{A:OpenDate}"); | ||
| 19 | |||
| 20 | =head1 NAME | ||
| 21 | |||
| 22 | Finance::GeniusTrader::Analyzers::AvgCosts - Average Costs per trade | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | The mean performance of the portfolio | ||
| 27 | |||
| 28 | =head2 Parameters | ||
| 29 | |||
| 30 | none | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | sub initialize { | ||
| 35 | 1; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub calculate { | ||
| 39 | my ($self, $calc, $last, $first, $portfolio) = @_; | ||
| 40 | my $name = $self->get_name; | ||
| 41 | |||
| 42 | if ( !defined($portfolio) ) { | ||
| 43 | $portfolio = $calc->{'pf'}; | ||
| 44 | } | ||
| 45 | if ( !defined($first) ) { | ||
| 46 | $first = $calc->{'first'}; | ||
| 47 | } | ||
| 48 | if ( !defined($last) ) { | ||
| 49 | $last = $calc->{'last'}; | ||
| 50 | } | ||
| 51 | |||
| 52 | my $array = $self->{'args'}->get_arg_values($calc, $last, 2); | ||
| 53 | my @ret = (); | ||
| 54 | |||
| 55 | foreach my $date (@{$array}) | ||
| 56 | { | ||
| 57 | my $i = $calc->prices->find_nearest_date( $date ); | ||
| 58 | my $val = $self->{'args'}->get_arg_values($calc, $calc->prices->date($date), 1); | ||
| 59 | $val ="NA" if ( !defined($val) ); | ||
| 60 | # print $date . "\t" . $calc->prices->date($date) . "\t" . $val . "\n"; | ||
| 61 | push @ret, $val; | ||
| 62 | } | ||
| 63 | |||
| 64 | $calc->indicators->set($name, $last, \@ret); | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; |