Data Mining With R bookで提供されているコードを実行しようとしています。基本的にSP500インデックス(GSPC)の見積もりデータを取得し、次のn日間の見積りを予測する予測関数(T.ind)を構築します。Rデータマイニングの構文
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()
私の質問は、T.ind
がnewTA()
関数呼び出しから呼び出される方法です。選択した期間の引用符の値は、どのようにT.ind
関数に渡されますか。私にお知らせください。
Rプロンプトで 'addT.ind'とタイプし、その機能を見てください。 3行目は、T.indがどのように呼び出されるかを示しています。 – BenBarnes