[R-SIG-Finance] addTA not working

George Schmoll george.schmoll at sbcglobal.net
Thu Mar 3 20:00:20 CET 2016


Thank you for your time. I guess I did not search enough. Both 
techniques worked. George

On 3/3/2016 12:27 PM, Joshua Ulrich wrote:
> This question has been asked many, many times on this list and on
> StackOverflow.  You need to either 1) include the addTA call in your
> chartSeries call, or 2) wrap the addTA call in plot().
>
> # 1)
> candleChart(sym, subset='2016-01::2016', name=ticker,
>    theme="white", TA='addTA(Forecast,col="blue",on=1)')
> # 2)
> candleChart(sym, subset='2016-01::2016', name=ticker, theme="white", TA=NULL)
> plot(addTA(Forecast,col="blue",on=1))
>
> On Thu, Mar 3, 2016 at 11:28 AM, George Schmoll
> <george.schmoll at sbcglobal.net> wrote:
>> 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]]
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
>
>



More information about the R-SIG-Finance mailing list