2021年3月14日日曜日

金利 NASDAQ 相関 cor.test() intersect()


choose date both TNX and NDX delta is available.


 d <- intersect(index(diff(TNX[,4])[!is.na(diff(TNX[,4]))]), index(diff(NDX[,4])[!is.na(diff(NDX[,4]))]))

check outputs.


head(as.Date(d))

[1] "2007-01-04" "2007-01-05" "2007-01-09" "2007-01-10" "2007-01-11" "2007-01-12"

Check correlation in 2021.


cor.test(diff(TNX[,4])["2021"][as.Date(d)],diff(NDX[,4])["2021"][as.Date(d)])

Pearson's product-moment correlation
data:  diff(TNX[, 4])["2021"][as.Date(d)] and diff(NDX[, 4])["2021"][as.Date(d)]
t = -2.3358, df = 36, p-value = 0.02519
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.61153962 -0.04874962
sample estimates:
       cor 
-0.3627793 
 警告メッセージ: 
 z + c(-1, 1) * sigma * qnorm((1 + conf.level)/2) で: 
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.

Check correlation all time.


cor.test(diff(TNX[,4])[as.Date(d)],diff(NDX[,4])[as.Date(d)])

Pearson's product-moment correlation
data:  diff(TNX[, 4])[as.Date(d)] and diff(NDX[, 4])[as.Date(d)]
t = 9.819, df = 2787, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.1467388 0.2184915
sample estimates:
      cor 
0.1828587 
 警告メッセージ: 
 z + c(-1, 1) * sigma * qnorm((1 + conf.level)/2) で: 
  Recycling array of length 1 in array-vector arithmetic is deprecated.
  Use c() or as.vector() instead.


> plot.default(diff(TNX[,4])[as.Date(d)],diff(NDX[,4])[as.Date(d)])
> plot.default(diff(TNX[,4])["2021"][as.Date(d)],diff(NDX[,4])["2021"][as.Date(d)])

0 件のコメント: