Module Finance
In: lib/finance/quote/yahoo/asia.rb
lib/finance/quote/yahoo/europe.rb
lib/finance/quote/yahoo/usa.rb
lib/finance/quote/yahoo/australia.rb
lib/finance/quote/yahoo.rb
lib/finance/quote/aex.rb
lib/finance/currency.rb
lib/finance/quote.rb
lib/finance.rb

Ruby/Finance - Access to financial data, including stock quotes.

Introduction

Ruby/Finance allows access to changing financial data, such as currency conversion rates and stock quotes. It is a partial port of Perl Finance::Quote module, currently implementing the Yahoo Finance modules and the Amsterdam Euronext eXchange (AEX) module.

Please note that the AEX module is currently obsolete, due to the removal of the underlying service that it used.

Installation

Please see the INSTALL file supplied with the software for details of how to install Ruby/Finance. It‘s very simple and involves running just a single script.

Examples

Currency conversion

 require 'finance/currency'

 # Display the US Dollar ($) to Euro (¤) conversion rate.
 #
 puts Finance::Currency::convert( 'EUR', 'USD' )

 # Display the British Pounds Sterling (£) to Icelandic Kronur conversion
 # rate for the amount of £32.50.
 #
 puts Finance::Currency::convert( 'ISK', 'GBP', 32.50 )

Stock quotes

 require 'finance/quote'

 q = Finance::Quote.new               # Answers will be given in the native
                                      # currency of the exchange on which
                                      # they are listed.

 q = Finance::Quote.new( 'EUR' )      # Answers will be given in Euros.

 q.currency = 'VND'                   # Switch to using Vietnamese Dong.

 info = q.fetch( 'usa', 'CRM' )       # Fetch a single quote, namely CRM.

 info = q.fetch( :usa, 'EBAY', 'AMZN' )  # Fetch EBAY and AMZN. Note that
                                         # a Symbol can be used instead of a
                                         # String for the exchange name.

 info = q.fetch( 'usa', %w[ EBAY AMZN ] ) # An Array of ticker symbols is
                                          # OK, too.
 puts info['EBAY'][:price]

 # A block can be passed, too:
 #
 q.fetch( :usa, 'RHAT' ) { |info| puts info['RHAT'][:high] }

 # You can also bypass #fetch and call the exchange as a method:

 q.usa( 'RHAT' ) { |info| puts info['RHAT'][:high] }

The Finance::Quote#fetch method accepts an exchange (either a Symbol or a String), followed by a list of one or more stocks to fetch. This list may be a variable length list of Strings or an Array of Strings. It returns an object of class QuoteData, which is basically a two-dimensional Hash. The outer index is the stock ticker symbol, which can be referenced as either a Symbol (e.g. :RHAT) or a String (e.g. ‘RHAT‘). Internally, however, it is a String. The inner index is referred to as the label and must be referenced as a Symbol. In the above examples, you can see labels such as :price and :high in use.

Labels

When information about a stock is returned, the following labels are filled with data:

name
Company or mutual fund name
last
Last price
price
Same as last
high
Highest trade today
low
Lowest trade today
date
Last Trade Date (MM/DD/YY format)
time
Last Trade Time
net
Net Change
p_change
Percentage change from previous day‘s close
volume
Volume
avg_vol
Average daily volume
bid
Bid
ask
Ask
close
Previous close
open
Today‘s open
day_range
Day‘s range
year_range
52-week range
eps
Earnings per share
pe
Price/earnings ratio
div_date
Dividend pay date
div
Dividend per share
div_yield
Dividend yield
cap
Market capitalisation
ex_div
Ex-dividend date
nav
Net asset value
yield
Yield (usually the 30 day average)
exchange
The exchange from which the information was obtained
success
Did the stock successfully return information? The answer here will be true or false.
error_msg
If success is false, this field may contain the reason why.
method
The mapped method (as passed to Finance::Quote#fetch) that found this information.

Exchanges

The first argument passed to the Finance::Quote#fetch method is the exchange to query. The following exchanges are currently recognised:

asia
Asian Markets
australia
Australian Stock Exchange
canada
Canadian Markets
europe
European Markets
fidelity
Fidelity Investments
nasdaq
NASDAQ
nyse
New York Stock Exchange
usa
USA Markets
vanguard
Vanguard Investments

More exchanges will be added in the fullness of time.

HISTORY

Ruby/Finance is a Ruby port of Perl‘s Finance::Quote module.

The contributors to Finance::Quote at the time of porting (v1.08) were:

  DJ Padzensky   <djpadz@padz.net>
  Linas Vepstas  <linas@linas.org>
  Yannick LE NY  <y-le-ny@ifrance.com>
  Paul Fenwick   <pjf@cpan.org>
  Brent Neal     <brentn@users.sourceforge.net>

Finance::Quote itself started life as the Quote module, which was distributed as part of GnuCash. That module was a modified version of Finance::YahooQuote, which was written by DJ Padzensky. At that point, it was separated from GnuCash and became an independent project.

Since that time, many people have contributed to Finance::Quote, including Xose Manoel Ramos (inheritable Yahoo! methods), Brent Neal, Keith Refson, and Volker Stuerzl (pluggable modules), and Peter Thatcher, Jacinta Richardson and Steven Murdoch (who contributed various bug-fixes and improvements).


Author:Ian Macdonald <ian@caliban.org>
Version:0.2.3
Licence:GPL

Methods

Classes and Modules

Module Finance::Currency
Class Finance::Quote

Public Class methods

Returns an array of [ host, port, user, password ], based on the setting of $http_proxy. Each of these will be nil if the corresponding data element is not set.

This method is likely to be of little use to you, as it is primarily intended for the internal use of Ruby/Finance.

[Validate]