File Coverage

blib/lib/App/Chart/Suffix/NoSuffix.pm
Criterion Covered Total %
statement 21 23 91.3
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 29 31 93.5


line stmt bran cond sub pod time code
1             # Copyright 2007, 2008, 2009, 2010 Kevin Ryde
2              
3             # This file is part of Chart.
4             #
5             # Chart is free software; you can redistribute it and/or modify it under the
6             # terms of the GNU General Public License as published by the Free Software
7             # Foundation; either version 3, or (at your option) any later version.
8             #
9             # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10             # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11             # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12             # details.
13             #
14             # You should have received a copy of the GNU General Public License along
15             # with Chart. If not, see <http://www.gnu.org/licenses/>.
16              
17             package App::Chart::Suffix::NoSuffix;
18 1     1   365 use 5.010;
  1         3  
19 1     1   5 use strict;
  1         1  
  1         16  
20 1     1   4 use warnings;
  1         1  
  1         18  
21 1     1   4 use Carp;
  1         2  
  1         42  
22 1     1   229 use Date::Parse;
  1         4658  
  1         87  
23 1     1   230 use URI::Escape;
  1         1042  
  1         45  
24 1     1   6 use Locale::TextDomain 'App-Chart';
  1         2  
  1         5  
25              
26 1     1   392 use App::Chart::Glib::Ex::MoreUtils;
  0            
  0            
