save XTS

4 messages Options
Embed this post
Permalink
zubin-2

save XTS

Reply Threaded More More options
Print post
Permalink
Hello, have an XTS object, simply trying to save, but when i open the
saved file and review the XTS object, its different, and most of the
data does not exist.  How does one save an XTS object correctly?

Found this link but no mention;  
http://old.nabble.com/write.xts%28%29-and-read.xts%28%29-td25613485.html


example:  XTS object called VDF
 > str(vdf)
An 'xts' object from 2009-10-16 09:30:02 to 2009-10-16 15:59:56 containing:
  Data: num [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
  xts Attributes:
 NULL
 > head(vdf)
                      FAS   VIX  UUP   USO    GLD   HYG  term   spread   TNX
2009-10-16 09:30:02 87.26 21.72 22.5 39.88 102.74 85.99 4.214 0.826827 3.443
2009-10-16 09:30:10 87.24 21.72 22.5 39.88 102.77 85.99 4.214 0.826827 3.443
2009-10-16 09:30:17 87.23 21.72 22.5 39.88 102.74 85.99 4.214 0.826827 3.443
2009-10-16 09:30:25 87.23 21.72 22.5 39.89 102.74 85.99 4.209 0.826827 3.438
2009-10-16 09:30:33 87.23 21.72 22.5 39.90 102.74 85.99 4.209 0.826827 3.438
2009-10-16 09:30:40 87.23 21.72 22.5 39.90 102.76 85.99 4.209 0.826827 3.438

I now save:
 > save(vdf,file="vdf.Rdata")

I then open up vdf.Rdata, very different and i lose data.

str(vdf)
 xts [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
 - attr(*, "index")= num [1:2919] 1.26e+09 1.26e+09 1.26e+09 1.26e+09
1.26e+09 ...
 - attr(*, ".indexTZ")= Named chr "GMT"
  ..- attr(*, "names")= chr "TZ"
 - attr(*, ".indexCLASS")= chr [1:2] "POSIXt" "POSIXct"
 - attr(*, "class")= chr [1:2] "xts" "zoo"

 > head(vdf)
[1] 87.26 87.24 87.23 87.23 87.23 87.23
 >

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Joshua Ulrich

Re: save XTS

Reply Threaded More More options
Print post
Permalink
Did you load xts via "library(xts)" before you tried to use the xts object?

Best,
Josh
--
http://www.fosstrading.com



On Mon, Nov 2, 2009 at 5:18 PM, zubin <[hidden email]> wrote:

> Hello, have an XTS object, simply trying to save, but when i open the
> saved file and review the XTS object, its different, and most of the
> data does not exist.  How does one save an XTS object correctly?
>
> Found this link but no mention;
> http://old.nabble.com/write.xts%28%29-and-read.xts%28%29-td25613485.html
>
>
> example:  XTS object called VDF
>  > str(vdf)
> An 'xts' object from 2009-10-16 09:30:02 to 2009-10-16 15:59:56 containing:
>  Data: num [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
>  - attr(*, "dimnames")=List of 2
>  ..$ : NULL
>  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
>  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
>  xts Attributes:
>  NULL
>  > head(vdf)
>                      FAS   VIX  UUP   USO    GLD   HYG  term   spread   TNX
> 2009-10-16 09:30:02 87.26 21.72 22.5 39.88 102.74 85.99 4.214 0.826827 3.443
> 2009-10-16 09:30:10 87.24 21.72 22.5 39.88 102.77 85.99 4.214 0.826827 3.443
> 2009-10-16 09:30:17 87.23 21.72 22.5 39.88 102.74 85.99 4.214 0.826827 3.443
> 2009-10-16 09:30:25 87.23 21.72 22.5 39.89 102.74 85.99 4.209 0.826827 3.438
> 2009-10-16 09:30:33 87.23 21.72 22.5 39.90 102.74 85.99 4.209 0.826827 3.438
> 2009-10-16 09:30:40 87.23 21.72 22.5 39.90 102.76 85.99 4.209 0.826827 3.438
>
> I now save:
>  > save(vdf,file="vdf.Rdata")
>
> I then open up vdf.Rdata, very different and i lose data.
>
> str(vdf)
>  xts [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
>  - attr(*, "dimnames")=List of 2
>  ..$ : NULL
>  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
>  - attr(*, "index")= num [1:2919] 1.26e+09 1.26e+09 1.26e+09 1.26e+09
> 1.26e+09 ...
>  - attr(*, ".indexTZ")= Named chr "GMT"
>  ..- attr(*, "names")= chr "TZ"
>  - attr(*, ".indexCLASS")= chr [1:2] "POSIXt" "POSIXct"
>  - attr(*, "class")= chr [1:2] "xts" "zoo"
>
>  > head(vdf)
> [1] 87.26 87.24 87.23 87.23 87.23 87.23
>  >
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
Jeff Ryan

Re: save XTS

Reply Threaded More More options
Print post
Permalink
The fact that you see a class attribute is a red flag that you haven't  
loaded the appropriate package, as Josh has also alluded to.

This is due to the fact that R hasn't any methods to handle zoo or xts  
natively, so you just see attributes. print.xts hides this normally.

HTH
Jeff

Jeffrey A. Ryan
[hidden email]

ia: insight algorithmics
www.insightalgo.com

On Nov 2, 2009, at 5:23 PM, Joshua Ulrich <[hidden email]>  
wrote:

> Did you load xts via "library(xts)" before you tried to use the xts  
> object?
>
> Best,
> Josh
> --
> http://www.fosstrading.com
>
>
>
> On Mon, Nov 2, 2009 at 5:18 PM, zubin <[hidden email]> wrote:
>> Hello, have an XTS object, simply trying to save, but when i open the
>> saved file and review the XTS object, its different, and most of the
>> data does not exist.  How does one save an XTS object correctly?
>>
>> Found this link but no mention;
>> http://old.nabble.com/write.xts%28%29-and-read.xts%28%29-td25613485.html
>>
>>
>> example:  XTS object called VDF
>>  > str(vdf)
>> An 'xts' object from 2009-10-16 09:30:02 to 2009-10-16 15:59:56  
>> containing:
>>  Data: num [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
>>  - attr(*, "dimnames")=List of 2
>>  ..$ : NULL
>>  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
>>  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
>>  xts Attributes:
>>  NULL
>>  > head(vdf)
>>                      FAS   VIX  UUP   USO    GLD   HYG  term    
>> spread   TNX
>> 2009-10-16 09:30:02 87.26 21.72 22.5 39.88 102.74 85.99 4.214 0.826827
>>  3.443
>> 2009-10-16 09:30:10 87.24 21.72 22.5 39.88 102.77 85.99 4.214 0.826827
>>  3.443
>> 2009-10-16 09:30:17 87.23 21.72 22.5 39.88 102.74 85.99 4.214 0.826827
>>  3.443
>> 2009-10-16 09:30:25 87.23 21.72 22.5 39.89 102.74 85.99 4.209 0.826827
>>  3.438
>> 2009-10-16 09:30:33 87.23 21.72 22.5 39.90 102.74 85.99 4.209 0.826827
>>  3.438
>> 2009-10-16 09:30:40 87.23 21.72 22.5 39.90 102.76 85.99 4.209 0.826827
>>  3.438
>>
>> I now save:
>>  > save(vdf,file="vdf.Rdata")
>>
>> I then open up vdf.Rdata, very different and i lose data.
>>
>> str(vdf)
>>  xts [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
>>  - attr(*, "dimnames")=List of 2
>>  ..$ : NULL
>>  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
>>  - attr(*, "index")= num [1:2919] 1.26e+09 1.26e+09 1.26e+09 1.26e+09
>> 1.26e+09 ...
>>  - attr(*, ".indexTZ")= Named chr "GMT"
>>  ..- attr(*, "names")= chr "TZ"
>>  - attr(*, ".indexCLASS")= chr [1:2] "POSIXt" "POSIXct"
>>  - attr(*, "class")= chr [1:2] "xts" "zoo"
>>
>>  > head(vdf)
>> [1] 87.26 87.24 87.23 87.23 87.23 87.23
>>  >
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>>
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.
zubin-2

Re: save XTS

Reply Threaded More More options
Print post
Permalink
yep, that was it.  loaded quantmod library, all is well.  thx

-zubin


J Ryan wrote:

> The fact that you see a class attribute is a red flag that you haven't
> loaded the appropriate package, as Josh has also alluded to.
>
> This is due to the fact that R hasn't any methods to handle zoo or xts
> natively, so you just see attributes. print.xts hides this normally.
>
> HTH
> Jeff
>
> Jeffrey A. Ryan
> [hidden email]
>
> ia: insight algorithmics
> www.insightalgo.com
>
> On Nov 2, 2009, at 5:23 PM, Joshua Ulrich <[hidden email]>
> wrote:
>
>> Did you load xts via "library(xts)" before you tried to use the xts
>> object?
>>
>> Best,
>> Josh
>> --
>> http://www.fosstrading.com
>>
>>
>>
>> On Mon, Nov 2, 2009 at 5:18 PM, zubin <[hidden email]> wrote:
>>> Hello, have an XTS object, simply trying to save, but when i open the
>>> saved file and review the XTS object, its different, and most of the
>>> data does not exist.  How does one save an XTS object correctly?
>>>
>>> Found this link but no mention;
>>> http://old.nabble.com/write.xts%28%29-and-read.xts%28%29-td25613485.html 
>>>
>>>
>>>
>>> example:  XTS object called VDF
>>>  > str(vdf)
>>> An 'xts' object from 2009-10-16 09:30:02 to 2009-10-16 15:59:56
>>> containing:
>>>  Data: num [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
>>>  - attr(*, "dimnames")=List of 2
>>>  ..$ : NULL
>>>  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
>>>  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
>>>  xts Attributes:
>>>  NULL
>>>  > head(vdf)
>>>                      FAS   VIX  UUP   USO    GLD   HYG  term  
>>> spread   TNX
>>> 2009-10-16 09:30:02 87.26 21.72 22.5 39.88 102.74 85.99 4.214
>>> 0.826827 3.443
>>> 2009-10-16 09:30:10 87.24 21.72 22.5 39.88 102.77 85.99 4.214
>>> 0.826827 3.443
>>> 2009-10-16 09:30:17 87.23 21.72 22.5 39.88 102.74 85.99 4.214
>>> 0.826827 3.443
>>> 2009-10-16 09:30:25 87.23 21.72 22.5 39.89 102.74 85.99 4.209
>>> 0.826827 3.438
>>> 2009-10-16 09:30:33 87.23 21.72 22.5 39.90 102.74 85.99 4.209
>>> 0.826827 3.438
>>> 2009-10-16 09:30:40 87.23 21.72 22.5 39.90 102.76 85.99 4.209
>>> 0.826827 3.438
>>>
>>> I now save:
>>>  > save(vdf,file="vdf.Rdata")
>>>
>>> I then open up vdf.Rdata, very different and i lose data.
>>>
>>> str(vdf)
>>>  xts [1:2919, 1:9] 87.3 87.2 87.2 87.2 87.2 ...
>>>  - attr(*, "dimnames")=List of 2
>>>  ..$ : NULL
>>>  ..$ : chr [1:9] "FAS" "VIX" "UUP" "USO" ...
>>>  - attr(*, "index")= num [1:2919] 1.26e+09 1.26e+09 1.26e+09 1.26e+09
>>> 1.26e+09 ...
>>>  - attr(*, ".indexTZ")= Named chr "GMT"
>>>  ..- attr(*, "names")= chr "TZ"
>>>  - attr(*, ".indexCLASS")= chr [1:2] "POSIXt" "POSIXct"
>>>  - attr(*, "class")= chr [1:2] "xts" "zoo"
>>>
>>>  > head(vdf)
>>> [1] 87.26 87.24 87.23 87.23 87.23 87.23
>>>  >
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>> -- Subscriber-posting only.
>>> -- If you want to post, subscribe first.
>>>
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.