view release on metacpan or search on metacpan
devel/closed-form.pl view on Meta::CPAN
}
return \@ret;
}
my $sma2 = [0.5, 0.5];
my @bandini = ($sma2);
while (@bandini < 10) {
push @bandini, compose_weights($sma2, $bandini[-1]);
}
foreach my $aref (@bandini) {
require Data::Dumper;
say Data::Dumper->new([$aref],['B'])->Indent(0)->Dump;
}
say scalar @{$bandini[-1]};
foreach my $aref (@bandini) {
require Data::Dumper;
$aref = [ map {$_*1024} @$aref ];
say Data::Dumper->new([$aref],['B'])->Indent(0)->Dump;
}
exit 0;
}
sub wma {
my ($N, $P) = @_;
my @coeffs = (1 .. $N);
my $total = List::Util::sum (@coeffs);
@coeffs = map {Math::BigRat->new("$_/$total")} @coeffs;
devel/ema-omitted-old.pl view on Meta::CPAN
package main;
#------------------------------------------------------------------------------
sub print_ma_terms {
my ($name) = @_;
print "$name\n";
my $term_proc = do { no strict; \&$name };
foreach my $k (0 .. 20) {
say " p[$k] * (@{[$term_proc->($k)]})";
}
}
my $poly_0 = Math::Polynomial->new;
# {
# say Math::Polynomial->new()->to_string_for_eval;
# say Math::Polynomial->new(1)->to_string_for_eval;
# say Math::Polynomial->new(-1)->to_string_for_eval;
# say Math::Polynomial->new(1,0)->to_string_for_eval;
# say Math::Polynomial->new(-1,0)->to_string_for_eval;
# say Math::Polynomial->new(-1,0,1)->to_string_for_eval;
# say Math::Polynomial->new(123,0,-456)->to_string_for_eval;
# say Math::Polynomial->new(-1,-1,-456)->to_string_for_eval;
# say Math::Polynomial->new(1,1,1,1,1)->to_string_for_eval;
# say Math::Polynomial->new(1,1,1,1,0)->to_string_for_eval;
# say Math::Polynomial->new(1,1,1,0,0)->to_string_for_eval;
# say Math::Polynomial->new(0,1,1,1,0,0)->to_string_for_eval;
# exit 0;
# }
# per Knuth vol 2 sect 4.3.3
sub interpolate_successive {
my $start = 0;
if (! ref $_[0] && $_[0] eq 'start') {
shift;
$start = shift;
}
devel/ema-omitted-old.pl view on Meta::CPAN
# $numerator = shift @nums;
# print "num ",$numerator,"\n";
# my $constant = pop(@y) / $numerator->eval($_);
# $result += $numerator * $constant;
# }
# return $result;
# }
{
say interpolate_successive(10, 304, 1980, 7084, 18526);
say interpolate_successive(0,1,4);
say interpolate_successive(1,2,3);
say interpolate_successive(1, 4, 9, 16);
my $triangle = sub {
my ($n) = @_;
return List::Util::sum (1 .. $n);
};
my $sum_squares = sub {
my ($n) = @_;
return List::Util::sum (map {$_**2} (1 .. $n));
};
my $yden = sub {
my ($n) = @_;
return $n * $sum_squares->($n) - ($triangle->($n))**2;
};
require Math::Polynomial;
require Math::BigRat;
Math::Polynomial->verbose(1);
Math::Polynomial->configure(VARIABLE => '$N');
my $poly = Math::Polynomial::interpolate (map {
($_, Math::BigRat->new(12 * $yden->($_)))} (1..10));
say "yfactor 1/12 * ($poly)";
$poly = Math::Polynomial::interpolate (map {
($_, 1*2*3*4*5*6*7*12 * $yden->($_))} (1..10));
say "yfactor 1/12 * ($poly)";
# print "\n\n";
# $poly = interpolate_faster (map {
# ($_, Math::BigRat->new(12 * $yden->($_)))} (1..10));
# say "yfactor 1/12 * ($poly)";
# print "\n\n";
# $poly = interpolate_successive (map {12 * $yden->($_)} (0..10));
# say "yfactor 1/12 * ($poly)";
# exit 0;
}
sub high_power {
my ($data) = @_;
my $power = 0;
my $deriv = 1;
for (;;) {
say "$power $deriv ",@$data;
if (List::MoreUtils::all {$_ == $data->[0]} @$data) {
return ($data->[0] / $deriv, $power);
}
$data = [ map {$data->[$_] - $data->[$_-1]} (1 .. $#$data) ];
$power++;
$deriv *= ($power + 1);
}
}
devel/ema-omitted-old.pl view on Meta::CPAN
#
# $term_proc->($k) should return a polynomial in f which is the coefficient
# of the f^k term. The created $weight_proc function simply adds them up.
#
sub make_weight_proc {
my ($term_proc) = @_;
my $weight_proc;
$weight_proc = memoize
(sub {
my ($k) = @_;
# say "weight_to_proc $k";
return $term_proc->($k) + ($k > 0 ? $weight_proc->($k-1) : $poly_0);
});
return $weight_proc;
}
# ema_weight_to($k) returns a polynomial in f which is the total weight of
# terms up to and including the p[k] input.
*ema_weight_to = make_weight_proc(\&ema_term);
say "ema_weight_to(4) ", ema_weight_to(4);
# ema_omitted_after($k) returns a polynomial in f which is the total weight
# omitted by stopping at (and including) the p[k] input.
sub ema_omitted_after {
my ($k) = @_;
return 1 - ema_weight_to($k);
}
say "ema_omitted_after(4) ",ema_omitted_after(4);
#------------------------------------------------------------------------------
print "\n\nEMA x 2\n";
use vars qw($a $b);
sub sum {
return List::Util::reduce {$a+$b} @_;
}
devel/ema-omitted-old.pl view on Meta::CPAN
# the result of smoothing $term_proc with an EMA.
#
sub ema_of_term_proc {
my ($term_proc) = @_;
return memoize
(sub {
my ($k) = @_;
# print "ema_of_term $k\n";
sum (map {
# ema_term($_) * $term_proc->($k-$_)
# say "T=", $term_proc->($k-$_);
# say "#=", ema_term($_);
# say "P ", ema_term($_) * $term_proc->($k-$_);
my $prod = $term_proc->($k-$_);
# say "N ", $prod;
$prod = -$prod; # now *(1-f)
$prod->mul1c (1); # *(f-1)
# say "M ", $prod;
push @$prod, (0)x$_; # *f^e
# say "X ", $prod;
$prod
} (0 .. $k));
});
}
# ema2_term() returns a polynomial in f=1-alpha which is the coefficient of
# the f^k term. This is simply (1-f)*f^k = 1*f^k + -1*f^(k+1).
*ema2_term = ema_of_term_proc(\&ema_term);
print_ma_terms ("ema2_term");
# ema2_term(0) == Math::Polynomial->new(-1,1) or die;
# ema2_term(1) == Math::Polynomial->new(-1,1,0) or die;
*ema2_weight_to = make_weight_proc(\&ema2_term);
say "ema2_weight_to(4) ", ema2_weight_to(4);
sub ema2_omitted_after {
my ($k) = @_;
return 1 - ema2_weight_to($k);
}
memoize 'ema2_omitted_after';
say "ema2_omitted_after(4) ",ema2_omitted_after(4);
# `omitted-fk' returns the coefficient (a number) of the f^(k+offset) term
# in the p[k] omitted polynomial of OMITTED-POLY-PROC. This is meant for
# finding closed-form expressions (a poly in k) for that f^(k+offset)
# coefficient.
#
# OMITTED-POLY-PROC returns a polynomial in f which is the weight omitted
# from some weighted average by stopping at (and including) the p[k] term.
#
sub omitted_fk {
my ($omitted_proc, $offset) = @_;
return memoize (sub {
my ($k) = @_;
# say "omitted_fk $omitted_proc $offset $k";
my $poly = $omitted_proc->($k);
my $i = $k+$offset;
if ($i > $poly->degree) {
return 0;
} else {
return $poly->coeff($i);
}
});
}
memoize('omitted_fk');
sub Xclosed_form {
my ($proc) = @_;
say "closed_form $proc";
my @data;
my @x = (20 .. 25);
foreach my $i (0 .. $#x) {
$data[$i] = $proc->($x[$i]);
}
}
sub closed_form {
my ($proc) = @_;
# my @data = map {
# ($_, Math::BigRat->new($proc->($_)))
# } (20 .. 30);
# print " interpolate_successive ...\n";
# return interpolate_successive (start => 20, @data);
return Math::Polynomial::interpolate (map {
# say $_;
# say $proc->($_);
(Math::BigRat->new ($_),
Math::BigRat->new($proc->($_)))
} (20 .. 30));
}
memoize 'closed_form';
sub omitted_fk_closed_form {
my ($name, $offset) = @_;
my $proc = do { no strict; \&$name };
my $poly = closed_form(omitted_fk($proc, $offset));
say "$name k+$offset ", $poly;
}
sub omitted_expr {
my ($name) = @_;
print "omitted_expr $name ...\n";
my $proc = do { no strict; \&$name };
my %a;
foreach my $offset (-8 .. 20) {
my $poly = closed_form(omitted_fk($proc, $offset));
$a{$offset} = $poly;
devel/ema-omitted-old.pl view on Meta::CPAN
while (my ($key, $value) = each %a) {
if ($value == 0) { delete $a{$key}; }
}
if (! %a) {
die "Oops, omitted_expr all zeros";
}
my $start = min(keys %a);
my $end = max(keys %a);
my $level = 1;
say "\$f ** ",offset_k_form($start);
foreach my $offset ($start .. $end) {
if ($offset != $start) {
say ' 'x$level, "+ (\$f # f^",offset_k_form($offset);
$level++;
}
my $poly = $a{$offset} // $poly_0;
say ' 'x$level, "* (", $poly->to_string_for_eval;
$level++;
}
say ' 'x$level,")"x$level;
}
sub offset_k_form {
my ($offset) = @_;
if ($offset == 0) {
return '$k';
} else {
return sprintf "(\$k%+d)", $offset;
}
}
devel/ema-omitted-old.pl view on Meta::CPAN
#------------------------------------------------------------------------------
print "\n\nEMA x 3\n";
# ema3_term() returns a polynomial in f=1-alpha which is the coefficient of
# the f^k term. This is simply (1-f)*f^k = 1*f^k + -1*f^(k+1).
*ema3_term = ema_of_term_proc(\&ema2_term);
print_ma_terms ("ema3_term");
*ema3_weight_to = make_weight_proc(\&ema3_term);
say "ema3_weight_to(4) ", ema3_weight_to(4);
sub ema3_omitted_after {
my ($k) = @_;
return 1 - ema3_weight_to($k);
}
memoize 'ema3_omitted_after';
say "ema3_omitted_after(4) ",ema3_omitted_after(4);
# omitted_fk_closed_form('ema3_omitted_after', 0);
# omitted_fk_closed_form('ema3_omitted_after', 1);
# omitted_fk_closed_form('ema3_omitted_after', 2);
# omitted_fk_closed_form('ema3_omitted_after', 3);
# omitted_fk_closed_form('ema3_omitted_after', 4);
omitted_expr('ema3_omitted_after');
#------------------------------------------------------------------------------
devel/ema-omitted-old.pl view on Meta::CPAN
Math::BigRat->new(0));
# poly equal to 1-$X
my $poly_1_minus_X = Math::Polynomial->new(Math::BigRat->new(-1),
Math::BigRat->new(1));
sub make_laguerre_for_ema {
my ($term_proc) = @_;
return memoize
(sub {
my ($k) = @_;
# say "make_laguerre_for_ema $k";
my $L0prev = ($k <= 0 ? $poly_0 : $term_proc->($k-1));
my $L0_times_f = $term_proc->($k) * $poly_X;
my $diff = $L0_times_f - $L0prev;
$diff->div1c (1); # (x-1) instead of (1-x)
# say "l done";
return $diff;
});
}
sub L0_term {
my ($k) = @_;
# say "L0_term $k";
if ($k < 0) {
return Math::BigRat->new(0);
} else {
return Math::Polynomial->new (Math::BigRat->new(-1),
Math::BigRat->new(1),
(0) x $k);
}
}
memoize 'L0_term';
print_ma_terms ('L0_term');
devel/ema-omitted-old.pl view on Meta::CPAN
sub laguerre_term {
my ($k) = @_;
return (L0_term($k) + 2*L1_term($k) + 2*L2_term($k) + L3_term($k))
/ 6;
}
memoize ('laguerre_term');
print_ma_terms ('laguerre_term');
*laguerre_weight_to = make_weight_proc(\&laguerre_term);
say "laguerre_weight_to(4) ", laguerre_weight_to(4);
sub laguerre_omitted_after {
my ($k) = @_;
# say "laguerre_omitted_after $k";
return 1 - laguerre_weight_to($k);
}
memoize 'laguerre_omitted_after';
say "laguerre_omitted_after(4) ",laguerre_omitted_after(4);
# omitted_fk_closed_form('laguerre_omitted_after', -2);
# omitted_fk_closed_form('laguerre_omitted_after', -1);
# omitted_fk_closed_form('laguerre_omitted_after', 0);
# omitted_fk_closed_form('laguerre_omitted_after', 1);
# omitted_fk_closed_form('laguerre_omitted_after', 2);
# omitted_fk_closed_form('laguerre_omitted_after', 3);
# omitted_fk_closed_form('laguerre_omitted_after', 4);
omitted_expr('laguerre_omitted_after');
devel/ema-omitted.pl view on Meta::CPAN
}
#------------------------------------------------------------------------------
sub print_ma_terms {
my ($name) = @_;
print "$name\n";
my $term_proc = do { no strict; \&$name };
foreach my $k (0 .. 20) {
say " p[$k] * (@{[$term_proc->($k)]})";
}
}
my $poly_0 = Math::Polynomial->new;
# per Knuth vol 2 sect 4.3.3
sub interpolate_successive {
my $start = 0;
if (! ref $_[0] && $_[0] eq 'start') {
shift;
devel/ema-omitted.pl view on Meta::CPAN
# $numerator = shift @nums;
# print "num ",$numerator,"\n";
# my $constant = pop(@y) / $numerator->eval($_);
# $result += $numerator * $constant;
# }
# return $result;
# }
{
say Math::Polynomial->new(1)->mul_root(1);
say Math::Polynomial->new(-1,1)->div_root(1);
say Math::Polynomial->new(1,1)->mul_root(1);
say interpolate_successive(10, 304, 1980, 7084, 18526);
say interpolate_successive(0,1,4);
say interpolate_successive(1,2,3);
say interpolate_successive(1, 4, 9, 16);
my $triangle = sub {
my ($n) = @_;
return List::Util::sum (1 .. $n);
};
my $sum_squares = sub {
my ($n) = @_;
return List::Util::sum (map {$_**2} (1 .. $n));
};
my $yden = sub {
devel/ema-omitted.pl view on Meta::CPAN
return $n * $sum_squares->($n) - ($triangle->($n))**2;
};
require Math::Polynomial;
require Math::BigRat;
# Math::Polynomial->configure(VARIABLE => '$N');
my $poly = Math::Polynomial->interpolate
([ 1 .. 10 ],
[ map {Math::BigRat->new(12 * $yden->($_))} (1..10)]);
# my $poly = Math::Polynomial::interpolate (map {
# ($_, Math::BigRat->new(12 * $yden->($_)))} (1..10));
say "yfactor 1/12 * ($poly)";
$poly = Math::Polynomial->interpolate
([ 1 .. 10],
[ map {1*2*3*4*5*6*7*12 * $yden->($_)} (1..10)]);
say "yfactor 1/12 * ($poly)";
# print "\n\n";
# $poly = interpolate_faster (map {
# ($_, Math::BigRat->new(12 * $yden->($_)))} (1..10));
# say "yfactor 1/12 * ($poly)";
# print "\n\n";
# $poly = interpolate_successive (map {12 * $yden->($_)} (0..10));
# say "yfactor 1/12 * ($poly)";
# exit 0;
}
sub high_power {
my ($data) = @_;
my $power = 0;
my $deriv = 1;
for (;;) {
say "$power $deriv ",@$data;
if (List::MoreUtils::all {$_ == $data->[0]} @$data) {
return ($data->[0] / $deriv, $power);
}
$data = [ map {$data->[$_] - $data->[$_-1]} (1 .. $#$data) ];
$power++;
$deriv *= ($power + 1);
}
}
devel/ema-omitted.pl view on Meta::CPAN
#
# $term_proc->($k) should return a polynomial in f which is the coefficient
# of the f^k term. The created $weight_proc function simply adds them up.
#
sub make_weight_proc {
my ($term_proc) = @_;
my $weight_proc;
$weight_proc = memoize
(sub {
my ($k) = @_;
# say "weight_to_proc $k";
return $term_proc->($k) + ($k > 0 ? $weight_proc->($k-1) : $poly_0);
});
return $weight_proc;
}
# ema_weight_to($k) returns a polynomial in f which is the total weight of
# terms up to and including the p[k] input.
*ema_weight_to = make_weight_proc(\&ema_term);
say "ema_weight_to(4) ", ema_weight_to(4);
# ema_omitted_after($k) returns a polynomial in f which is the total weight
# omitted by stopping at (and including) the p[k] input.
sub ema_omitted_after {
my ($k) = @_;
return 1 - ema_weight_to($k);
}
say "ema_omitted_after(4) ",ema_omitted_after(4);
#------------------------------------------------------------------------------
print "\n\nEMA x 2\n";
use vars qw($a $b);
sub sum {
return List::Util::reduce {$a+$b} @_;
}
devel/ema-omitted.pl view on Meta::CPAN
sub ema_of_term_proc {
my ($term_proc) = @_;
return memoize
(sub {
my ($k) = @_;
# print "ema_of_term $k\n";
my $_1_f = Math::Polynomial->new (1, -1); # 1-f
sum (map {
# ema_term($_) * $term_proc->($k-$_)
# say "T=", $term_proc->($k-$_);
# say "#=", ema_term($_);
# say "P ", ema_term($_) * $term_proc->($k-$_);
my $i = $_;
my $prod = $term_proc->($k-$i);
# say "N ", $prod;
$prod <<= $i; # *f^e
# say "NP ", $prod;
$prod *= $_1_f; # *(1-f)*f^e
# say "X ", $prod;
$prod
} (0 .. $k));
});
}
# ema2_term() returns a polynomial in f=1-alpha which is the coefficient of
# the f^k term. This is simply (1-f)*f^k = 1*f^k + -1*f^(k+1).
*ema2_term = ema_of_term_proc(\&ema_term);
print_ma_terms ("ema2_term");
# ema2_term(0) == Math::Polynomial->new(-1,1) or die;
# ema2_term(1) == Math::Polynomial->new(-1,1,0) or die;
*ema2_weight_to = make_weight_proc(\&ema2_term);
say "ema2_weight_to(4) ", ema2_weight_to(4);
sub ema2_omitted_after {
my ($k) = @_;
return 1 - ema2_weight_to($k);
}
memoize 'ema2_omitted_after';
say "ema2_omitted_after(4) ",ema2_omitted_after(4);
# `omitted-fk' returns the coefficient (a number) of the f^(k+offset) term
# in the p[k] omitted polynomial of OMITTED-POLY-PROC. This is meant for
# finding closed-form expressions (a poly in k) for that f^(k+offset)
# coefficient.
#
# OMITTED-POLY-PROC returns a polynomial in f which is the weight omitted
# from some weighted average by stopping at (and including) the p[k] term.
#
sub omitted_fk {
my ($omitted_proc, $offset) = @_;
return memoize (sub {
my ($k) = @_;
# say "omitted_fk $omitted_proc $offset $k";
my $poly = $omitted_proc->($k);
my $i = $k+$offset;
if ($i > $poly->degree) {
return 0;
} else {
return $poly->coeff($i);
}
});
}
memoize('omitted_fk');
sub Xclosed_form {
my ($proc) = @_;
say "closed_form $proc";
my @data;
my @x = (20 .. 25);
foreach my $i (0 .. $#x) {
$data[$i] = $proc->($x[$i]);
}
}
sub closed_form {
my ($proc) = @_;
devel/ema-omitted.pl view on Meta::CPAN
# my @data = map {
# ($_, Math::BigRat->new($proc->($_)))
# } (20 .. 30);
# print " interpolate_successive ...\n";
# return interpolate_successive (start => 20, @data);
my @xs = (20 .. 30);
return Math::Polynomial->interpolate
(\@xs,
[ map {
# say $_;
# say $proc->($_);
Math::BigRat->new($proc->($_)) } @xs]);
}
memoize 'closed_form';
sub omitted_fk_closed_form {
my ($name, $offset) = @_;
my $proc = do { no strict; \&$name };
my $poly = closed_form(omitted_fk($proc, $offset));
say "$name k+$offset ", $poly;
}
sub omitted_expr {
my ($name) = @_;
print "omitted_expr $name ...\n";
my $proc = do { no strict; \&$name };
my %a;
foreach my $offset (-8 .. 20) {
my $poly = closed_form(omitted_fk($proc, $offset));
$a{$offset} = $poly;
devel/ema-omitted.pl view on Meta::CPAN
while (my ($key, $value) = each %a) {
if ($value == 0) { delete $a{$key}; }
}
if (! %a) {
die "Oops, omitted_expr all zeros";
}
my $start = min(keys %a);
my $end = max(keys %a);
my $level = 1;
say "\$f ** ",offset_k_form($start);
foreach my $offset ($start .. $end) {
if ($offset != $start) {
say ' 'x$level, "+ (\$f # f^",offset_k_form($offset);
$level++;
}
my $poly = $a{$offset} // $poly_0;
say ' 'x$level, "* (", Math::Polynomial::Horner::as_string($poly);
$level++;
}
say ' 'x$level,")"x$level;
}
sub offset_k_form {
my ($offset) = @_;
if ($offset == 0) {
return '$k';
} else {
return sprintf "(\$k%+d)", $offset;
}
}
devel/ema-omitted.pl view on Meta::CPAN
#------------------------------------------------------------------------------
print "\n\nEMA x 3\n";
# ema3_term() returns a polynomial in f=1-alpha which is the coefficient of
# the f^k term. This is simply (1-f)*f^k = 1*f^k + -1*f^(k+1).
*ema3_term = ema_of_term_proc(\&ema2_term);
print_ma_terms ("ema3_term");
*ema3_weight_to = make_weight_proc(\&ema3_term);
say "ema3_weight_to(4) ", ema3_weight_to(4);
sub ema3_omitted_after {
my ($k) = @_;
return 1 - ema3_weight_to($k);
}
memoize 'ema3_omitted_after';
say "ema3_omitted_after(4) ",ema3_omitted_after(4);
# omitted_fk_closed_form('ema3_omitted_after', 0);
# omitted_fk_closed_form('ema3_omitted_after', 1);
# omitted_fk_closed_form('ema3_omitted_after', 2);
# omitted_fk_closed_form('ema3_omitted_after', 3);
# omitted_fk_closed_form('ema3_omitted_after', 4);
omitted_expr('ema3_omitted_after');
#------------------------------------------------------------------------------
devel/ema-omitted.pl view on Meta::CPAN
Math::BigRat->new(1));
# poly equal to 1-$X
my $poly_1_minus_X = Math::Polynomial->new(Math::BigRat->new(1),
Math::BigRat->new(-1));
sub make_laguerre_for_ema {
my ($term_proc) = @_;
return memoize
(sub {
my ($k) = @_;
# say "make_laguerre_for_ema $k";
my $L0prev = ($k <= 0 ? $poly_0 : $term_proc->($k-1));
my $L0_times_f = $term_proc->($k) * $poly_X;
my $diff = $L0_times_f - $L0prev;
# $diff = $diff->div1c (1); # (x-1) instead of (1-x)
$diff = $diff->div_root (1); # (x-1) instead of (1-x)
# say "l done";
return $diff;
});
}
sub L0_term {
my ($k) = @_;
# say "L0_term $k";
if ($k < 0) {
return Math::BigRat->new(0);
} else {
return Math::Polynomial->new ((0) x $k,
Math::BigRat->new(1),
Math::BigRat->new(-1));
}
}
memoize 'L0_term';
print_ma_terms ('L0_term');
devel/ema-omitted.pl view on Meta::CPAN
sub laguerre_term {
my ($k) = @_;
return (L0_term($k) + 2*L1_term($k) + 2*L2_term($k) + L3_term($k))
/ 6;
}
memoize ('laguerre_term');
print_ma_terms ('laguerre_term');
*laguerre_weight_to = make_weight_proc(\&laguerre_term);
say "laguerre_weight_to(4) ", laguerre_weight_to(4);
sub laguerre_omitted_after {
my ($k) = @_;
# say "laguerre_omitted_after $k";
return 1 - laguerre_weight_to($k);
}
memoize 'laguerre_omitted_after';
say "laguerre_omitted_after(4) ",laguerre_omitted_after(4);
# omitted_fk_closed_form('laguerre_omitted_after', -2);
# omitted_fk_closed_form('laguerre_omitted_after', -1);
# omitted_fk_closed_form('laguerre_omitted_after', 0);
# omitted_fk_closed_form('laguerre_omitted_after', 1);
# omitted_fk_closed_form('laguerre_omitted_after', 2);
# omitted_fk_closed_form('laguerre_omitted_after', 3);
# omitted_fk_closed_form('laguerre_omitted_after', 4);
omitted_expr('laguerre_omitted_after');
devel/run-about.pl view on Meta::CPAN
use warnings;
use Gtk2 '-init';
use App::Chart;
use App::Chart::Gtk2::AboutDialog;
use FindBin;
my $progname = $FindBin::Script;
use Data::Dumper;
print "$progname: ",Data::Dumper->Dump([\%INC],['INC']);
say "$progname: App::Chart loaded from $INC{'App/Chart.pm'}";
my $toplevel = Gtk2::Window->new;
$toplevel->show_all;
App::Chart::Gtk2::AboutDialog->new->present;
# my $about = App::Chart::Gtk2::AboutDialog->instance;
# my $about = App::Chart::Gtk2::AboutDialog->instance_for_screen ($toplevel);
# $about->signal_connect (destroy => sub {
# say "$progname: dialog destroy, do main_quit()";
# Gtk2->main_quit;
# });
Gtk2->main;
say "$progname: instance() is ", App::Chart::Gtk2::AboutDialog->instance;
exit 0;
devel/run-raw-dialog.pl view on Meta::CPAN
$raw_dialog->signal_connect (destroy => sub { Gtk2->main_quit; });
App::Chart::chart_dirbroadcast()->listen;
Gtk2->main;
$raw_dialog->destroy;
require Scalar::Util;
Scalar::Util::weaken ($raw_dialog);
if ($raw_dialog) {
say "$progname: oops, raw_dialog not finalized by weakening";
if (eval { require Devel::FindRef }) {
print Devel::FindRef::track($raw_dialog);
} else {
say "Devel::FindRef not available -- $@";
}
} else {
say "$progname: raw_dialog destroyed by weakening ok";
}
exit 0;
devel/run-watchlist.pl view on Meta::CPAN
# connect to "unmap" here in case hide-on-delete, not destroy
$watchlist->signal_connect (unmap => sub { Gtk2->main_quit });
App::Chart::chart_dirbroadcast()->listen;
Gtk2->main;
$watchlist->destroy;
require Scalar::Util;
Scalar::Util::weaken ($watchlist);
if ($watchlist) {
say "$progname: oops, watchlist not finalized by weakening";
if (eval { require Devel::FindRef }) {
print Devel::FindRef::track($watchlist);
} else {
say "Devel::FindRef not available -- $@";
}
} else {
say "$progname: watchlist destroyed by weakening ok";
}
exit 0;
doc/chart.texi view on Meta::CPAN
The order of the lists controls how they appear in the Open dialog
(@pxref{Open}) and the sequence for Next and Prev in the main display. You
can drag rows to re-order.
@item Colours
Each line is shown in green for a last trade higher than yesterday's close,
red for lower, or black unchanged. Blue means a refresh download is in
progress.
@item Bid/Offer Column
The bid/offer column is normally shown as say @samp{2.10/2.12}, but when the
market is crossed (ie.@: bid higher than offer) an ``x'' is used to highlight
this, for example @samp{2.20x1.99}. What that means depends on the exchange,
it might be a pre-open auction, or merely transient.
@item Volume Column
Volume is abbreviated @samp{k} for thousands, @samp{m} for millions, @samp{b}
for billions. This is number of shares (or number of contracts), the same as
shown in the main chart.
@item When Column
lib/App/Chart.pm view on Meta::CPAN
foreach my $inc (@INC) {
my $filename = File::Spec->catfile ($inc, 'App', 'Chart', @_);
if (-e $filename) { return $filename; }
}
require File::Basename;
return File::Spec->catfile (File::Basename::dirname($INC{'App/Chart.pm'}),
'Chart', @_);
}
# return true if range ($alo,$ahi) overlaps range ($blo,$bhi)
# each endpoint is taken as inclusive, so say (1,4) and (4,7) do overlap
#
sub overlap_inclusive_p {
my ($alo, $ahi, $blo, $bhi) = @_;
return ! ($ahi < $blo || $alo > $bhi);
}
1;
__END__
=head1 NAME
lib/App/Chart/Barchart.pm view on Meta::CPAN
# @c
# @c @uref{http://www.sgx.com}
# @c
# @c @cindex @code{.SIMEX}
# @c SIMEX is the derivatives arm of the Singapore Stock Exchange. SIMEX symbols
# @c have a @samp{.SIMEX} suffix, for example @samp{NK.SIMEX} for Nikkei 225
# @c futures.
# @c @c SYMBOL: NK.SIMEX
# @c
# @c @c The terms and conditions at www.sgx.com (the last of the ``useful links''
# @c @c at the right hand side of the home page) say linking is allowed but not
# @c @c deep linking is not allowed. Dunno what that means, maybe it's nothing
# @c @c except the home page, though if that were the case you'd think it would
# @c @c say that. In any case give directions instead of links.
# @c @c
# @c @c (Prohibitions on publishing the URL of something already freely accessible
# @c @c seem pretty dubious, though it's not some passive object, but somebody
# @c @c else's computer, and is more or less an invitation to use that in a way
# @c @c they don't want, which would be at best highly irresponsible.)
# @c @c
# @c Symbols can be found on the contract specifications pages. On the home page
# @c under ``Products and Services'' choose ``Derivatives'' then either the
# @c ``Equity Index Futures / Options'' or ``Interest Rate Futures / Options''
# @c items. Those two pages then have selection boxes to see each contract.
lib/App/Chart/Download.pm view on Meta::CPAN
$latest_changed{$symbol} = 1;
}
next;
}
# For symbols not in the database, if the newest daily is >= latest quote
# then replace that quote with the daily.
#
# Times in the latest record are not considered, so it's possible a
# quote taken after close of trading will be deleted or overwritten.
# Would want something in the latest to say it's after the close ...
my $latest_get_sth = $dbh->prepare_cached
('SELECT last_date, name FROM latest WHERE symbol=?');
my ($last_date, $name, $dividend)
= $dbh->selectrow_array ($latest_get_sth, undef, $symbol);
if (defined $last_date && $last_date gt $date) { next; }
# "name" from the daily, or retain name from existing latest record.
$name = $h->{'names'}->{$symbol} // $name;
lib/App/Chart/DownloadHandler/IndivInfo.pm view on Meta::CPAN
# key => 'Foo-info',
# recheck_days => 10);
#
# =head1 DESCRIPTION
#
# This module downloads and processes information for a given symbol,
# such as the name. Info is re-checked at intervals of a given
# number of days.
#
# This is for use when information is a separate download for each
# symbol (rather than say a single big download of many symbols).
#
# C<url_func> is a function which returns a URL (a string),
#
# sub my_url {
# my ($symbol) = @_;
# return "http://example.com/info/$symbol";
# }
#
# C<parse> is a function which returns a C<write_daily_group()> style
# hashref,
lib/App/Chart/Gtk2/Ex/ListStore/DragByCopy.pm view on Meta::CPAN
# really should have a way to say what kinds of models are compatible
# - same num columns
# - same class, or subclass
# drop text to one column ...
# Copyright 2008, 2009, 2010 Kevin Ryde
# This file is part of Chart.
#
# Chart is free software; you can redistribute it and/or modify
lib/App/Chart/Series.pm view on Meta::CPAN
# Return (LOWER UPPER) which is a suggested initial Y-axis page range to
# show for dates LO to HI. This is for use both with
# App::Chart::Series::OHLCVI and also any other series type without its own
# specific style.
#
# As described in "Main Window" in the manual, the aim is to scale according
# to apparent volatility, so that daily range or daily close-to-close change
# are some modest fraction of the initial page. In particular if the series
# is just going sideways it's not zoomed out to try to fill the whole
# screen. The absolute price level is not used, so say bond prices which
# hover near 100 still get scaled out to make typical daily changes of 0.1
# or whatever visible.
#
sub initial_range {
my ($self, $lo, $hi) = @_;
### Series initial_range: "$lo to $hi $self"
$lo = max ($lo, 0);
$hi = max ($hi, 0);
$self->fill ($lo, $hi);
my $highs = $self->array('highs') // [];
lib/App/Chart/Suffix/RBA.pm view on Meta::CPAN
my $sheet = $excel->Worksheet (0);
### SheetCount: $excel->{'SheetCount'}
### Name: $sheet->{'Name'}
my ($minrow, $maxrow) = $sheet->RowRange;
my ($mincol, $maxcol) = $sheet->ColRange;
### rows: $minrow, $maxrow
### cols: $mincol, $maxcol
# heading row repeats the filename "F11HIST.XLS" and then the currencies
# in columns as say "FXRJY"
my $heading_row = List::Util::first {
my $cell = $sheet->Cell($_,$mincol);
$cell && $cell->Value eq 'F11HIST.XLS' }
($minrow .. $maxrow)
or die "RBA monthly: headings not found";
### $heading_row
my @currencies = map {
my $cell = $sheet->Cell($heading_row,$_);
my $currency = $cell ? $cell->Value : '';
lib/App/Chart/Suffix/SIMEX.pm view on Meta::CPAN
use App::Chart::Suffix::SI;
my $pred = App::Chart::Sympred::Suffix->new ('.SIMEX');
$App::Chart::Suffix::SI::timezone_singapore->setup_for_symbol ($pred);
# barchart for database and for intraday graphs
$App::Chart::Barchart::intraday_pred->add ($pred);
$App::Chart::Barchart::fiveday_pred->add ($pred);
# FIXME: dunno what delay for simex, www.sgx.com says its quotes are
# delayed, but doesn't seem to say be how much
#
# App::Chart::Barchart::setup_quote_delay ($pred, 20);
App::Chart::Barchart::commodity_mung
($pred,
# equity index futures
'NK' => 'NX', # nikkei 225
'N3' => 'VN', # nikkei 300
#
# 'JP' MSCI Japan seems to be missing from barchart, it looks
lib/App/Chart/Timebase.pm view on Meta::CPAN
example if C<$from_timebase> is years but the destination C<$timebase> is
months then C<floor> gives the first month (ie. January) in the C<$from_t>
year and C<ceil> gives the last month (ie. December).
=item $timebase->strftime ($format, $t)
Return an C<strftime> formatted string which is timebase value C<$t> (an
integer) under C<$format>. For example,
$timebase->strftime ('%d %b %Y', $t)
# gives say "31 December 2007"
=item $timebase->today ()
=item $timebase->today ($timezone)
Return today's date as an integer in C<$timebase>. The optional
C<$timezone> is a C<App::Chart::TZ> object to use, or the default is
local time.
=item C<< $timebase->adjective() >>
lib/App/Chart/doc/chart.html view on Meta::CPAN
can drag rows to re-order.
</p>
</dd>
<dt>Colours</dt>
<dd><p>Each line is shown in green for a last trade higher than yesterday’s close,
red for lower, or black unchanged. Blue means a refresh download is in
progress.
</p>
</dd>
<dt>Bid/Offer Column</dt>
<dd><p>The bid/offer column is normally shown as say ‘<samp class="samp">2.10/2.12</samp>’, but when the
market is crossed (ie. bid higher than offer) an “x” is used to highlight
this, for example ‘<samp class="samp">2.20x1.99</samp>’. What that means depends on the exchange,
it might be a pre-open auction, or merely transient.
</p>
</dd>
<dt>Volume Column</dt>
<dd><p>Volume is abbreviated ‘<samp class="samp">k</samp>’ for thousands, ‘<samp class="samp">m</samp>’ for millions, ‘<samp class="samp">b</samp>’
for billions. This is number of shares (or number of contracts), the same as
shown in the main chart.
</p>
misc/t-barchart.pl view on Meta::CPAN
require HTTP::Request;
my $req = HTTP::Request->new ('GET', $req_url);
my $resp = HTTP::Response->new(200, 'OK');
$resp->request ($req);
my $content = slurp(<~/chart/samples/barchart/chart.php-daily.html>);
$resp->content($content);
$resp->content_type('application/x-javascript');
my $img_url = App::Chart::Barchart::intraday_resp_to_url ($resp, 'XYZ');
say $img_url;
exit 0;
}
{
my $url = 'http://www.barchart.com/detailedquote/futures/CLZ10';
require URI;
my $uri = URI->new($url);
misc/t-barchart.pl view on Meta::CPAN
}
{
my $resp = HTTP::Response->new(200, 'OK');
# my $content = slurp(<~/chart/samples/barchart/chart.asp.html>);
my $content = slurp(<~/chart/samples/barchart/chart-no-chart.html>);
$resp->content($content);
$resp->content_type('application/x-javascript');
my $url = App::Chart::Barchart::intraday_resp_to_url ($resp, 'XYZ');
say $url;
exit 0;
}
{
my $resp = HTTP::Response->new(200, 'OK');
my $content = slurp(<~/chart/samples/barchart/ifutpage-NX.asp.html>);
$resp->content($content);
$resp->content_type('text/html');
my $h = App::Chart::Barchart::ifutpage_parse ('NX', '.SIMEX', $resp);
$h->{'resp'} = '...';
print Dumper ($h);
misc/t-fq.pl view on Meta::CPAN
my $progname = $FindBin::Script;
{
require Module::Find;
require Module::Load;
require Data::Dumper;
my %method_to_modules;
foreach my $module (Module::Find::findsubmod ('Finance::Quote')) {
say $module;
next if ($module =~ /UserAgent$/);
Module::Load::load ($module);
my %method_to_func = $module->methods;
my @methods = keys %method_to_func;
print " ", Data::Dumper->Dump([\@methods],['sources']);
$module =~ s/^Finance::Quote:://;
foreach my $method (@methods) {
push @{$method_to_modules{$method}}, $module;
misc/t-fq.pl view on Meta::CPAN
exit 0;
}
{
# require Finance::Quote;
# my $q = Finance::Quote->new ('-defaults', 'MLC');
# my $sources = $q->sources;
# print Data::Dumper->new([$sources],['sources'])->Sortkeys(1)->Dump;
say "$progname: ", App::Chart::Suffix::FQ::quoter_for_method('tsp');
exit 0;
}
{
say "$progname: ", App::Chart::Suffix::FQ::method_to_modules('asx');
}
{
require Finance::Quote;
my $q = Finance::Quote->new;
my %rates = $q->fetch ('xyz','BHP');
print Data::Dumper->new([\%rates],['rates'])->Sortkeys(1)->Dump;
exit 0;
misc/t-gui.pl view on Meta::CPAN
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
use 5.010;
use strict;
use warnings;
use App::Chart::Gtk2::GUI;
{
require Module::Util;
say Module::Util::find_installed('App::Chart::Gtk2::GUI');
say Module::Util::find_installed('App::Chart::chart.xpm');
exit 0;
}
{
require Module::Find;
exit 0;
}
misc/t-indicator-combo.pl view on Meta::CPAN
{
my $combobox = App::Chart::Gtk2::IndicatorComboBox->new (type => 'average');
$vbox->pack_start ($combobox, 0,0,0);
$combobox->signal_connect
(notify => sub {
my ($combobox, $pspec) = @_;
my $pname = $pspec->get_name;
my $value = $combobox->get($pname);
say "$progname: combo $pname changed to ",($value//'undef');
});
# $combobox->set_key ('TA_HT_DCPERIOD');
}
{
my $combobox = App::Chart::Gtk2::IndicatorComboBox->new (type => 'indicator');
$vbox->pack_start ($combobox, 0,0,0);
$combobox->signal_connect
(notify => sub {
my ($combobox, $pspec) = @_;
my $pname = $pspec->get_name;
my $value = $combobox->get($pname);
say "$progname: combo $pname changed to ",($value//'undef');
});
}
$toplevel->show_all;
Gtk2->main;
misc/t-indicator-info.pl view on Meta::CPAN
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
use strict;
use warnings;
use 5.010;
use App::Chart::IndicatorInfo;
use Data::Dumper;
foreach my $key ('SMA', 'GT_SMA', 'GT_BOL', 'TA_SMA', 'TA_BBANDS', 'TA_PPO') {
say $key;
my $info = App::Chart::IndicatorInfo->new ($key);
print Data::Dumper->Dump([$info],['info']);
my $module = $info->module;
print Data::Dumper->Dump([$module],['module']);
my $manual = $info->manual;
print Data::Dumper->Dump([$manual],['manual']);
my $params = $info->parameter_info;
misc/t-series.pl view on Meta::CPAN
# my $dates = $series->dates;
# print Dumper (\$dates);
exit 0;
}
{
require App::Chart::Gtk2::SeriesModel;
my $series = App::Chart::Series::Database->new('000001.SS');
my $model = App::Chart::Gtk2::SeriesModel->new (series => $series);
my $iter = $model->get_iter_first;
say $model->get($iter,$model->COL_DATE);
say $model->get($iter,$model->COL_OPEN);
say $model->get($iter,$model->COL_CLOSE);
say $model->get($iter,$model->COL_VOLUME) // 'undef';
$series->fill(0,0);
my $volumes = $series->array('volumes');
say $volumes->[0] // 'undef';
exit 0;
}
{
my $series = App::Chart::Series::Database->new('BHP.AX');
my $adj = $series->Adjust(adjust_dividends=>1);
print Dumper($adj);
my $hi = $adj->hi;
print "hi $hi\n";
misc/t-ticker.pl view on Meta::CPAN
$ticker->signal_connect (menu_popup => sub {
print "$progname: menu-popup action signal runs\n";
});
$ticker->signal_connect (menu_popup => sub {
print "$progname: menu-popup action signal runs more\n";
});
print "$progname: get_name ",$ticker->get_name//'undef',"\n";
{ local $,=' '; print "$progname: class_path ",$ticker->class_path,"\n"; }
{ my @sigs = Glib::Type->list_signals (ref($ticker));
print "$progname: signals: ";
local $,=' '; say map {$_->{'signal_name'}} @sigs;
}
# use Data::Dumper;
# print Dumper($ticker);
# { my $req = $ticker->size_request;
# print $req->width,"x",$req->height,"\n";
# }
# $ticker->queue_resize;
# { my $req = $ticker->size_request;
t/Heading.t view on Meta::CPAN
return $toplevel;
},
destructor => \&Test::Weaken::Gtk2::destructor_destroy,
contents => \&Test::Weaken::Gtk2::contents_container,
});
is ($leaks, undef, 'Test::Weaken deep garbage collection');
if ($leaks) {
diag "Test-Weaken ", explain $leaks;
my $unfreed = $leaks->unfreed_proberefs;
say "unfreed isweak ",
(Scalar::Util::isweak ($unfreed->[0]) ? "yes" : "no");
foreach my $proberef (@$unfreed) {
diag " unfreed $proberef";
}
foreach my $proberef (@$unfreed) {
diag " search $proberef";
MyTestHelpers::findrefs($proberef);
}
}
}
xt/0-META-read.t view on Meta::CPAN
use lib 't';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings(); }
# When some of META.yml is generated by explicit text in Makefile.PL it can
# be easy to make a mistake in the syntax, or indentation, etc, so the idea
# here is to check it's readable from some of the YAML readers.
#
# The various readers differ in how strictly they look at the syntax.
# There's no attempt here to say one of them is best or tightest or
# whatever, just see that they all work.
#
# See 0-Test-YAML-Meta.t for Test::YAML::Meta which looks into field
# contents, as well as maybe the YAML formatting.
my $meta_filename;
# allow for ancient perl, maybe
eval { require FindBin; 1 } # new in 5.004
or plan skip_all => "FindBin not available -- $@";
eval { require File::Spec; 1 } # new in 5.005