It downloads a csv file through yahoo's finance site and then parses it and prints out the date and adjusted close for each business day that has data.
1 2 require 'open-uri' 3 require 'csv' 4 5 def get_adjusted_close stock_symbol 6 puts "-- #{stock_symbol} Adjusted Close - Historical --" 7 url = "http://ichart.finance.yahoo.com/table.csv?s=#{stock_symbol}&d=7&e=1&f=2006&g=d&a=2&b=26&c=1990&ignore=.csv" 8 puts "Connecting to #{url}\n" 9 10 csv = CSV.parse(open(url).read) 11 12 csv.each{|row| 13 puts "#{row[0]} - #{row.last}" 14 } 15 puts "---------------------------------" 16 end 17 18 example_stocks = "CSCO GOOG" 19 print "Enter a series of stock symbols separated by spaces (example: #{example_stocks}) to retrieve the historical adjusted close.\n" 20 stock_symbols = gets 21 stock_symbols ||= example_stocks 22 23 stock_symbols.split.each{|symbol| 24 get_adjusted_close(symbol) 25 }