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'를 입력하고 함수를 살펴보십시오. 세 번째 줄은 T.ind가 어떻게 호출되는지 보여줍니다. – BenBarnes