Neues in der Kategorie Finance

Mit Finance::QuoteHist von Matt Sisk lassen sich historische Börsenkursdaten (Stock Quotes) einfach über das Web abrufen.

Beispiel: Historische Dax-Kurse von Yahoo! Finance

#!/usr/bin/perl 
use strict;
use warnings;
use Finance::QuoteHist::Yahoo;

my $q = Finance::QuoteHist::Yahoo->new
     (
      			#symbols    => [qw(IBM UPS AMZN)],
      			#Adidas
      			#symbols    => [qw(ADS.DE)],
      symbols    => [qw(^GDAXI)],
      start_date => '01/01/1999',
      end_date   => 'today',
     );

  # Einfache Ausgabe der Ergebnisse 
foreach my $quote ( $q->quotes() ) {
	my ($symbol, $date, $open, $high, $low, $close, $volume, $adjusted) = @$quote;
	print "$symbol startete am $date mit $open und schloss zu $close ($adjusted).\n";
}

Das Programm erzeugt folgende Ausgabe:

^GDAXI startete am 1999/01/04 mit 4991.9500 und schloss zu 5252.3600 (5252.3600).
^GDAXI startete am 1999/01/05 mit 5221.4300 und schloss zu 5253.9100 (5253.9100).
^GDAXI startete am 1999/01/06 mit 5328.0200 und schloss zu 5443.6200 (5443.6200).
^GDAXI startete am 1999/01/07 mit 5485.6100 und schloss zu 5323.2100 (5323.2100).
......
^GDAXI startete am 2009/06/11 mit 5039.9700 und schloss zu 5107.2600 (5107.2600).
^GDAXI startete am 2009/06/12 mit 5098.0100 und schloss zu 5069.2400 (5069.2400).
^GDAXI startete am 2009/06/15 mit 5051.3500 und schloss zu 4889.9400 (4889.9400).
^GDAXI startete am 2009/06/16 mit 4899.8100 und schloss zu 4890.7200 (4890.7200).

 

Siehe auch

Finance::YahooQuote von Dirk Eddelbuettel vereinfacht die Ermittlung der Börsenkurse von Yahoo! Finance und dient als Grundlage für den graphischen Stockticker SMTM.

DAX.png

Beispiel: Aktueller Stand des DAX

#!/usr/bin/perl 
use strict;
use warnings;

use Finance::YahooQuote;

my $symbol = '^GDAXI';

my @quote = getonequote $symbol; # Get a quote for a single symbol

if (scalar @quote) {
	print " 0 Symbol: $quote[0]\n";
	print " 1 Company Name: $quote[1]\n";
	print " 2 Last Price: $quote[2]\n";
	print " 3 Last Trade Date: $quote[3]\n";
	print " 4 Last Trade Time: $quote[4]\n";
	print " 5 Change: $quote[5]\n";
	print " 6 Percent Change: $quote[6]\n";
	print " 7 Volume: $quote[7]\n";
	print " 8 Average Daily Vol: $quote[8]\n";
	print " 9 Bid: $quote[9]\n";
	print "10 Ask: $quote[10]\n";
	print "11 Previous Close: $quote[11]\n";
	print "12 Today's Open: $quote[12]\n";
	print "13 Day's Range: $quote[13]\n";
	print "14 52-Week Range: $quote[14]\n";
	print "15 Earnings per Share: $quote[15]\n";
	print "16 P/E Ratio: $quote[16]\n";
	print "17 Dividend Pay Date: $quote[17]\n";
	print "18 Dividend per Share: $quote[18]\n";
	print "19 Dividend Yield: $quote[19]\n";
	print "20 Market Capitalization: $quote[20]\n";
	print "21 Stock Exchange: $quote[21]\n";
} 
else {
	print "Ooops\n";
}

Das Programm erzeugt folgende Ausgabe:

 0 Symbol: ^GDAXI
 1 Company Name: DAX
 2 Last Price: 5107.26
 3 Last Trade Date: 6/11/2009
 4 Last Trade Time: 11:45am
 5 Change: +56.08
 6 Percent Change: +1.11%
 7 Volume: 0
 8 Average Daily Vol: 0
 9 Bid: N/A
10 Ask: N/A
11 Previous Close: 5051.18
12 Today's Open: 5039.97
13 Day's Range: 5038.03 - 5120.87
14 52-Week Range: 3588.89 - 6855.84
15 Earnings per Share: N/A
16 P/E Ratio: N/A
17 Dividend Pay Date: N/A
18 Dividend per Share: N/A
19 Dividend Yield: N/A
20 Market Capitalization: N/A
21 Stock Exchange: XETRA

Beispiel: Aktueller Kurs der adidas Aktie

Durch useExtendedQueryFormat können weitere Felder, wie Earnings per Share, ermittelt werden:

#!/usr/bin/perl 
use strict;
use warnings;

use Finance::YahooQuote;

my $symbol = 'ADS.DE';

useExtendedQueryFormat(); 

my @quote = getonequote $symbol; # Get a quote for a single symbol

