« GeniusTrader/Graphics/DataSource/Prices.pm
↑ Summary
GeniusTrader/Graphics/DataSource/PortfolioEvaluation.pm »
| 1 | package Finance::GeniusTrader::Graphics::DataSource::Volume; | ||
| 2 | |||
| 3 | # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber | ||
| 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 | use strict; | ||
| 8 | use vars qw(@ISA); | ||
| 9 | |||
| 10 | @ISA = qw(Finance::GeniusTrader::Graphics::DataSource); | ||
| 11 | |||
| 12 | use Finance::GeniusTrader::Prices; | ||
| 13 | use Finance::GeniusTrader::Graphics::DataSource; | ||
| 14 | use Finance::GeniusTrader::Tools qw(:math); | ||
| 15 | |||
| 16 | =head1 Finance::GeniusTrader::Graphics::DataSource::Volume | ||
| 17 | |||
| 18 | This datasource provides volume information. | ||
| 19 | It uses a Finance::GeniusTrader::Prices object as a basis. | ||
| 20 | |||
| 21 | =head2 Finance::GeniusTrader::Prices::DataSource::Volume->new($prices) | ||
| 22 | |||
| 23 | Create a new volume data source. | ||
| 24 | |||
| 25 | =cut | ||
| 26 | sub new { | ||
| 27 | my $type = shift; | ||
| 28 | my $class = ref($type) || $type; | ||
| 29 | my $prices = shift; | ||
| 30 | |||
| 31 | my $self = { "prices" => $prices }; | ||
| 32 | |||
| 33 | bless $self, $class; | ||
| 34 | |||
| 35 | $self->set_available_range(0, $prices->count() - 1); | ||
| 36 | $self->set_selected_range($self->get_available_range()); | ||
| 37 | |||
| 38 | return $self; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub is_available { | ||
| 42 | my ($self, $index) = @_; | ||
| 43 | if (($index >= 0) && ($index < $self->{'prices'}->count())) | ||
| 44 | { | ||
| 45 | return 1; | ||
| 46 | } | ||
| 47 | return 0; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub get { | ||
| 51 | my ($self, $index) = @_; | ||
| 52 | return $self->{'prices'}->at($index)->[$VOLUME]; | ||
| 53 | } | ||
| 54 | |||
| 55 | sub update_value_range { | ||
| 56 | my ($self) = @_; | ||
| 57 | my ($start, $end) = $self->get_selected_range(); | ||
| 58 | my ($min, $max); | ||
| 59 | $min = $self->{'prices'}->at($start)->[$VOLUME]; | ||
| 60 | $max = $self->{'prices'}->at($start)->[$VOLUME]; | ||
| 61 | for(my $i = $start; $i <= $end; $i++) { | ||
| 62 | $min = min($self->{'prices'}->at($i)->[$VOLUME], $min); | ||
| 63 | $max = max($self->{'prices'}->at($i)->[$VOLUME], $max); | ||
| 64 | } | ||
| 65 | $self->set_min_value($min); | ||
| 66 | $self->set_max_value($max); | ||
| 67 | } | ||
| 68 | |||
| 69 | 1; |