NAME
Math::Business::RSI - Technical Analysis: Relative Strength Index
SYNOPSIS
use Math::Business::RSI;
my $rsi = new Math::Business::RSI;
$rsi->set_alpha(14); # issues a set days of 2*14-1
$rsi->set_days(27); # equivilent to set_alpha(14)
# equivelent to set_days(27)/set_alpha(14):
my $rsi = new Math::Business::RSI(14);
# or to just get the recommended model ... set_alpha(14)
my $rsi = Math::Business::RSI->recommended;
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
);
# choose one:
$rsi->insert( @closing_values );
$rsi->insert( $_ ) for @closing_values;
if( defined(my $q = $rsi->query) ) {
print "RSI: $q.\n";
} else {
print "RSI: n/a.\n";
}
# you may use this to kick start
$rsi->start_with( $U, $D, $cy );
# you may fetch those values with these
my $U = $rsi->query_EMA_U;
my $D = $rsi->query_EMA_D;
my $cy = $rsi->query_cy; # (close yesterday)
RESEARCHER
The RSI was designed by J. Welles Wilder Jr in 1978.
According to Wilder, a security is "overbought" it the RSI reaches an upper bound of 70 and is "oversold" when it moves below 30. Some sources also use thresholds of 80 and 20.
Therefore, moving above the upper threshold is a selling signal, whlie moving below the lower threshold is a signal to buy.
Oddly, RSI(14) uses a "smoothing period" of 14 days -- referring to an alpha of 1/14. This means the EMA[N]u/EMA[N]d has N set to 27!
Therefore, in addition to the usual set_days()
there is also a set_alpha()
(which is used by new()
). set_days(27)
is equivelent to set_alpha(14)
or new(14)
.
Cutler
There are differing schools of thought on how to calculate this and how important it is to stick to precisely the formula Wilder used. Cutler used simple moving averages instead of exponential moving averages.
You can switch between Wilder and Cutler mode with these:
$rsi->set_cutler; # for simple moving averages
$rsi->set_standard; # for exponential moving averages
WARNING: Both of these clear out the value queue! If you need to track both, you'll need two objects.
Thanks
Todd Litteken <cl@xganon.com>
Amit Dutt <amit_dutt@hotmail.com>
AUTHOR
Paul Miller <jettero@cpan.org>
I am using this software in my own projects... If you find bugs, please please please let me know.
I normally hang out on #perl on freenode, so you can try to get immediate gratification there if you like. irc://irc.freenode.net/perl
COPYRIGHT
Copyright (c) 2008 Paul Miller -- LGPL [Software::License::LGPL_2_1]
perl -MSoftware::License::LGPL_2_1 \
-e '$l = Software::License::LGPL_2_1->new({
holder=>"Paul Miller"});
print $l->fulltext' | less
SEE ALSO
perl(1)