Class: YahooFinance::Historical

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/yahoo_finance/historical.rb

Constant Summary collapse

BASE_URL =
"http://ichart.finance.yahoo.com/table.csv"
GROUPS =
{
  :daily   => "d",
  :weekly  => "w",
  :monthly => "m"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticker, options = {}) ⇒ Historical

Returns a new instance of Historical.



31
32
33
34
35
36
# File 'lib/yahoo_finance/historical.rb', line 31

def initialize(ticker, options = {})
  @ticker = ticker
  @start_date = options[:from]
  @end_date = options[:to]
  @group  = options[:group] || GROUPS[:daily]
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



9
10
11
# File 'lib/yahoo_finance/historical.rb', line 9

def end_date
  @end_date
end

#groupObject (readonly)

Returns the value of attribute group.



9
10
11
# File 'lib/yahoo_finance/historical.rb', line 9

def group
  @group
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



9
10
11
# File 'lib/yahoo_finance/historical.rb', line 9

def start_date
  @start_date
end

#tickerObject (readonly)

Returns the value of attribute ticker.



9
10
11
# File 'lib/yahoo_finance/historical.rb', line 9

def ticker
  @ticker
end

Class Method Details

.daily(ticker, options = {}) ⇒ Object



19
20
21
# File 'lib/yahoo_finance/historical.rb', line 19

def self.daily(ticker, options = {})
  new(ticker, options.merge(:group => GROUPS[:daily]))
end

.monthly(ticker, options = {}) ⇒ Object



27
28
29
# File 'lib/yahoo_finance/historical.rb', line 27

def self.monthly(ticker, options = {})
  new(ticker, options.merge(:group => GROUPS[:monthly]))
end

.weekly(ticker, options = {}) ⇒ Object



23
24
25
# File 'lib/yahoo_finance/historical.rb', line 23

def self.weekly(ticker, options = {})
  new(ticker, options.merge(:group => GROUPS[:weekly]))
end

Instance Method Details

#each(&block) ⇒ Object



38
39
40
# File 'lib/yahoo_finance/historical.rb', line 38

def each(&block)
  result.reverse_each(&block)
end

#to_csvObject



42
43
44
# File 'lib/yahoo_finance/historical.rb', line 42

def to_csv
  raw_data.lines.to_a[1..-1].join
end