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

Jeff Ryan jeff.a.ryan at gmail.com
Wed Sep 16 16:10:44 CEST 2009


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
>
>> xts(GOOG[,],as.Date(GOOG[,1]))
>             [,1]   [,2]   [,3]   [,4]    [,5]   [,6]
> 1971-04-01 455.82 458.33 452.59 453.01 1804800 453.01
> 1971-04-01 455.82 458.25 455.00 457.52 1646200 457.52
> 1971-04-03 457.57 462.60 455.78 461.30 1499200 461.30
> 1971-04-05 459.06 466.27 458.80 463.97 2195400 463.97
> 1971-04-05 459.68 466.82 454.42 455.76 2594900 455.76
> 1971-04-10 464.29 466.99 455.84 458.62 2656700 458.62
> 1971-04-12 466.65 470.94 462.00 470.94 2534600 470.94
> 1971-04-16 470.40 473.30 467.63 472.14 1902900 472.14
> 1971-04-16 470.51 476.80 470.05 475.12 1975700 475.12
> 1971-04-21 475.08 478.91 472.71 477.54 2398100 477.54
>
>
>> xts(GOOG[,],as.POSIXct(GOOG[,1],origin='1970-01-01'))
>                      [,1]   [,2]   [,3]   [,4]    [,5]   [,6]
> 1970-01-01 00:07:35 455.82 458.33 452.59 453.01 1804800 453.01
> 1970-01-01 00:07:35 455.82 458.25 455.00 457.52 1646200 457.52
> 1970-01-01 00:07:37 457.57 462.60 455.78 461.30 1499200 461.30
> 1970-01-01 00:07:39 459.06 466.27 458.80 463.97 2195400 463.97
> 1970-01-01 00:07:39 459.68 466.82 454.42 455.76 2594900 455.76
> 1970-01-01 00:07:44 464.29 466.99 455.84 458.62 2656700 458.62
> 1970-01-01 00:07:46 466.65 470.94 462.00 470.94 2534600 470.94
> 1970-01-01 00:07:50 470.40 473.30 467.63 472.14 1902900 472.14
> 1970-01-01 00:07:50 470.51 476.80 470.05 475.12 1975700 475.12
> 1970-01-01 00:07:55 475.08 478.91 472.71 477.54 2398100 477.54
>
>
>> xts(GOOG[,],as.Date(GOOG[,1],origin='1970-01-01'))
>             [,1]   [,2]   [,3]   [,4]    [,5]   [,6]
> 1971-04-01 455.82 458.33 452.59 453.01 1804800 453.01
> 1971-04-01 455.82 458.25 455.00 457.52 1646200 457.52
> 1971-04-03 457.57 462.60 455.78 461.30 1499200 461.30
> 1971-04-05 459.06 466.27 458.80 463.97 2195400 463.97
> 1971-04-05 459.68 466.82 454.42 455.76 2594900 455.76
> 1971-04-10 464.29 466.99 455.84 458.62 2656700 458.62
> 1971-04-12 466.65 470.94 462.00 470.94 2534600 470.94
> 1971-04-16 470.40 473.30 467.63 472.14 1902900 472.14
> 1971-04-16 470.51 476.80 470.05 475.12 1975700 475.12
> 1971-04-21 475.08 478.91 472.71 477.54 2398100 477.54
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list