[R-SIG-Finance] addTA not working
George Schmoll
george.schmoll at sbcglobal.net
Thu Mar 3 18:28:35 CET 2016
I have been trying to display multiple chart using a TDNN creating a
forecast. When done on a individual time series, there is no problem.
When trying to do multiple charts, the forecast line is missing.
The entire source code follows.
library(quantmod)
library(TTR)
library(forecast)
library(nnet)
from<-as.Date("2010-12-01")
tickers<-c("MSFT")#,"ORCL","IBM","HPQ")
getSymbols(tickers,from=from,auto.assign=TRUE)
for(ticker in tickers)
{
sym <-eval((parse(text=ticker)))
clse <- Cl(sym)
hi <- Hi(sym)
lo <- Lo(sym)
vo <- Vo(sym)
DataLength <-length(clse)
MidPoint <- DataLength-10
MaxHigh <- max(hi);
MinLow <- min(lo);
MaxVol <- max(vo)
MinVol <- min(vo)
xiLag0 <- (clse-MinLow)/(MaxHigh-MinLow)
xiLag1 <- lag(xiLag0,1,na.pad=TRUE)
xiLag2 <- lag(xiLag0,2,na.pad=TRUE)
xiLag3 <- lag(xiLag0,3,na.pad=TRUE)
xiLag4 <- lag(xiLag0,4,na.pad=TRUE)
volLag0 <- (vo-MinVol)/(MaxVol-MinVol)
volLag1 <- lag(volLag0,1,na.pad=TRUE)
volLag2 <- lag(volLag0,2,na.pad=TRUE)
volLag3 <- lag(volLag0,3,na.pad=TRUE)
volLag4 <- lag(volLag0,4,na.pad=TRUE)
DeltaClose <- diff(clse)
Max <-max(na.omit(DeltaClose))
Min <-min(na.omit(DeltaClose))
scaleDeltaClose<-(DeltaClose-Min)/(Max-Min)
DeltaClose <-lag(DeltaClose,-1,na.pad=TRUE)
scaleDeltaClose<-lag(scaleDeltaClose,-1,na.pad=TRUE)
data.all <-cbind(sym,xiLag0,
xiLag1,xiLag2,xiLag3,xiLag4,
volLag0,volLag1,volLag2,volLag3,
volLag4,scaleDeltaClose)
colnames(data.all)<-c("Open","High","Low",
"Close","Volume","Adj",
"xiLag0","xiLag1","xiLag2",
"xiLag3","xiLag4","volLag0",
"volLag1","volLag2","volLag3",
"volLag4","scaleDeltaClose")
data.train <-data.all[10:MidPoint]
data.eval <-data.all[MidPoint:DataLength]
learn<-nnet(scaleDeltaClose~
xiLag0+xiLag1+xiLag2+xiLag3+xiLag4+
volLag0+volLag1+volLag2+volLag3+volLag4,
data=data.train,size=5,maxit=10000)
prdct<-predict(learn,data.eval,type="raw")
Change<-prdct*(Max-Min)+Min
Forecast<-data.eval$Close+Change
candleChart(sym,subset='2016-01::2016',name=ticker,theme="white",TA=NULL)
addTA(Forecast,col="blue",on=1)
}
Thanks in advance. George
--
<mailto:gschmoll at acm.org>
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list