【问题标题】:R data mining syntaxR 数据挖掘语法
【发布时间】:2012-05-01 10:59:21
【问题描述】:

我正在尝试运行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 函数。请告诉我。

【问题讨论】:

  • 在 R 提示符下输入 addT.ind 并查看函数。第三行显示了如何调用 T.ind。

标签: r statistics data-mining xts quantmod


【解决方案1】:

这有点像 lattice 或 ggolot2 图,但没有“+”号。然而,相当于“特征添加”的操作是通过副作用传递的。绘图不仅是 2D 显示,而且还是工作区中的一个对象。当您调用 addT.ind() 时,它的效果将应用于当前活动的图表对象,该对象具有 HLC() 在隐式访问烛图 () 产品结果的上下文中收集的数据。

【讨论】:

    猜你喜欢
    • 2019-04-24
    • 2011-05-17
    • 1970-01-01
    • 2011-06-16
    • 2012-12-30
    • 2011-02-07
    • 1970-01-01
    • 2011-07-28
    • 2011-11-28
    相关资源
    最近更新 更多