if (scalar @quote) {
	print " 0 Symbol: $quote[0]\n";
	print " 1 Company Name: $quote[1]\n";
	print " 2 Last Price: $quote[2]\n";
	print " 3 Last Trade Date: $quote[3]\n";
	print " 4 Last Trade Time: $quote[4]\n";
	print " 5 Change: $quote[5]\n";
	print " 6 Percent Change: $quote[6]\n";
	print " 7 Volume: $quote[7]\n";
	print " 8 Average Daily Vol: $quote[8]\n";
	print " 9 Bid: $quote[9]\n";
	print "10 Ask: $quote[10]\n";
	print "11 Previous Close: $quote[11]\n";
	print "12 Today's Open: $quote[12]\n";
	print "13 Day's Range: $quote[13]\n";
	print "14 52-Week Range: $quote[14]\n";
	print "15 Earnings per Share: $quote[15]\n";
	print "16 P/E Ratio: $quote[16]\n";
	print "17 Dividend Pay Date: $quote[17]\n";
	print "18 Dividend per Share: $quote[18]\n";
	print "19 Dividend Yield: $quote[19]\n";
	print "20 Market Capitalization: $quote[20]\n";
	print "21 Stock Exchange: $quote[21]\n";
	print "22 Short ratio: $quote[22]\n";
	print "23 1yr Target Price: $quote[23]\n";
	print "24 EPS Est. Current Yr: $quote[24]\n";
	print "25 EPS Est. Next Year: $quote[25]\n" ;
	print "26 EPS Est. Next Quarter: $quote[26]\n";
	print "27 Price/EPS Est. Current Yr: $quote[27]\n";
	print "28 Price/EPS Est. Next Yr: $quote[28]\n";
	print "29 PEG Ratio: $quote[29]\n";
	print "30 Book Value: $quote[30]\n";
	print "31 Price/Book: $quote[31]\n";
	print "32 Price/Sales: $quote[32]\n";
	print "33 EBITDA: $quote[33]\n";
	print "34 50-day Moving Avg: $quote[34]\n";
	print "35 200-day Moving Avg: $quote[35]\n";
} 
else {
	print "Ooops\n";
}

Das Programm erzeugt folgende Ausgabe:

 0 Symbol: ADS.DE
 1 Company Name: ADIDAS
 2 Last Price: 27.88
 3 Last Trade Date: 6/11/2009
 4 Last Trade Time: 11:35am
 5 Change: +0.17
 6 Percent Change: +0.61%
 7 Volume: 1324113
 8 Average Daily Vol: 1747360
 9 Bid: 27.80
10 Ask: 27.84
11 Previous Close: 27.71
12 Today's Open: 27.59
13 Day's Range: 27.48 - 28.30
14 52-Week Range: 21.22 - 45.12
15 Earnings per Share: 0.00
16 P/E Ratio: N/A
17 Dividend Pay Date: N/A
18 Dividend per Share: 0.50
19 Dividend Yield: 1.80
20 Market Capitalization: N/A
21 Stock Exchange: XETRA
22 Short ratio: N/A
23 1yr Target Price: N/A
24 EPS Est. Current Yr: 0.00
25 EPS Est. Next Year: 0.00
26 EPS Est. Next Quarter: 0.00
27 Price/EPS Est. Current Yr: N/A
28 Price/EPS Est. Next Yr: N/A
29 PEG Ratio: N/A
30 Book Value: 0.00
31 Price/Book: N/A
32 Price/Sales: N/A
33 EBITDA: 0
34 50-day Moving Avg: 26.7369
35 200-day Moving Avg: 26.1586

Siehe auch

alexm hat drüben bei den Perlmonks ein kleines Programm zur tagesaktuellen Währungsumrechnung veröffentlicht: Using up-to-date currency conversion rates

#!/usr/bin/perl 
use strict;
use warnings;


# Quelle: Using up-to-date currency conversion rates
# http://www.perlmonks.org/?node_id=709343

use Locale::Currency;
use File::Basename;
use Cache::FileCache;
use Finance::Quote;

die "usage: $0 amount currency_from currency_to\n"
    unless @ARGV == 3;

my $amount = shift @ARGV;

my ($currency_from, $currency_to) = map { uc } @ARGV;

for my $code ($currency_from, $currency_to) {
    die "sorry, currency $code not in ISO 4217\n"
        unless defined code2currency($code);
}

my ($filename) = fileparse($0, '.pl');

my $cache = Cache::FileCache->new({
    cache_root         => "$ENV{HOME}/.$filename",
    default_expires_in => '1 day',
});

my $quote = Finance::Quote->new();

my $ratio = $cache->get("$currency_from:$currency_to");

$ratio = $quote->currency($currency_from, $currency_to)
    unless defined $ratio;

die "sorry, cannot convert from $currency_from to $currency_to\n"
    unless defined $ratio;

$cache->set("$currency_from:$currency_to", $ratio);
print "$amount $currency_from = ", $amount * $ratio, " $currency_to\n";

Wenn man das Programm als currency.pl speichert und anschließend auf der Kommandozeile aufruft, ergibt sich beispielsweise folgende Ausgabe.

$ perl currency.pl 100 USD EUR
100 USD = 70.46 EUR

Finance::Quote holt den Umrechnungsfaktor, Cache::FileCache speichert diesen Faktor für einen Tag auf der lokalen Festplatte und Locale::Currency prüft, ob die eingegebenen Währungscodes gültig sind.

Siehe auch:

Über dieses Archiv

Diese Seite enthält aktuelle Einträge der Kategorie Finance.

E-Mail ist die vorherige Kategorie.

Geo ist die nächste Kategorie.

Aktuelle Einträge finden Sie auf der Startseite, alle Einträge in den Archiven.

Fachzeitschriften

Blog Roll