0

我正在尝试绘制滚动线性回归,但出现以下错误:

if (any(by < 0L) || any(by > nc)) stop("'by' must match numbers of columns") 中的错误:需要 TRUE/FALSE 的地方缺少值

相关代码为:

library(TTR)

mydata <-read.csv("EURUSD2.csv", sep=",",header=TRUE)
gh<-as.matrix(mydata)
reg <- rollSFM(mydata[, "PRICE"], 1:nrow(mydata), n=5)

这是 CSV 文件的示例:

BAR,PRICE,HIGH,LOW
0,113.3035,113.306,113.282
1,113.306,113.311,113.296
2,113.306,113.312,113.302
3,113.297,113.308,113.297
4,113.2875,113.304,113.285
5,113.2975,113.298,113.29
6,113.278,113.303,113.278
7,113.2915,113.294,113.28
8,113.3,113.3,113.284
9,113.298,113.302,113.296
10,113.3195,113.32,113.3
11,113.3275,113.336,113.32

为什么它不接受这些数据?

4

1 回答 1

0

我想到了。您只需为数据提供自己的索引。例如:

xts1 <- xts(mydata[, "PRICE"], order.by=Sys.Date()+1:length(mydata[, "BAR"]))
reg <- rollSFM(xts1, .index(xts1), 2)
rma <- reg$alpha + reg$beta*.index(xts1)
于 2020-12-08T14:14:54.680 回答