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";
}

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. This also means the alpha is upside of other alpha you might see. RSI(14) actually uses an alpha of ~0.0714, but set_alpha() takes the inverse to make $rsi-set_alpha(14)> work.

If all of the above seems really confusing, no worries: RSI(14) means set_alpha(14) (or new(14) and is equivelent to set_days(27).

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. There is a mailing list with very light traffic that you might want to join: http://groups.google.com/group/stockmonkey/.

COPYRIGHT

Copyright © 2013 Paul Miller

LICENSE

This is released under the Artistic License. See perlartistic.

SEE ALSO

perl(1), Math::Business::StockMonkey, Math::Business::StockMonkey::FAQ, Math::Business::StockMonkey::CookBook

http://en.wikipedia.org/wiki/Relative_Strength_Index