NAME

Math::Business::Stochastic - Technical Analysis: Stochastic Oscillator

SYNOPSIS

use Math::Business::Stochastic;

my $sto = new Math::Business::Stochastic;
   $sto->set_days(5);     # Lane uses 5 in his examples (if any)
   $sto->set_dperiod(30); # Lane
   $sto->set_method( Math::Business::Stochastic::METHOD_LANE );
   # methods: METHOD_LANE, METHOD_SLOW, METHOD_FAST, METHOD_FULL
   $sto->set_xperiod(3); # used only by METHOD_FULL 


# Lane's version
my $sto = Math::Business::Stochastic->recommended;


# Probably more like what you expect (ie, matches up with
# Yahoo/Google/Ameritrade, etc)

my $sto_slow = Math::Business::Stochastic->modern_slow;
my $sto_fast = Math::Business::Stochastic->modern_fast;
my $sto_full = Math::Business::Stochastic->modern_full;


# basic usage

$sto->insert($close);
my ($D, $K) = $sto->query;
my $K = $sto->query; # if you don't care about %D
print "current stochastic: %K=$K and %D=$D\n";

RESEARCHER

The Stochastic was designed by R. George C. Lane.

It is difficult to find a good reference on this indicator. Almost every source disagrees with the next and some sources even disagree internally (I'm looking at you Wikipedia).

The stochastic (among other things) purports to indicate an "overbought" situation where the %K is above 80 and "oversold" when below 20.

There are "divergences" and "convergences" to look for too, however. If there is a higher high or a lower low in the %K, this can apperntly indicate trend changes. This concept is not easy to pin down explicitly, and so is not described here.

FUTHER BACKGROUND ON COMPUTATION

The basic idea is that %K should be a momentum indicator and %D should be a smoothed version of %K. Most sources generally agree that %K(5) should be computed as follows:

$K = 100 * (close - min(@last_5_low))/(max(@last_5_high)-min(@last_5_low))

%D is more sticky and various sources give various answers. Lane himself seemed to use:

$D = 100 * max(@last_3_high)/min(@last_3_low)

But most charting sites and the Wikipedia seem to choose an SMA or EMA for smothing on %D and thus produce something like:

$SMA->set_days(3);
$SMA->insert($K);
$D = $SMA->query;

The main problem getting this right is that Lane himself hasn't really spelled it out in publication. "Do this, then this, then that." The reason seems to be the lecture circuit. He teaches this stuff in classes and seminars (or tought) and hasn't really published it in the traditional sense.

To a certain extent, we therefore feel free to pick whatever we want for the defaults.

THANKS

Robby Oliver <robbykaty@gmail.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/Stochastic_oscillator

http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:stochastic_oscillato