27             use App::Chart::Database;
28             use App::Chart::Download;
29             use App::Chart::Sympred;
30             use App::Chart::TZ;
31             use App::Chart::Yahoo;
32              
33             my $shares_re = qr/^[^^][^.]+$/;
34             my $pred_shares = App::Chart::Sympred::Regexp->new ($shares_re);
35              
36             $App::Chart::Yahoo::latest_pred->add ($pred_shares);
37             App::Chart::setup_source_help
38             ($pred_shares, __p('manual-node','Yahoo Finance'));
39              
40              
41             # (yahoo-quote-delay! usa-symbol?
42             # (lambda (symbol exchange)
43             # ;; exchange is NasdaqSC, NasdaqNM, etc, not sure what the suffix bit is
44             # (if (string-prefix-ci? "nasdaq" exchange)
45             # 15 ;; NASDAQ
46             # 20))) ;; AMEX, NYSE
47              
48              
49             #------------------------------------------------------------------------------
50             # weblinks - US company info
51              
52             my $pred_nyse = App::Chart::Sympred::Proc->new
53             (sub {
54             my ($symbol) = @_;
55             $symbol =~ $shares_re or return 0;
56             my $exchange = symbol_exchange($symbol) // return 1;
57             return ($exchange eq 'NYSE');
58             });
59             my $pred_amex = App::Chart::Sympred::Proc->new
60             (sub {
61             my ($symbol) = @_;
62             $symbol =~ $shares_re or return 0;
63             my $exchange = symbol_exchange($symbol) // return 1;
64             return ($exchange eq 'AMEX');
65             });
66             my $pred_nasdaq = App::Chart::Sympred::Proc->new
67             (sub {
68             my ($symbol) = @_;
69             $symbol =~ $shares_re or return 0;
70             my $exchange = symbol_exchange($symbol) // return 1;
71             # allow NasdaqNM, NasdaqSC etc
72             return ($exchange =~ /^Nasdaq/i);
73             });
74              
75             App::Chart::Weblink->new
76             (pred => $pred_nyse,
77             name => __('NYSE _Company Information'),
78             desc => __('Open web browser at the New York Stock Exchange page for this company'),
79             proc => sub {
80             my ($symbol) = @_;
81             return 'http://www.nyse.com/about/listed/'
82             . URI::Escape::uri_escape($symbol) . '.html';
83             });
84             App::Chart::Weblink->new
85             (pred => $pred_amex,
86             name => __('AMEX _Company Information'),
87             desc => __('Open web browser at the American Stock Exchange page for this company'),
88             proc => sub {
89             my ($symbol) = @_;
90             return 'http://www.amex.com/?href=/equities/listCmp/EqLCCmpDesc.jsp?Product_Symbol=' . URI::Escape::uri_escape ($symbol);
91             });
92             App::Chart::Weblink->new
93             (pred => $pred_nasdaq,
94             name => __('NASDAQ _Company Information'),
95             desc => __('Open web browser at the NASDAQ page for this company'),
96             proc => sub {
97             my ($symbol) = @_;
98             return 'http://quotes.nasdaq.com/asp/summaryquote.asp?symbol='
99             . URI::Escape::uri_escape ($symbol);
100             });
101              
102             # return exchange name string, or undef if not known
103             sub symbol_exchange {
104             my ($symbol) = @_;
105             require App::Chart::DBI;
106             return (App::Chart::DBI->read_single
107             ('SELECT exchange FROM info WHERE symbol=?', $symbol)
108             //
109             App::Chart::DBI->read_single
110             ('SELECT exchange FROM latest WHERE symbol=?', $symbol));
111             }
112              
113              
114             #------------------------------------------------------------------------------
115              
116             our @to_suffix =
117             (
118             # ^AEX
119             [ '^AEX', '.AS' ],
120              
121             # ^ATX vienna
122             # and must avoid ^ATLI and similar below
123             [ '^ATX', '.VI' ],
124              
125             [ '^AX', '.AX' ], # several, inc ^AXJO, ^AXPJ
126             [ '^AORD', '.AX' ], # all ords
127             [ '^ATLI', '.AX' ], # asx 20
128             [ '^AFLI', '.AX' ], # asx 50
129             [ '^ATOI', '.AX' ], # asx 100
130              
131             # ^BFX belgium
132             [ '^BF', sub {
133             my $pred = App::Chart::Sympred::Prefix->new ('^BF');
134             my $timezone_brussels = App::Chart::TZ->new
135             (name => __('Brussels'),
136             choose => [ 'Europe/Brussels' ],
137             fallback => 'CET-1');
138             $timezone_brussels->setup_for_symbol ($pred);
139              
140             # only home page for now ...
141             App::Chart::Weblink->new
142             (pred => $pred,
143             name => __('Brussels Stock Exchange Home Page'),
144             desc => __('Open web browser at the Brussels Stock Exchange home page'),
145             # now part of euronext ...
146             url => 'http://www.stockexchange.be');
147             } ],
148              
149             # ^BVSP bovespa
150             [ '^BV', '.SA' ],
151              
152             # ^BSESN bse sensitive
153             [ '^BSE', '.BO' ],
154              
155             # ^CASE30
156             [ '^CASE', '.CA' ],
157              
158             # ^CLDOW
159             # ^CLDOWD
160             [ '^CL', \&santiago ],
161              
162             # ^CCSI - cairo CMA
163             [ '^CC', '.CA' ],
164              
165             # ^CSE composite
166             [ '^CSE', sub {
167             my $pred = App::Chart::Sympred::Prefix->new ('^CSE');
168             my $timezone_colombo = App::Chart::TZ->new
169             (name => __('Colombo'),
170             choose => [ 'Asia/Colombo' ],
171             fallback => 'LKT-5:30');
172             $timezone_colombo->setup_for_symbol ($pred);
173              
174             # only home page for now ...
175             App::Chart::Weblink->new
176             (pred => $pred,
177             name => __('_CSE Home Page'),
178             desc => __('Open web browser at the Colombo Stock Exchange home page'),
179             url => 'http://www.cse.lk');
180             } ],
181              
182             # ^DJEG20
183             # ^DJEG20E
184             # ^DJEG20D
185             # ^DJEG20T
186             # ^DJEG20ET
187             # ^DJEG20DT
188             [ '^DJEG', '.CA' ],
189              
190             # ^DWEG -- dow/wiltshire egypt
191             [ '^DWEG', '.CA' ],
192              
193             [ '^DWCL', \&santiago ],
194              
195             # ^DWTH etc
196             [ '^DWTH', '.BK' ],
197              
198             # ^DWVE
199             # ^DWVED
200             # ^DWVET
201             # ^DWVEDT
202             [ '^DWVE', '.CR' ],
203              
204             # ^FTSE
205             [ '^FT', '.L' ],
206              
207             # ^GDAXI germany
208             [ '^GDAXI', \&germany ],
209              
210             # ^GSPC S&P 500
211             [ '^GSPC', \&usa ],
212              
213             # ^GSPTSE - S&P TSX Composite, etc
214             [ '^GSPT', '.TO' ],
215              
216             # ^HSI hang seng index
217             [ '^H', '.HK' ],
218              
219             # paris
220             [ '^FC', '.PA' ],
221              
222             # ^JKSE composite
223             [ '^JK', '.JK' ],
224              
225             # http://finance.yahoo.com/intlindices?e=europe
226             # ^IXX - ISE 100 options
227             # http://www.ise.com/WebForm/options_product_indexDetails.aspx?categoryid=234&header0=true&menu2=true&link2=true&symbol=IXX
228             [ '^IXX', '.JK' ],
229              
230             # ^KFX copenhagen
231             [ '^KF', '.CO' ],
232              
233             # ^KLSE composite
234             [ '^KL', '.KL' ],
235              
236             # ^KS11 korea
237             # and avoid clash with ^KSE
238             [ 'KS1', '.KS' ],
239              
240             # ^KSE karachi 100
241             [ '^KSE', sub {
242             my $pred = App::Chart::Sympred::Prefix->new ('^KSE');
243             my $timezone_karachi = App::Chart::TZ->new
244             (name => __('Karachi'),
245             choose => [ 'Asia/Karachi' ],
246             fallback => 'PKT-5');
247             $timezone_karachi->setup_for_symbol ($pred);
248              
249             # only home page for now ...
250             App::Chart::Weblink->new
251             (pred => $pred,
252             name => __('_Karachi Stock Exchange Home Page'),
253             desc => __('Open web browser at the Karachi Stock Exchange home page'),
254             url => 'http://www.kse.com.pk');
255             } ],
256              
257             # ^MERV
258             [ '^MER', '.BA' ],
259              
260             # ^MIBTEL milan
261             [ '^MIB', '.MI' ],
262              
263             # ^MXX ipc
264             [ '^MX', '.MX' ],
265              
266             # ^N225
267             # and not ^NZ50 etc
268             [ '^N2', sub {
269             my $pred = App::Chart::Sympred::Prefix->new ('^N2');
270             App::Chart::TZ->tokyo->setup_for_symbol ($pred);
271              
272             # only home page for now ...
273             App::Chart::Weblink->new
274             (pred => $pred,
275             name => __('_Tokyo Stock Exchange Home Page'),
276             desc => __('Open web browser at the Tokyo Stock Exchange home page'),
277             url => App::Chart::Glib::Ex::MoreUtils::lang_select
278             ('ja' => 'http://www.tse.or.jp',
279             'en' => 'http://www.tse.or.jp/english/'));
280             } ],
281             # web link - TSE company info
282             #
283             # Eg. in english
284             # http://quote.tse.or.jp/tse/quote.cgi?F=listing/EDetail1&MKTN=T&QCODE=2001
285             # and japanese
286             # http://quote.tse.or.jp/tse/quote.cgi?F=listing/Jdetail1&MKTN=T&QCODE=2001
287             #
288              
289             # no tokyo symbols as such yet ...
290             #
291             # (weblink-handler! tokyo-symbol?
292             # (lambda (symbol)
293             # (list (_ 'TSE _Company Information')
294             # (_ 'Open web browser at the Tokyo Stock Exchange page for this company')
295             # (string-append 'http://quote.tse.or.jp/tse/quote.cgi?F=listing/'
296             # (lang-select '(('ja' 'J')
297             # ('en' 'E')))
298             # 'Detail1&MKTN=T&QCODE='
299             # (chart-symbol-sans-dot symbol)))))
300              
301              
302             # ^NZ50 new zealand
303             [ '^NZ', '.NZ' ],
304              
305             # ^OEX S&P 100
306             [ '^OEX', \&usa ],
307              
308             # ^OMXSPI - stockholm
309             [ '^OMX', '.ST' ],
310              
311             # ^OSEAX oslo
312             [ '^OS', '.OL' ],
313              
314             # ^PSI - PSE composite phillipines
315             [ '^PS', sub {
316             my $pred = App::Chart::Sympred::Prefix->new ('^PS');
317             my $timezone_manila = App::Chart::TZ->new
318             (name => __('Manila'),
319             choose => [ 'Asia/Manila' ],
320             fallback => 'PHT-8');
321             $timezone_manila->setup_for_symbol ($pred);
322              
323             # only home page for now ...
324             App::Chart::Weblink->new
325             (pred => $pred,
326             name => __p('phillipine','_PSE Home Page'),
327             desc => __('Open web browser at the Phillipine Stock Exchange home page'),
328             url => 'http://www.pse.org.ph');
329             } ],
330              
331             # ^PX50 prague
332             [ '^PX', sub {
333             my $pred = App::Chart::Sympred::Prefix->new ('^PX');
334             my $timezone_prague = App::Chart::TZ->new
335             (name => __('Prague'),
336             choose => [ 'Europe/Prague', 'Europe/Berlin' ],
337             fallback => 'CET-1');
338             $timezone_prague->setup_for_symbol ($pred);
339              
340             # only home page for now ...
341             App::Chart::Weblink->new
342             (pred => $pred,
343             name => __p('prague','_PSE Home Page'),
344             desc => __('Open web browser at the Prague Stock Exchange home page'),
345             url => App::Chart::Glib::Ex::MoreUtils::lang_select
346             ('cs' => 'http://www.pse.cz',
347             'en' => 'http://www.pse.cz/default.asp?language=english'));
348             } ],
349              
350             # ^SMSI
351             # not ^SML - S&P small 600
352             [ '^SMS', '.MA' ],
353              
354             # ^SSEC shanghai composite
355             # and not hitting ^SSMI
356             [ '^SSE', '.SS' ],
357              
358             # ^SPCDNX - CDNX Index TSX venture
359             [ '^SPC', '.V' ],
360              
361             # ^SPTSECP - S&P TSX 60 Capped, etc
362             [ '^SPT', '.TO' ],
363              
364             # http://au.finance.yahoo.com/intlindices
365             # ^SSMI - SMI switzerland
366             # and not hitting ^SSEC
367             [ 'SSM', '.SW' ],
368              
369             # ^STI straits times singapore
370             [ '^STI', '.SI' ],
371              
372             # ^STOXX
373             [ '^STO', \&germany ],
374              
375             # ^SXIP etc stoxx variations
376             [ '^SX', \&germany ],
377              
378             # ^THDOW etc
379             [ '^TH', '.BK' ],
380              
381             # ^TWII weighted
382             [ '^TW', '.TW' ],
383              
384             # ^VEDOW
385             # ^VEDOWD
386             [ '^VE', '.CR' ],
387              
388             );
389              
390              
391             sub symbol_setups {
392             my ($symbol) = @_;
393             foreach my $elem (@to_suffix) {
394             my $prefix = $elem->[0];
395             if ($symbol =~ /^\Q$prefix\E/) {
396             my $action = $elem->[1];
397             $elem->[1] = \&noop; # once only
398             if (ref($action)) {
399             &$action();
400             } else {
401             my $dummy = 'DUMMY' . $action;
402             App::Chart::symbol_setups ($dummy);
403             }
404             return;
405             }
406             }
407              
408             my $pred = App::Chart::Sympred::Equal->new ($symbol);
409             App::Chart::TZ->newyork->setup_for_symbol ($pred);
410             }
411             sub noop {}
412              
413             # not sure if these indexes are based on a particular exchange
414             use constant::defer germany => sub {
415             my $pred = App::Chart::Sympred::Any->new
416             (App::Chart::Sympred::Prefix->new ('^STO'),
417             App::Chart::Sympred::Prefix->new ('^SX'),
418             App::Chart::Sympred::Regexp->new (qr/^.*DAX/));
419             require App::Chart::Suffix::BE;
420             no warnings 'once';
421             $App::Chart::Suffix::BE::timezone_berlin->setup_for_symbol ($pred);
422             return;
423             };
424              
425             use constant::defer santiago => sub {
426             # ^CLDOW
427             # ^CLDOWD
428             # ^DWCL
429             # ^DWCLD
430             # ^DWCLT
431             # ^DWCLTD
432             # used to have ^IPSA, but shows 0.00 as of March 2007
433             my $pred = App::Chart::Sympred::Any->new
434             (App::Chart::Sympred::Prefix->new ('^CL'),
435             App::Chart::Sympred::Prefix->new ('^DWCL'));
436              
437             my $timezone_santiago = App::Chart::TZ->new
438             (name => __('Santiago'),
439             choose => [ 'America/Santiago' ],
440             fallback => 'CLT+4');
441             $timezone_santiago->setup_for_symbol ($pred);
442              
443             # only home page for now ...
444             App::Chart::Weblink->new
445             (pred => $pred,
446             name => __('_Santiago Stock Exchange Home Page'),
447             desc => __('Open web browser at the Santiago Stock Exchange home page'),
448             url => App::Chart::Glib::Ex::MoreUtils::lang_select
449             ('es' => 'http://www.bolsadesantiago.com',
450             'en' => 'http://www.bolsadesantiago.com/english/index.asp'));
451             return;
452             };
453              
454              
455             use constant::defer usa => sub {
456             my %sandp_table
457             = ('^GSPC' => '500', # S&P 500
458             '^OEX' => '100', # S&P 100
459             );
460              
461             require App::Chart::Weblink::SandP;
462             my $weblink = App::Chart::Weblink::SandP->new
463             (url_pattern => 'http://www2.standardandpoors.com/portal/site/sp/{lang}/page.topic/indices_{symbol}/2,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0.html',
464             symbol_table => \%sandp_table);
465              
466             my $pred = $weblink->{'pred'};
467             App::Chart::TZ->newyork->setup_for_symbol ($pred);
468             return;
469             };
470              
471             1;
472             __END__
473              
474              
475              
476              
477             # ^TV.N - total volume NYSE
478             (define (nyse-symbol? symbol)
479             (string-suffix? '.N' symbol))
480              
481             # ^TV.O - total volume NASDAQ
482             (define (nasdaq-symbol? symbol)
483             (string-suffix? '.O' symbol))
484              
485             (define (yahoo-index-symbol-usa? symbol)
486             (or
487             # http://finance.yahoo.com/indices?e=nasdaq -- and more below
488             # ^IXBK - nasdaq banking
489             # ^IXIC - nasdaq composite
490             # ^IXF - nasdaq financials
491             # ^IXID - nasdaq industrials
492             # ^IXIS - nasdaq insurance
493             # ^IXQ - nasdaq nnm composite
494             # ^IXK - nasdaq computer
495             # ^IXFN - nasdaq other finances
496             # ^IXUT - nasdaq telecommunications
497             # ^IXTR - nasdaq transports
498             (string-prefix? '^IX' symbol)
499              
500             (member symbol
501             '(
502             '^VIX' # volatility
503             '^VXO' # CBOE options volatility
504              
505             # http://finance.yahoo.com/indices?e=dow_jones
506             '^DJA' # Dow average
507             '^DJI' # Dow
508             '^DJT' # Dow transports
509             '^DJU' # Dow utilities
510              
511             # http://finance.yahoo.com/indices?e=new_york
512             '^NYA' # NYSE composite
513             '^NIN' # NYSE international
514             '^NTM' # NYSE TMT
515             '^NUS' # NYSE US 100
516             '^NWL' # NYSE world leaders
517              
518             # http://finance.yahoo.com/indices?e=nasdaq
519             '^NBI' # nasdaq biotech
520             '^NDX' # nasdaq 100 drm
521              
522             # http://finance.yahoo.com/indices?e=sp
523             '^OEX' # S&P 100
524             '^MID' # S&P 400 midcap
525             '^GSPC' # S&P 500
526             '^SPSUPX' # S&P composite 1500
527             '^SML' # S&P small 600
528              
529             # http://finance.yahoo.com/indices?e=other
530             '^XAX' # AMEX composite
531             '^IIX' # AMEX internet
532             '^NWX' # AMEX networking
533             '^DWC' # DJ wilshire 5000 tot
534             '^XMI' # major market index
535             '^PSE' # NYSE arca tech 100
536             '^SOXX' # Philadelphia semiconductor
537             '^DOT' # Philadelphia/thestreet.com internet
538             '^RUI' # Russell 1000
539             '^RUT' # Russell 2000
540             '^RUA' # Russell 3000
541              
542             # http://finance.yahoo.com/indices?e=treasury
543             '^TNX' # 10-year treasury bond interest rate
544             '^IRX' # 13-week treasury note interest rate
545             '^TYX' # 30-year treasury bond interest rate
546             '^FVX' # 5-year treasury bond interest rate
547              
548             # http://finance.yahoo.com/indices?e=commodities
549             '^DJC' # Dow commodities
550             '^DJS2' # Dow industrial avg settle
551             '^XAU' # Philadelphia gold and silver index
552              
553             # old bits
554             '^WIL5' # Wiltshire 5000 - gone, now ^DWC maybe
555             ))))