Class: YahooFinance::HistoricalQuote

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoofinance.rb

Overview

‘Historical’ quote retrieval.

Constant Summary collapse

@@date_re =
/([0-9]{1,2})-([A-Za-z]+)-([0-9]{1,2})/
@@months =
%w( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sym, valarray = nil, &block) ⇒ HistoricalQuote

Returns a new instance of HistoricalQuote.



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/yahoofinance.rb', line 354

def initialize( sym, valarray=nil, &block )
  @symbol = sym.upcase
  if valarray

    @date = HistoricalQuote.parse_date( valarray[0] )
    @open = valarray[1].to_f
    @high = valarray[2].to_f
    @low = valarray[3].to_f
    @close = valarray[4].to_f
    @volume = valarray[5].to_i
    @adjClose = valarray[6].to_f
    @recno = valarray[7].to_i if valarray.size >= 8
  end
  if block_given?
    instance_eval( &block )
  end
end

Instance Attribute Details

#adjCloseObject

Returns the value of attribute adjClose.



352
353
354
# File 'lib/yahoofinance.rb', line 352

def adjClose
  @adjClose
end

#closeObject

Returns the value of attribute close.



352
353
354
# File 'lib/yahoofinance.rb', line 352

def close
  @close
end

#dateObject

Returns the value of attribute date.



351
352
353
# File 'lib/yahoofinance.rb', line 351

def date
  @date
end

#highObject

Returns the value of attribute high.



352
353
354
# File 'lib/yahoofinance.rb', line 352

def high
  @high
end

#lowObject

Returns the value of attribute low.



352
353
354
# File 'lib/yahoofinance.rb', line 352

def low
  @low
end

#openObject

Returns the value of attribute open.



351
352
353
# File 'lib/yahoofinance.rb', line 351

def open
  @open
end

#recnoObject

Returns the value of attribute recno.



351
352
353
# File 'lib/yahoofinance.rb', line 351

def recno
  @recno
end

#symbolObject

Returns the value of attribute symbol.



351
352
353
# File 'lib/yahoofinance.rb', line 351

def symbol
  @symbol
end

#volumeObject

Returns the value of attribute volume.



352
353
354
# File 'lib/yahoofinance.rb', line 352

def volume
  @volume
end

Class Method Details

.parse_date(date) ⇒ Object

This method is obsolete since the Yahoo format change. However, I am leaving it here for API stability.



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/yahoofinance.rb', line 379

def HistoricalQuote.parse_date( date )
  # Yahoo changed the format of the date column. It is now in the
  # same format as this method returned, so this method just
  # returns the same date.
  return date
#       md = @@date_re.match( date )
#       if md
#         if md[3].to_i > 30
#           year = "19#{md[3]}"
#         else
#           year = "20#{md[3]}"
#         end
#         return "#{year}-%02d-%02d" % [(@@months.index(md[2]) + 1), md[1].to_i]
#       else
#         return date
#       end
end

.parse_date_to_Date(date) ⇒ Object



397
398
399
# File 'lib/yahoofinance.rb', line 397

def HistoricalQuote.parse_date_to_Date( date )
  return Date.parse( parse_date( date ) )
end

Instance Method Details

#date_to_DateObject



410
411
412
# File 'lib/yahoofinance.rb', line 410

def date_to_Date
  return Date.parse( @date )
end

#to_aObject



405
406
407
408
# File 'lib/yahoofinance.rb', line 405

def to_a
  return [] << symbol << date << open << high << 
    low << close << volume << adjClose
end

#to_sObject



401
402
403
# File 'lib/yahoofinance.rb', line 401

def to_s
  return "#{symbol},#{date},#{open},#{high},#{low},#{close},#{volume},#{adjClose}"
end