Class: YahooFinance::HistoricalQuote
- Inherits:
-
Object
- Object
- YahooFinance::HistoricalQuote
- 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
-
#adjClose ⇒ Object
Returns the value of attribute adjClose.
-
#close ⇒ Object
Returns the value of attribute close.
-
#date ⇒ Object
Returns the value of attribute date.
-
#high ⇒ Object
Returns the value of attribute high.
-
#low ⇒ Object
Returns the value of attribute low.
-
#open ⇒ Object
Returns the value of attribute open.
-
#recno ⇒ Object
Returns the value of attribute recno.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
-
#volume ⇒ Object
Returns the value of attribute volume.
Class Method Summary collapse
-
.parse_date(date) ⇒ Object
This method is obsolete since the Yahoo format change.
- .parse_date_to_Date(date) ⇒ Object
Instance Method Summary collapse
- #date_to_Date ⇒ Object
-
#initialize(sym, valarray = nil, &block) ⇒ HistoricalQuote
constructor
A new instance of HistoricalQuote.
- #to_a ⇒ Object
- #to_s ⇒ Object
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
#adjClose ⇒ Object
Returns the value of attribute adjClose.
352 353 354 |
# File 'lib/yahoofinance.rb', line 352 def adjClose @adjClose end |
#close ⇒ Object
Returns the value of attribute close.
352 353 354 |
# File 'lib/yahoofinance.rb', line 352 def close @close end |
#date ⇒ Object
Returns the value of attribute date.
351 352 353 |
# File 'lib/yahoofinance.rb', line 351 def date @date end |
#high ⇒ Object
Returns the value of attribute high.
352 353 354 |
# File 'lib/yahoofinance.rb', line 352 def high @high end |
#low ⇒ Object
Returns the value of attribute low.
352 353 354 |
# File 'lib/yahoofinance.rb', line 352 def low @low end |
#open ⇒ Object
Returns the value of attribute open.
351 352 353 |
# File 'lib/yahoofinance.rb', line 351 def open @open end |
#recno ⇒ Object
Returns the value of attribute recno.
351 352 353 |
# File 'lib/yahoofinance.rb', line 351 def recno @recno end |
#symbol ⇒ Object
Returns the value of attribute symbol.
351 352 353 |
# File 'lib/yahoofinance.rb', line 351 def symbol @symbol end |
#volume ⇒ Object
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_Date ⇒ Object
410 411 412 |
# File 'lib/yahoofinance.rb', line 410 def date_to_Date return Date.parse( @date ) end |
#to_a ⇒ Object
405 406 407 408 |
# File 'lib/yahoofinance.rb', line 405 def to_a return [] << symbol << date << open << high << low << close << volume << adjClose end |
#to_s ⇒ Object
401 402 403 |
# File 'lib/yahoofinance.rb', line 401 def to_s return "#{symbol},#{date},#{open},#{high},#{low},#{close},#{volume},#{adjClose}" end |