我正在尝试运行Data Mining With R book提供的代码。它基本上将报价数据用于SP500指数(GSPC),并构建一个预测函数(T.ind)来预测未来n天的报价。
library(DMwR)
#load S&P500 Dataset
data(GSPC)
# Create a Prediction function T based on which Buy / Sell / Hold decision
# will be taken. target variation margin is 2.5%
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
}
#Plot candle chart for 3 months of Index with Avg. price and Parameter T.
candleChart(last(GSPC,'3 months'),theme='white',TA=NULL)
addAvgPrice <- newTA(FUN=avgPrice,col=1,legend='AvgPrice')
addT.ind <- newTA(FUN=T.ind,col='red',legend='tgtRet')
addT.ind()我的问题是如何从newTA()函数调用中调用T.ind。如何将所选期间的引号值传递给T.ind函数。请让我知道。
发布于 2012-04-20 04:55:29
它有点像格子图或ggolot2图,但没有"+“符号。然而,相当于“特征添加”的操作是通过副作用传递的。打印不仅是二维显示,而且也是工作空间中的对象。当您调用addT.ind()时,它的效果将应用于当前活动的图表对象,该对象具有HLC()在隐式访问candleChart()的产品结果的上下文中收集的数据。
https://stackoverflow.com/questions/10236383
复制相似问题