Difference between revisions of "Stocks/get prices"

From GnuCash
Jump to: navigation, search
(second draft)
Line 2: Line 2:
  
 
Some knowledge of perl and python is required, adding a sample stock to Gnucash is explained here [[stocks/add_stock|Add stock to portfolio]].
 
Some knowledge of perl and python is required, adding a sample stock to Gnucash is explained here [[stocks/add_stock|Add stock to portfolio]].
 +
The first thing is to get historic stock prices. This is done with the perl module [http://www.mojotoad.com/sisk/projects/Finance-QuoteHist/ QuoteHist]. A sample perl script to get quotes is e.g.:
 +
 +
#!/usr/bin/perl -w
 +
use Finance::QuoteHist;
 +
print "Will get stock quotes of $ARGV[0] and save it into the file $ARGV[0]\n";
 +
$fname = $ARGV[0];
 +
    open (MYFILE, ">$fname");
 +
    $q = Finance::QuoteHist->new
 +
      (
 +
        symbols    => [($ARGV[0])],
 +
        start_date => '01/01/2000',
 +
        end_date  => 'today',
 +
      );
 +
 +
 +
print "name,date, open, high, low, close, volume\n";
 +
foreach $row ($q->quotes()) {
 +
        ($name,$date, $open, $high, $low, $close, $volume) = @$row;
 +
        print MYFILE "$name,$date, $open, $high, $low, $close, $volume\n";
 +
    }
 +
 +
close(MYFILE);

Revision as of 18:15, 18 January 2011

This document explains how to import historic stock quotes into gnucash

Some knowledge of perl and python is required, adding a sample stock to Gnucash is explained here Add stock to portfolio. The first thing is to get historic stock prices. This is done with the perl module QuoteHist. A sample perl script to get quotes is e.g.:

#!/usr/bin/perl -w
use Finance::QuoteHist;
print "Will get stock quotes of $ARGV[0] and save it into the file $ARGV[0]\n";
$fname = $ARGV[0];
   open (MYFILE, ">$fname");
   $q = Finance::QuoteHist->new
      (
       symbols    => [($ARGV[0])],
       start_date => '01/01/2000',
       end_date   => 'today',
      ); 


print "name,date, open, high, low, close, volume\n";
foreach $row ($q->quotes()) {
       ($name,$date, $open, $high, $low, $close, $volume) = @$row;
       print MYFILE "$name,$date, $open, $high, $low, $close, $volume\n";
   }

close(MYFILE);