我知道这个问题已经被问过了,但是这里发布的所有答案都对我不起作用。我回测了一个简单的单指标策略,但最终出现以下错误:
Error in .xts(e, .index(e1), .indexCLASS = indexClass(e1), .indexFORMAT = indexFormat(e1), :
index length must match number of observations
In addition: Warning messages:
1: In match.names(column, colnames(data)) :
all columns not located in X1.runsum for bid.vol ask.vol vol bid.freq ask.freq freq bid.price ask.price price
2: In min(j, na.rm = TRUE) :
no non-missing arguments to min; returning Inf
3: In max(j, na.rm = TRUE) :
no non-missing arguments to max; returning -Inf
我正在使用的数据显示出价/询价量、总交易量、出价/询价报价、报价和一秒钟内的出价/询价交易数量:
> head(data)
bid.vol ask.vol vol bid.freq ask.freq freq bid.price ask.price price
2014-09-25 00:00:01 0.0000000 0.0722401 0.0722401 0 1 1 NA 408.110 408.110
2014-09-25 00:00:02 0.0423759 0.0430572 0.0854331 1 2 3 408.110 408.111 408.111
2014-09-25 00:00:03 0.0299792 0.1648549 0.1948341 1 4 5 408.106 408.112 408.112
2014-09-25 00:00:04 0.0000000 2.9369966 2.9369966 0 9 9 408.106 407.500 407.500
2014-09-25 00:00:05 0.0000000 0.0000000 0.0000000 0 0 0 408.106 407.500 407.500
2014-09-25 00:00:06 0.0000000 0.0000000 0.0000000 0 0 0 408.106 407.500 407.500
具有以下结构:
> str(data)
An ‘xts’ object on 2014-09-25 00:00:01/2014-10-01 23:59:50 containing:
Data: num [1:603994, 1:9] 0 0.0424 0.03 0 0 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:9] "bid.vol" "ask.vol" "vol" "bid.freq" ...
Indexed by objects of class: [POSIXct,POSIXt] TZ: CET
xts Attributes:
NULL
>
策略非常简单:当给定间隔的移动窗口上的运行总和高于或等于某个阈值时,应该有一个信号。
运行总和的指标运行良好:
add.indicator(strategy.st, name = "runSum", arguments = list(x = quote(data$ask.vol), n = lookBackVol), label = "runsum")
给
bid.vol ask.vol vol bid.freq ask.freq freq bid.price ask.price price X1.runsum
2014-09-25 00:00:01 0.0000000 0.0722401 0.0722401 0 1 1 NA 408.110 408.110 NA
2014-09-25 00:00:02 0.0423759 0.0430572 0.0854331 1 2 3 408.110 408.111 408.111 NA
2014-09-25 00:00:03 0.0299792 0.1648549 0.1948341 1 4 5 408.106 408.112 408.112 NA
2014-09-25 00:00:04 0.0000000 2.9369966 2.9369966 0 9 9 408.106 407.500 407.500 NA
2014-09-25 00:00:05 0.0000000 0.0000000 0.0000000 0 0 0 408.106 407.500 407.500 3.217149
2014-09-25 00:00:06 0.0000000 0.0000000 0.0000000 0 0 0 408.106 407.500 407.500 3.144909
但我不明白为什么 newc olumns 被称为“ X1.runsum ”,而不仅仅是参数标签 =“runsum”中所述的“runsum” 。这可能会导致调用信号时的命名问题:
> add.signal(strategy.st, name = "sigThreshold", arguments = list(column = "X1.runsum", threshold = thresholdVol, relationship = "gte", cross = TRUE), label = "longEntry")
最终会出现如开头所述的错误。
我试过这个:
- 将 add.signal 中的名称从更改
column = X1.runsum
为column = runsum
- 没有帮助 - 下载较新版本的 RRT 包 - 没有帮助
- 指标功能也有技巧
arguments = list(x = quote(data$ask.vol[,1])
- 没有帮助
我不能使用标准的 OHLC 函数,因为我的数据包含的信息不仅仅是 OHLC。
你能帮忙吗?