|
Math::Business::SMA - Perl extension for calculating simple moving averages. |
Math::Business::SMA - Perl extension for calculating simple moving averages.
use Math::Business::SMA;
my $sma = new Math::Business::SMA;
set_days $sma 3;
my @closing_values = qw(
3 4 4 5 6 5 6 5 5 5 5
6 6 6 6 7 7 7 8 8 8 8
);
foreach(@closing_values) {
$sma->insert( $_ );
if( defined(my $q = $sma->query) ) {
print "SMA value: $q.\n";
} else {
print "SMA value: n/a.\n";
# note that a simple moving average is undefined before
# there's enough days to calculate it.
}
}
# you may use this to kick start $sma->start_with( [@array_of_days_most_recent_on_right] );
Jettero Heller jettero@cpan.org
perl(1), Math::Business::SMA(3).
|
Math::Business::SMA - Perl extension for calculating simple moving averages. |