App-financeta
view release on metacpan or search on metacpan
lib/App/financeta/gui.pm view on Meta::CPAN
local $SIG{HUP} = $stack_sub;
run Prima;
}
sub security_wizard {
my ($self, $win) = @_;
my $wiz = App::financeta::gui::security_wizard->new(owner => $win, gui => $self);
return ($wiz->run() == mb::Ok) ? 1 : undef;
}
sub remove_indicator($) {
my ($self, $win) = @_;
my $result = $self->remove_indicator_wizard($win);
if ($result and ref $result eq 'HASH') {
$log->debug("Removing indicator: ", dumper($result));
# we know here the name of the indicator, the index of the indicator and
# the columns in the data to remove.
# let's do that.
my ($data, $symbol, $indicators, $headers) = $self->get_tab_data_by_name($win, $result->{tab});
return unless $headers;
my $total_cols = $data->dim(1);
lib/App/financeta/gui.pm view on Meta::CPAN
}
my ($next_data) = $self->display_data($win, $data, $symbol, $iref, $output);
$icount--;
$data = $next_data if $icount > 0;
}
return 1;
}
return 0;
}
sub add_indicator($$$) {
my ($self, $win, $data, $symbol) = @_;
if ($self->add_indicator_wizard($win)) {
my $iref = $self->current->{indicator};
if ($self->run_and_display_indicator($win, $data, $symbol, [$iref])) {
my ($ndata, $nsymbol, $indicators, $ndhr, $nbs) = $self->get_tab_data($win);
my $type = $self->current->{plot_type} || 'OHLC';
$self->plot_data($win, $ndata, $nsymbol, $type, $indicators, $nbs);
return 1;
}
}
lib/App/financeta/gui.pm view on Meta::CPAN
sub get_tab_data {
my ($self, $win) = @_;
return unless $win;
my @tabs = grep { $_->name =~ /data_tabs/ } $win->get_widgets();
return unless @tabs;
my $idx = $win->data_tabs->pageIndex;
return $self->_get_tab_data($win->data_tabs, $idx);
}
sub get_tab_data_by_name($$) {
my ($self, $win, $name) = @_;
return unless $win;
my @tabs = grep { $_->name =~ /data_tabs/ } $win->get_widgets();
return unless @tabs;
my $pc = $win->data_tabs->pageCount - 1;
return unless $pc >= 0;
$log->debug("Looking for $name");
for my $idx (0 .. $pc) {
my @nt = $win->data_tabs->widgets_from_page($idx);
next unless @nt;
lib/App/financeta/gui.pm view on Meta::CPAN
my $idx = $win->data_tabs->pageIndex;
my @nt = $win->data_tabs->widgets_from_page($idx);
return unless @nt;
my ($dl) = grep { $_->name =~ /^tab_/i } @nt;
if ($dl) {
$log->debug("Getting info for " . $dl->name);
return wantarray ? ($dl->{-info}, $dl->name) : $dl->{-info};
}
}
sub set_tab_info($$) {
my ($self, $win, $info) = @_;
return unless $win;
my @tabs = grep { $_->name =~ /data_tabs/ } $win->get_widgets();
return unless @tabs;
my $idx = $win->data_tabs->pageIndex;
my @nt = $win->data_tabs->widgets_from_page($idx);
return unless @nt;
my ($dl) = grep { $_->name =~ /^tab_/i } @nt;
if ($dl) {
$log->debug("Setting info for " . $dl->name);
$dl->{-info} = $info;
return 1;
}
}
sub set_tab_data_by_name($$) {
my ($self, $win, $name, $p, $s, $ind, $hdr) = @_;
return unless $win;
return unless $name;
my @tabs = grep { $_->name =~ /data_tabs/ } $win->get_widgets();
return unless @tabs;
my $pc = $win->data_tabs->pageCount - 1;
return unless $pc >= 0;
my $found;
for my $idx (0 .. $pc) {
my @nt = $win->data_tabs->widgets_from_page($idx);
lib/App/financeta/gui.pm view on Meta::CPAN
my @nt = $win->data_tabs->widgets_from_page($idx);
next unless @nt;
my ($dl) = grep { $_->name =~ /^tab_/i } @nt;
if ($dl and $dl->name eq $name) {
$log->debug("Getting buy-sells for " . $dl->name);
return wantarray ? ($dl->{-buysells}, $dl->name) : $dl->{-buysells};
}
}
}
sub get_tab_names($) {
my ($self, $win) = @_;
return unless $win;
my @tabs = grep { $_->name =~ /data_tabs/ } $win->get_widgets();
return unless @tabs;
my $pc = $win->data_tabs->pageCount - 1;
return unless $pc >= 0;
my %names = ();
for my $idx (0 .. $pc) {
my @nt = $win->data_tabs->widgets_from_page($idx);
next unless @nt;
lib/App/financeta/indicators.pm view on Meta::CPAN
'Volatility Indicators',
'Volume Indicators',
'Statistic Functions',
'Price Transform',
'Hilbert Transform',
'Candlestick Patterns',
);
return wantarray ? @groups : \@groups;
}
sub get_funcs($) {
my ($self, $grp) = @_;
$grp = $self->group_key->{$grp} if defined $grp;
if (defined $grp and $self->has($grp)) {
my $r = $self->$grp;
my @funcs = ();
foreach my $k (sort(keys %$r)) {
push @funcs, $r->{$k}->{name};
}
$log->debug("Found funcs: ", dumper(\@funcs));
return wantarray ? @funcs : \@funcs;
}
}
sub get_params($$) {
my ($self, $fn_name, $grp) = @_;
$grp = $self->group_key->{$grp} if defined $grp;
my $fn;
# find the function parameters
if (defined $grp and $self->has($grp)) {
my $r = $self->$grp;
foreach my $k (sort (keys %$r)) {
$fn = $k if $r->{$k}->{name} eq $fn_name;
last if defined $fn;
}
my $params = $r->{$fn}->{params} if defined $fn;
$log->debug("Found params: ", dumper($params));
return $params;
}
}
sub _find_func_key($$) {
my ($self, $iref) = @_;
return unless ref $iref eq 'HASH';
my $params = $iref->{params};
my $fn_name = $iref->{func};
my $fn_key;
my $grp = $self->group_key->{$iref->{group}} if defined $iref->{group};
if (defined $grp and $self->has($grp) and $fn_name) {
my $r = $self->$grp;
foreach my $k (sort (keys %$r)) {
$fn_key = $k if $r->{$k}->{name} eq $fn_name;
last if defined $fn_key;
}
}
return unless defined $fn_key;
$log->debug("Found function key: $fn_key");
return $fn_key;
}
sub execute_ohlcv($$) {
my ($self, $data, $iref, $data2) = @_;
return unless ref $data eq 'PDL';
my $fn_key = $self->_find_func_key($iref);
return unless defined $fn_key;
# ok now we found the function so let's invoke it
my $grp = $self->group_key->{$iref->{group}} if defined $iref->{group};
return unless defined $grp;
my $params = $iref->{params};
my $func = $self->$grp->{$fn_key}->{func};
my $coderef = $self->$grp->{$fn_key}->{code};
lib/App/financeta/indicators.pm view on Meta::CPAN
push @input_pdls, $data2(,(4)); # always use close
$log->debug("Adding close2 price");
}
unless (scalar @input_pdls) {
$log->warn("These input columns are not supported yet: ", dumper($input_cols));
return;
}
return &$coderef($self, @input_pdls, @args) if ref $coderef eq 'CODE';
}
sub get_plot_args($$$) {
my ($self, $xdata, $output, $iref) = @_;
my $fn_key = $self->_find_func_key($iref);
return unless defined $fn_key;
my $grp = $self->group_key->{$iref->{group}} if defined $iref->{group};
return unless defined $grp;
my $plotref = $self->$grp->{$fn_key}->{lc($self->plot_engine)};
$log->warn("There is no plotting function available for $fn_key") unless ref $plotref eq 'CODE';
return &$plotref($self, $xdata, $output) if ref $plotref eq 'CODE';
}
share/testpdl.pl view on Meta::CPAN
use PDL;
use PDL::NiceSlice;
use PDL::Finance::TA;
use PDL::Graphics::Gnuplot;
use JSON::XS qw(decode_json);
use LWP::UserAgent;
use DateTime;
use Try::Tiny;
use Path::Tiny;
sub get_data($) {
my $symbol = shift;
my $filename = lc "$symbol.json";
my $content;
my $qdata;
my $url = sprintf("https://api.gemini.com/v2/candles/%s/%s", lc $symbol, '1day');
if (-e $filename) {
print "Found $filename, loading data from that\n";
$content = path($filename)->slurp;
} else {
my $lwp = LWP::UserAgent->new(timeout => 60);
share/testpdljs.pl view on Meta::CPAN
use PDL::NiceSlice;
use PDL::Finance::TA;
use JSON::XS qw(decode_json encode_json);
use LWP::UserAgent;
use DateTime;
use Try::Tiny;
use Path::Tiny;
use Template;
use Browser::Open;
sub get_data($) {
my $symbol = shift;
my $filename = lc "$symbol.json";
my $content;
my $qdata;
my $url = sprintf("https://api.gemini.com/v2/candles/%s/%s", lc $symbol, '1day');
if (-e $filename) {
print "Found $filename, loading data from that\n";
$content = path($filename)->slurp;
} else {
my $lwp = LWP::UserAgent->new(timeout => 60);
( run in 0.652 second using v1.01-cache-2.11-cpan-65fba6d93b7 )