Difference between revisions of "Stocks/get prices"

From GnuCash
Jump to: navigation, search
(second draft)
Line 24: Line 24:
 
   
 
   
 
  close(MYFILE);
 
  close(MYFILE);
 +
 +
 +
On Unix/Linux save the text into a file (e.g. get_quotes) , do a chmod +x and execute it with the argument INTC to get the Intel prices saved into the file INTC
 +
chmod a+x get_quotes
 +
./get_quotes INTC

Revision as of 18:19, 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);


On Unix/Linux save the text into a file (e.g. get_quotes) , do a chmod +x and execute it with the argument INTC to get the Intel prices saved into the file INTC

chmod a+x get_quotes
./get_quotes INTC