T
Ted
I have been able to get this package to work sometimes. However,
invariably it fails on me part way through my script, after
downloading data for from one to four ticker symbols. The error is:
Can't use an undefined value as an ARRAY reference at C:/Perl/site/lib/
Finance/QuoteHist/Generic.pm line 863.
I have no information about how an undefined value is being passed
deep into the code of a package I didn't write. I took a quick look
into Generic.pm and yahoo.pm, but found no enlightenment so far
(there's a lot of code there).
Sometimes it arises when quotes() is executed, and at other times, it
occurs when dividends() is executed.
The script I am using is appended below. There isn't anything special
about it. Much of it I copied from example code in the documentation
provided for the two finance packages I'm trying. About all I did was
merge two example scripts, and attempt to get the historical quote
data for one symbol at a time. So far, I have historical quote data
for four stocks. There are over 7000 that I need to retrieve:
obviously not something that is manageable manually downloading each
individually.
Neither Finance::QuoteHist::Generic nor Finance::QuoteHist::Yahoo
(which is derived from the former) say anything about error handling,
or provide a way to test whether or not data was successfully
downloaded.
Any assistance would be greatly appreciated.
Thanks
Ted
use Finance::TickerSymbols;
use Finance::QuoteHist::Yahoo;
use IO::File;
#my $fh1 = new IO::File "> values.csv";
#my $fh2 = new IO::File "> splits.csv";
#my $fh3 = new IO::File "> dividends.csv";
my $fname1;
my $fname2;
my $fname3;
for my $industry ( industries_list()) {
print "\n\n$industry\n";
mkdir "$industry";
for my $symbol ( industry_list( $industry ) ) {
print "$symbol\n\n";
mkdir "$industry\\$symbol";
$fname1 = "$industry\\$symbol\\values.csv";
$fname2 = "$industry\\$symbol\\splits.csv";
$fname3 = "$industry\\$symbol\\dividends.csv";
$fh1 = new IO::File "> $fname1";
$fh2 = new IO::File "> $fname2";
$fh3 = new IO::File "> $fname3";
$q = new Finance::QuoteHist::Yahoo
(
symbols => "$symbol",
start_date => '01/01/1998',
end_date => 'today'
);
# Values
foreach $row ($q->quotes()) {
if (defined $row ) {
($symbol, $date, $open, $high, $low, $close, $volume) = @$row;
print $fh1 "$symbol, $date, $open, $high, $low, $close, $volume
\n";
} else {
print "No data for $symbol\n";
next;
}
}
$fh1->close();
foreach $row ($q->splits()) {
if (defined $row ) {
($symbol, $date, $post, $pre) = @$row;
print $fh2 "$symbol, $date, $post, $pre\n";
} else {
print "No splits data for $symbol\n";
next;
}
}
$fh2->close();
foreach $row ($q->dividends()) {
if (defined $row ) {
($symbol, $date, $dividend) = @$row;
print $fh3 "$symbol, $date, $dividend\n";
} else {
print "No dividend data for $symbol\n";
next;
}
}
$fh3->close();
}
}
invariably it fails on me part way through my script, after
downloading data for from one to four ticker symbols. The error is:
Can't use an undefined value as an ARRAY reference at C:/Perl/site/lib/
Finance/QuoteHist/Generic.pm line 863.
I have no information about how an undefined value is being passed
deep into the code of a package I didn't write. I took a quick look
into Generic.pm and yahoo.pm, but found no enlightenment so far
(there's a lot of code there).
Sometimes it arises when quotes() is executed, and at other times, it
occurs when dividends() is executed.
The script I am using is appended below. There isn't anything special
about it. Much of it I copied from example code in the documentation
provided for the two finance packages I'm trying. About all I did was
merge two example scripts, and attempt to get the historical quote
data for one symbol at a time. So far, I have historical quote data
for four stocks. There are over 7000 that I need to retrieve:
obviously not something that is manageable manually downloading each
individually.
Neither Finance::QuoteHist::Generic nor Finance::QuoteHist::Yahoo
(which is derived from the former) say anything about error handling,
or provide a way to test whether or not data was successfully
downloaded.
Any assistance would be greatly appreciated.
Thanks
Ted
use Finance::TickerSymbols;
use Finance::QuoteHist::Yahoo;
use IO::File;
#my $fh1 = new IO::File "> values.csv";
#my $fh2 = new IO::File "> splits.csv";
#my $fh3 = new IO::File "> dividends.csv";
my $fname1;
my $fname2;
my $fname3;
for my $industry ( industries_list()) {
print "\n\n$industry\n";
mkdir "$industry";
for my $symbol ( industry_list( $industry ) ) {
print "$symbol\n\n";
mkdir "$industry\\$symbol";
$fname1 = "$industry\\$symbol\\values.csv";
$fname2 = "$industry\\$symbol\\splits.csv";
$fname3 = "$industry\\$symbol\\dividends.csv";
$fh1 = new IO::File "> $fname1";
$fh2 = new IO::File "> $fname2";
$fh3 = new IO::File "> $fname3";
$q = new Finance::QuoteHist::Yahoo
(
symbols => "$symbol",
start_date => '01/01/1998',
end_date => 'today'
);
# Values
foreach $row ($q->quotes()) {
if (defined $row ) {
($symbol, $date, $open, $high, $low, $close, $volume) = @$row;
print $fh1 "$symbol, $date, $open, $high, $low, $close, $volume
\n";
} else {
print "No data for $symbol\n";
next;
}
}
$fh1->close();
foreach $row ($q->splits()) {
if (defined $row ) {
($symbol, $date, $post, $pre) = @$row;
print $fh2 "$symbol, $date, $post, $pre\n";
} else {
print "No splits data for $symbol\n";
next;
}
}
$fh2->close();
foreach $row ($q->dividends()) {
if (defined $row ) {
($symbol, $date, $dividend) = @$row;
print $fh3 "$symbol, $date, $dividend\n";
} else {
print "No dividend data for $symbol\n";
next;
}
}
$fh3->close();
}
}