[R-SIG-Finance] understanding xts & ccf
Joshua Ulrich
josh.m.ulrich at gmail.com
Wed Nov 9 03:37:32 CET 2011
xts objects are _always_ a matrix, even if there's only one column (a
univariate series). You need to drop the extra dimensions.
library(quantmod)
getSymbols("SPY;IEF")
ccf(Cl(SPY),Cl(IEF)) # error
ccf(drop(Cl(SPY)),drop(Cl(IEF)))
Best,
--
Joshua Ulrich | FOSS Trading: www.fosstrading.com
On Tue, Nov 8, 2011 at 8:12 PM, Eric Thungstom
<eric.thungstrom at gmail.com> wrote:
> why won't cross correlation function work in this case ?
>
>
>> ccf(sp,st)Error in ccf(sp, st) : univariate time series only
>
>
>
>> head(sp) sp
> 1993-12-31 466.45
> 1994-01-07 469.90
> 1994-01-14 474.91
> 1994-01-21 474.72
> 1994-01-28 478.70
> 1994-02-04 469.81
>
>> class(sp)[1] "xts" "zoo"
>
>> str(sp)An ‘xts’ object from 1993-12-31 to 2011-10-28 containing:
> Data: num [1:899, 1] 466 470 475 475 479 ...
> - attr(*, "dimnames")=List of 2
> ..$ : NULL
> ..$ : chr "sp"
> Indexed by objects of class: [Date] TZ:
> xts Attributes:
> NULL
>
>> head(st) stress
> 1993-12-31 -0.453
> 1994-01-07 -0.442
> 1994-01-14 -0.435
> 1994-01-21 -0.449
> 1994-01-28 -0.462
> 1994-02-04 -0.513
>
>> class(st)[1] "xts" "zoo"
>
>> str(sp)An ‘xts’ object from 1993-12-31 to 2011-10-28 containing:
> Data: num [1:899, 1] 466 470 475 475 479 ...
> - attr(*, "dimnames")=List of 2
> ..$ : NULL
> ..$ : chr "sp"
> Indexed by objects of class: [Date] TZ:
> xts Attributes:
> NULL
>
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>
More information about the R-SIG-Finance
mailing list