App-Chart

 view release on metacpan or  search on metacpan

unused/CommSec.pm  view on Meta::CPAN

# Chart is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3, or (at your option) any later version.
#
# Chart is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Chart.  If not, see <http://www.gnu.org/licenses/>.

package App::Chart::CommSec;
use 5.008;
use strict;
use warnings;
use Carp;
use Date::Calc;
use File::Basename;
use List::Util;
use Locale::TextDomain ('App-Chart');

use App::Chart;
use App::Chart::Database;
use App::Chart::Download;
use App::Chart::DownloadCost;
use App::Chart::DownloadHandler;
use App::Chart::Sympred;
use App::Chart::Timebase::Months;
use App::Chart::TZ;


my $pred = App::Chart::Sympred::Proc->new (\&is_commsec_symbol);
sub is_commsec_symbol {
  my ($symbol) = @_;
  if (! is_enabled()) { return 0; }
  no warnings 'once';
  require App::Chart::Suffix::AX;
  return $App::Chart::Suffix::AX::pred_shares->match ($symbol);
}
sub is_enabled {
  return App::Chart::Database->preference_get ('commsec-enable');
}
# use App::Chart::Memoize::ConstSecond 'is_enabled';


#-----------------------------------------------------------------------------
# download
#
# The download chooses between
#    - commsec whole-day update files
#    - commsec individual update files
#
# To update many ASX shares the whole-day files are best, or for just a few
# then the individual files are best.  A mixture is used too, if there's a
# few symbols that are quite a bit behind then they'll be done
# individually, and the balance with whole-day.
#
# The main problem with the whole-day file is how many entries it has,
# about 4500 as of Jan 2007.  There's about 1600 companies (a lot of them
# small caps), the rest is warrants on the majors, and a few prefs or bonds
# on various.

App::Chart::DownloadHandler->new
  (name            => __('CommSec'),
   pred            => $pred,
   available_tdate => \&available_tdate,
   proc            => \&download,
   priority        => 10);

# today's data available after 10:30pm weekdays, Sydney time
sub available_tdate {
  App::Chart::Download::tdate_today_after
      (22,30, App::Chart::TZ->sydney);
}

use constant { INDIV_PERMONTH_COST_KEY => 'commsec-indiv',
               INDIV_PERMONTH_COST_DEFAULT => 1300,
               WHOLEDAY_COST_KEY => 'commsec-wholeday' };

sub download {
  my ($symbol_list) = @_;
  App::Chart::Download::status (__('CommSec strategy'));

  my $avail = available_tdate();

  require App::Chart::DownloadCost;
  my ($whole_tdate, @indiv_list) = App::Chart::DownloadCost::by_day_or_by_symbol
    (available_tdate  => $avail,
     symbol_list      => $symbol_list,
     indiv_cost_proc  => \&indiv_cost_proc,
     whole_cost_key     => WHOLEDAY_COST_KEY,
     whole_cost_default => 259867); # May 2008

  App::Chart::Download::verbose_message
      (__x('CommSec whole days from {date} after indiv {symbols}',
           date => App::Chart::tdate_to_iso($whole_tdate),
           symbols => join(' ', @indiv_list)));

  foreach my $symbol (@indiv_list) { indiv_download ($symbol); }
  wholeday_download ($whole_tdate, $avail);
}

#------------------------------------------------------------------------------
# download - by each symbol
#
# This uses the download of all data for a symbol like
#

my @indiv_months_list = ([1,   '1mo' ],
                         [2,   '2mo' ],
                         [3,   '3mo' ],
                         [6,   '6mo' ],
                         [12,  '1yr' ],
                         [24,  '2yr' ],
                         [36,  '3yr' ],
                         [48,  '4yr' ],
                         [60,  '5yr' ],
                         [120, '10yr']);

sub indiv_download {



( run in 1.189 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )