Fetch data from Yahoo

suppressWarnings(suppressMessages(library(quantmod)))

ocbc = getSymbols("O39.SI", auto.assign=F, from = "2018-01-01", to = "2018-07-27")
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
## 
## This message is shown once per session and may be disabled by setting 
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## 
## WARNING: There have been significant changes to Yahoo Finance data.
## Please see the Warning section of '?getSymbols.yahoo' for details.
## 
## This message is shown once per session and may be disabled by setting
## options("getSymbols.yahoo.warning"=FALSE).

Traditional Plot Closing Price. Plot does not indicate the x-axis well

plot(as.ts(ocbc$O39.SI.Close))

Using library Zoo and Forecast

library(zoo)
myts <-zoo(ocbc$O39.SI.Close, seq(from = as.Date("2018-01-01"), to = as.Date("2018-07-27"), by = 1))

library(forecast)
myts <- tsclean(myts)
plot(myts)

Set up a Neural Network model

mynnetar <- nnetar(myts)

Forecast 30 day with the model

nnetforecast <- forecast(mynnetar, h = 30,PI = T)
autoplot(nnetforecast)

## interactive dygraph
# data we need for the graph
data <- nnetforecast$x
lower <- nnetforecast$lower[,2]
upper <- nnetforecast$upper[,2]
pforecast <- nnetforecast$mean
mydata <- cbind(data, lower, upper, pforecast)

Use a MOUSE and review in PC, not phone

library(dygraphs)

dygraph(mydata, main = "Stock Price") %>% 
  dyRangeSelector() %>% 
  dySeries(name = "data", label = "Price Data") %>%
  dySeries(c("lower","pforecast","upper"), label = "Price Forecast") %>%
  dyLegend(show = "always", hideOnMouseOut = FALSE) %>%
  dyAxis("y", label = "Daily Price") %>%
  dyHighlight(highlightCircleSize = 5,highlightSeriesOpts = list(strokeWidth = 2)) %>%
  dyOptions(axisLineColor = "navy", gridLineColor = "grey") %>%
  dyAnnotation("2018-7-24", text = "JL", tooltip = "JAMES LIM", attachAtBottom = T)