yahoo_stock

DESCRIPTION:

Provides an interface to yahoo finance to get stock related data. For instance, latest trade related data, volume, 50 day moving average, market cap, etc, virtually any thing that yahoo finance provides.

If you don’t know the stock / scrip symbol of the company then you can find that out by using the YahooStock::ScripSymbol class. The methods are mentioned in the Usage section below. For instance, YHOO for yahoo, GOOG for google, etc. The kind of parameters to be passed can be found after initializing the YahooStock::Quote object and passing valid_parameters message, example is given below in the USAGE section.

USAGE:

require ‘rubygems’

require ‘yahoo_stock’

  • Initialize quote object

quote = YahooStock::Quote.new(:stock_symbols => [‘YHOO’, ‘GOOG’])

  • To view the valid parameters that can be passed

quote.valid_parameters

  • To view the current parameters used

quote.current_parameters

  • To view the current stock symbols used

quote.current_symbols

  • To add more stocks to the list

quote.add_symbols(‘MSFT’, ‘AAPL’)

  • To remove stocks from list

quote.remove_symbols(‘MSFT’, ‘AAPL’)

  • To find data for all stocks, this will give a string containing all values

quote.results

to return an array instead of a string use:

quote.results(:to_array).output to return a hash, use: quote.results(:to_hash).output to store results in a file, use: quote.results.store(‘filename’)

  • To find out the stock symbol for a company

symbol = YahooStock::ScripSymbol.new(‘Yahoo’)

  • To find all symbols for that company, this will give a string containing all values

symbol.results

to return an array instead of a string use:

symbol.results(:to_array).output to return a hash, use: symbol.results(:to_hash).output to store results in a file, use: symbol.results.store(‘filename’)

  • To find symbols for multiple companies

symbols = YahooStock::ScripSymbol.results(‘Yahoo’, ‘Company1’, ‘Company3’)

  • to get the result in a string

symbols.output

  • to store output in a file

symbols.store(‘filename’)

  • To find historical data for a stock

    history = YahooStock::History.new(:stock_symbols => ‘yhoo’, :start_date => Date.today-20, end_date => Date.today -2)

    to return an array instead of a string use:

history.results(:to_array).output to return a hash, use: history.results(:to_hash).output to store results in a file, use: history.results.store(‘filename’)

INSTALL:

gem sources -a gems.github.com

sudo gem install nas-yahoo_stock

TESTS:

Tests are written using Rspec 1.2.2

To run all tests ‘rake spec’ from the root directory

LICENSE:

(The MIT License)

Copyright © 2009 Nasir Jamal

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.