stockmonkey
view release on metacpan or search on metacpan
examples/precursor-bayesian-nightmare-stockmonkey.pl view on Meta::CPAN
use Date::Manip;
use Algorithm::NaiveBayes;
use List::Util qw(min max sum);
use GD::Graph::lines;
use GD::Graph::Hooks;
my $dbo = MySQL::Easy->new("scratch"); # reads .my.cnf for password and host
my @tickers = split(m/[^A-Z]/, shift || "JPM,SCTY,P,TSLA,ATVI,HIMX,ZNGA,BEARX");
my $phist = shift || 180; # final plot history items
my $slurpp = "10 years"; # data we want to fetch
my @proj = map {[map {int $_} split m{/}]} @ARGV; # projections
# proj is a list of projections to consider, days/percent
@proj = (
[10,3],[10,5],[10,10],
[20,3],[20,5],[20,10],
);
if( $ENV{NEWK} ) {
$dbo->do("drop table if exists stockplop");
$dbo->do("drop table if exists stockplop_annotations");
examples/precursor-bayesian-nightmare-stockmonkey.pl view on Meta::CPAN
for (90,80,70) { $events{"crsi_$_"} = 1 if $rsi >= $_ }
for (10,20,30) { $events{"crsi_$_"} = 1 if $rsi <= $_ }
}
if( defined (my $adx = $row->{'ADX(14)'}) ) {
$adx = int(100 * $adx);
for (10, 20, 30, 40, 50) { $events{"adx_$_"} = 1 if $adx >= $_ }
}
if( defined ( my $bbs = $row->{'BOLL(2,20)'}) ) {
my ($L, $M, $U) = map {$_ eq "-" ? undef : (0.0+$_)} split m{/}, $bbs;
if( defined $L and defined $M and defined $U ) {
$events{boll_overbought} = 1 if $row->{close} >= $U;
$events{boll_oversold} = 1 if $row->{close} <= $L;
}
}
if( @last ) {
if( defined $last[-1]{"LAG(8)"} and defined $last[-1]{"LAG(4)"} ) {
$events{lag_break_up} = 1
if $last[-1]{'LAG(4)'} < $last[-1]{"LAG(8)"} and $row->{'LAG(4)'} > $row->{"LAG(8)"};
23-Jul-13,15.15,15.52,15.15,15.22,4642680
22-Jul-13,15.38,15.66,14.89,15.15,8197087
);
# }}}
my @cci;
for my $line (reverse @google_finance_data) {
my ($date, $open, $high, $low, $close, $volume) = split m/,/, $line;
$cci->insert( [$high, $low, $close] );
push @cci, 0+$cci->query;
}
my @manually_fetched_from_google = qw(46.32 56.46 97.9 106.59 27.61 19.39 77.46);
plan tests => 0+@manually_fetched_from_google;
while( my $mf = shift @manually_fetched_from_google ) {
my $K3 = Math::Business::SMA->new(3);
my $K33 = Math::Business::SMA->new(3);
my $K5 = Math::Business::SMA->new(5);
my $K55 = Math::Business::SMA->new(5);
while(<DATA>) {
# data ripped from http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:stochastic_oscillato
chomp;
my ($line, $date, $high, $low, $highest, $lowest, $close, $theirK) = split m/,/;
$fsto->insert( my $i = [$high,$low,$close] );
$ssto->insert( $i );
$sful->insert( $i );
my ($D,$K) = $fsto->query;
$K3->insert($K) if defined $K;
my $k3 = $K3->query;
( run in 0.477 second using v1.01-cache-2.11-cpan-71847e10f99 )