Use case and data

We want to build a deep neural network model to predict the movement of certain stocks. The problem is very difficult. Before we move onto building our network, let us look at our data.

To retrieve stock price data, do the following:

> library(ggplot2)
> stock.data <- new.env()
> tickers <- ('AAPL')
> stock.data <- getSymbols(tickers, src = 'yahoo', from = '2000-01-01', env = FALSE, auto.assign = F)

We leverage the package quantmod. The getSymbols function in quantmod can fetch stock information from sources such as Yahoo and Google. As you can see, we are fetching Apple's stock price data using their AAPL ticker.

Let us look at the fetched data:

> data <- stock.data$AAPL.Close
> head(data)
AAPL.Close
2000-01-03 3.997768
2000-01-04 3.660714
2000-01-05 3.714286
2000-01-06 3.392857
2000-01-07 3.553571
2000-01-10 3.491071

We are interested only in the close price. We take the closing price out and peek at the top rows.

Let us now plot the close price:

plot.data <- na.omit(data.frame(close_price = data))
names(plot.data) <- c("close_price")
ggplot(plot.data,aes(x = seq_along(close_price))) + geom_line(aes(y = close_price, color ="Close Price"))

We pull the data into a data frame called plot.data, so as to pass this conveniently to ggplot.

The ggplot line graph is as follows:

The graph shows the time series of the stock prices. It's a non-stationery time series with a definite trend and error component.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset