我正面临这个问题,无法解决:这是代码:
library(quantmod)
library(TTR)
library(randomForest)
getSymbols('^STOXX50E', src='yahoo')
equity.index<-STOXX50E
myReturnsSign = function(x) sign(Delt(Cl(x),type="log"))[-1]
mySMA =function(x,n) SMA(Cl(x),n)[-1]
myEMA = function(x,n,ratio) EMA(Cl(x),n,ratio)[-1]
model1<-specifyModel(myReturnsSign(equity.index) ~ myEMA(equity.index,20,0.8) + mySMA (equity.index,5))
这是错误消息:
Error in xts(model.frame(model@model.spec, data = env, na.action = NULL), :
NROW(x) must match length(order.by)
然而 :
> dim(myEMA(equity.index,20,0.8))
[1] 2632 1
> dim(mySMA(equity.index,5))
[1] 2632 1
> dim(myReturnsSign(equity.index))
[1] 2632 1