[R-SIG-Finance] hdf5, quantmod, xts... and dates

Daniel Cegielka daniel.cegielka at gmail.com
Wed Sep 16 16:26:25 CEST 2009


Jeff Ryan pisze:
> The problem is GOOG[,1] isn't the time index, that is stored as the
> 'index' attribute in the object:
>
>
>   
>> character(0)
>>     
>>> hdf5load('test.hdf')
>>>       
>> NULL
>>     
>>> ls()
>>>       
>> [1] "GOOG"
>>     
>>> GOOG
>>>       
>>        [,1]   [,2]   [,3]   [,4]    [,5]   [,6]
>>  [1,] 459.68 466.82 454.42 455.76 2594900 455.76
>>  [2,] 455.82 458.33 452.59 453.01 1804800 453.01
>>  [3,] 455.82 458.25 455.00 457.52 1646200 457.52
>>  [4,] 457.57 462.60 455.78 461.30 1499200 461.30
>>  [5,] 464.29 466.99 455.84 458.62 2656700 458.62
>>  [6,] 459.06 466.27 458.80 463.97 2195400 463.97
>>  [7,] 466.65 470.94 462.00 470.94 2534600 470.94
>>  [8,] 470.40 473.30 467.63 472.14 1902900 472.14
>>  [9,] 470.51 476.80 470.05 475.12 1975700 475.12
>> [10,] 475.08 478.91 472.71 477.54 2398100 477.54
>> attr(,"index")
>>  [1] 1251763200 1251849600 1251936000 1252022400 1252368000 1252454400
>>  [7] 1252540800 1252627200 1252886400 1252972800
>> attr(,".indexCLASS")
>> [1] "Date"
>> attr(,".indexTZ")
>> [1] "GMT"
>> attr(,"src")
>> [1] "yahoo"
>> attr(,"updated")
>> [1] 1253104705
>>
>>     
>
> Something like:
>
> goog <- .xts(GOOG, attr(GOOG,"index"))
>
> should work.  Note the *dot* preceding the *xts* call. This is the
> internal version that uses raw
> POSIXct timestamps for efficiency purposes.
>
> This would also work:
>
> goog <- xts(GOOG, as.POSIXct(attr(GOOG,"index"),origin="1970-01-01"))
>
>
> HTH
> Jeff
THX Jeff.. It works ;)



More information about the R-SIG-Finance mailing list