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.
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/yahoofinance.rb', line 340 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.
338 339 340 |
# File 'lib/yahoofinance.rb', line 338 def adjClose @adjClose end |
#close ⇒ Object
Returns the value of attribute close.
338 339 340 |
# File 'lib/yahoofinance.rb', line 338 def close @close end |
#date ⇒ Object
Returns the value of attribute date.
337 338 339 |
# File 'lib/yahoofinance.rb', line 337 def date @date end |
#high ⇒ Object
Returns the value of attribute high.
338 339 340 |
# File 'lib/yahoofinance.rb', line 338 def high @high end |
#low ⇒ Object
Returns the value of attribute low.
338 339 340 |
# File 'lib/yahoofinance.rb', line 338 def low @low end |
#open ⇒ Object
Returns the value of attribute open.
337 338 339 |
# File 'lib/yahoofinance.rb', line 337 def open @open end |
#recno ⇒ Object
Returns the value of attribute recno.
337 338 339 |
# File 'lib/yahoofinance.rb', line 337 def recno @recno end |
#symbol ⇒ Object
Returns the value of attribute symbol.
337 338 339 |
# File 'lib/yahoofinance.rb', line 337 def symbol @symbol end |
#volume ⇒ Object
Returns the value of attribute volume.
338 339 340 |
# File 'lib/yahoofinance.rb', line 338 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.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/yahoofinance.rb', line 365 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
383 384 385 |
# File 'lib/yahoofinance.rb', line 383 def HistoricalQuote.parse_date_to_Date( date ) return Date.parse( parse_date( date ) ) end |
Instance Method Details
#date_to_Date ⇒ Object
396 397 398 |
# File 'lib/yahoofinance.rb', line 396 def date_to_Date return Date.parse( @date ) end |
#to_a ⇒ Object
391 392 393 394 |
# File 'lib/yahoofinance.rb', line 391 def to_a return [] << symbol << date << open << high << low << close << volume << adjClose end |
#to_s ⇒ Object
387 388 389 |
# File 'lib/yahoofinance.rb', line 387 def to_s return "#{symbol},#{date},#{open},#{high},#{low},#{close},#{volume},#{adjClose}" end |