我正在努力(重新)建立标准普尔500指数的基本预测模型(数据来自雅虎财经)
我对数据集的"排序"遇到了一些困难.
在data.model的构建期间,发生以下错误
xts(new.x,x.index)中的错误:NROW(x)必须匹配length(order.by)
经过一些研究后,我意识到问题在于排序,并且它似乎缺乏基础动物园包所需的排序.
有没有一种优雅的方法来解决这个问题?!提前致谢
library(xts)
library(tseries)
library(quantmod)
GSPC <- as.xts(get.hist.quote("^GSPC",start="1970-01-02",
quote=c("Open", "High", "Low", "Close","Volume","AdjClose")))
head(GSPC)
T.ind <- function(quotes, tgt.margin = 0.025, n.days = 10) {
v <- apply(HLC(quotes), 1, mean)
r <- matrix(NA, ncol = n.days, nrow = NROW(quotes))
for (x in 1:n.days) r[, x] <- Next(Delt(v, k = x), x)
x <- apply(r, 1, function(x) sum(x[x > tgt.margin | x <
-tgt.margin]))
if (is.xts(quotes))
xts(x, time(quotes))
else x
}
myATR <- function(x) ATR(HLC(x))[, "atr"]
mySMI <- function(x) …
Run Code Online (Sandbox Code Playgroud)