[英]R: Why this strange ccf result with xts data
I saw here that you should use drop
when passing a (single-column) XTS object to the ccf
(cross-correlation) function. 我在这里看到将(单列)XTS对象传递给
ccf
(互相关)函数时,应该使用drop
。 (The sample data is quite big, so I put it in a gist ) (示例数据很大,因此我将其概括为一 )
library(xts)
gist="https://gist.github.com/raw/3291932"
tmp1=dget(file.path(gist,"e620647218626929b4ee370a05aa7748b2f9a32b/tmp1.txt"))
tmp2=dget(file.path(gist,"49b732db3eafa52f96006e3b1bb0be28380f5df0/tmp2.txt"))
ccf(drop(tmp1),drop(tmp2)) #Weird?
I expected a small peak around lag=0, with mostly noise either side. 我预计在lag = 0附近会有一个小峰值,而两侧各有噪声。 Instead I got a straight line:
相反,我得到一条直线:
That was 400 bars. 那是400酒吧。 I got the same kind of line on my full data of thousands of bars.
在数千条的完整数据上,我得到了相同的结果。 But if I use just the tail-end 100 bars of that data I get something closer to what I expected: (50 bars looks even more plausible)
但是,如果我只使用数据的尾部100条,我得到的结果将接近我的预期:(50条看起来更合理)
I'm a bit stumped if this is a ccf
bug, a problem with the way I use xts objects, my misunderstanding of what ccf
is doing, or I've magically discovered the formula to beat the stock market... 如果这是一个
ccf
错误,我使用xts对象的方式出现问题,对ccf
正在做什么的误解,或者我已经神奇地发现了击败股市的公式,我会感到有点困惑。
Your results aren't surprising, since you're looking at the cross-correlations between stock prices . 您现在的结果并不奇怪,因为你看股票价格之间的互相关。 Prices usually have high serial auto-correlation at several lags.
价格通常在几个滞后具有较高的串行自相关。
acf(tmp1)
acf(tmp2)
Most correlation analysis is done on returns , which creates something more like what you seemed to expect: 大多数相关分析都是针对收益进行的 ,这会产生类似于您期望的结果:
ccf(drop(diff(tmp1,na.pad=FALSE)),drop(diff(tmp2,na.pad=FALSE)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.