App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Suffix/TGE.pm  view on Meta::CPAN


use App::Chart::Glib::Ex::MoreUtils;
use App::Chart;
use App::Chart::DownloadHandler;
use App::Chart::Sympred;
use App::Chart::TZ;
use App::Chart::Weblink;


my $pred = App::Chart::Sympred::Suffix->new ('.TGE');
App::Chart::TZ->tokyo->setup_for_symbol ($pred);
# (source-help! tge-symbol?
# 	     __p('manual-node','Tokyo Grain Exchange'))



#-----------------------------------------------------------------------------
# weblinks - contract specs
#
# eg. http://www.tge.or.jp/japanese/contract/cont_s_corn.shtml
#     http://www.tge.or.jp/english/contract/cont_s_soym.shtml
#

my %commodity_to_weblink = ('CO' => 'corn',  # Corn
                            'SM' => 'soym',  # Soybean Meal
                            'SB' => 'soy',   # Soybean
                            'NG' => 'gmo',   # Non-GMO Soybean
                            'RB' => 'azuki', # Azuki
                            'AC' => 'ara',   # Arabica Coffee
                            'RC' => 'rob',   # Robusta Coffee
                            'SG' => 'raw',   # Raw Sugar
                            'SL' => 'silk',  # Raw Silk
                            'VG' => 'vege'); # Vegetables

App::Chart::Weblink->new
  (pred => $pred,
   name => __('TGE _Contract Specifications'),
   desc => __('Open web browser at the Tokyo Grain Exchange contract specifications for this commodity'),
   proc => sub {
     my ($symbol) = @_;
     my $commodity = App::Chart::symbol_commodity ($symbol);
     my $code = $commodity_to_weblink{$commodity} || return undef;
     my $lang = App::Chart::Glib::Ex::MoreUtils::lang_select (ja => 'japanese',
                                                  en => 'english');
     return "http://www.tge.or.jp/$lang/contract/cont_s_$code.shtml";
   });

#-----------------------------------------------------------------------------
# misc

# return ISO date string of last trading for SYMBOL, or possibly a day or
# two after (because public holidays are not accounted for)
#
sub symbol_expiry {
  my ($symbol) = @_;
  my $mdate = symbol_mdate($symbol) // return undef;

  my $commodity = App::Chart::symbol_commodity ($symbol);
  # if ($commodity eq 'CO') {
  #     # corn
  #     # 15th calendar day of the month preceding the delivery month
  #     #       (receive-list (year month day)
  #     #        (mdate->ymd mdate)
  #     #        (ymd->tdate year (1- month) 15)))
  #   }
  #   when (['NG','RB','SB']) {
  #     # non-gm soybeans, azuki
  #     # 2 business days prior to delivery day; delivery day
  #     # is the business day prior to the last business day of
  #     # the delivery month or 24th for December
  #     #     (receive-list (year month day)
  #     #      (mdate->ymd mdate)
  #     #      (- (if (= 12 month)
  #     #          (ymd->tdate year month 24)
  #     #          (- (mdate->tdate (1+ mdate)) 2))
  #     #       2))
  #   }
  #   when (['NG','RB','SB']) {
  #     # arabica, robusta, soybean meal
  #     # 10 business days prior to the last business day of
  #     # the delivery month
  #     #     (- (mdate->tdate (1+ mdate)) 11)
  #   }
  #   when ('SG') {
  #     # raw sugar
  #     # last business day two months prior to delivery month
  #     #    (1- (mdate->tdate (1- mdate))))
  #   }
  #   default {
  #     # unknown, lets guess the last day of the contract month,
  #     # this won't be right but at least won't be early
  #     #       (1- (mdate->tdate (1+ mdate))))))
  #   }
  # }

  # FIXME:
  return undef;
}

# see table in http://www.tge.or.jp/japanese/price/prisel.js.php
# ENHANCE-ME: maybe download and parse that page
my %commodity_to_nav
  = ('CO' => 'tou',  # corn
     'SM' => 'dai',  # soybean meal
     'SB' => 'ipd',  # soybeans
     'NG' => 'ngd',  # non-gmo soybeans
     'RB' => 'azu',  # azuki
     'AC' => 'ara',  # arabica coffee
     'RC' => 'rob',  # robusta coffee
     'SG' => 'sot',  # raw sugar
     'SL' => 'rsl',  # raw silk
     'VG' => 'veg'); # vegetables

#-----------------------------------------------------------------------------
# download
#
# This uses the "download" under the price data page
#
#     http://www.tge.or.jp/english/price/pri_sel_01.shtml
#
# There's two files for each commodity,



( run in 1.286 second using v1.01-cache-2.11-cpan-39bf76dae61 )