library(readr)
library(ggplot2)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
Importing Unilever Stock Prices
Source: Yahoo Finance
Monthly frequency: 08/04/2015-08/04/2020
Uni <- read.csv("/Users/dorothymensah/Desktop/UN.csv")

#Time Series

Uni.ts <- ts(Uni$Adj.Close,frequency = 12, start = c(2015,1))

autoplot(Uni.ts) + xlab("Month") + ylab("Adjusted Monthly Close Price")

There is some obvious seasonality to this dataset with an upward trend overtime

NEURAL NET MODEL

Uni.nn <-nnetar(Uni.ts, lambda = 0)
Uni.nn
## Series: Uni.ts 
## Model:  NNAR(1,1,2)[12] 
## Call:   nnetar(y = Uni.ts, lambda = 0)
## 
## Average of 20 networks, each of which is
## a 2-2-1 network with 9 weights
## options were - linear output units 
## 
## sigma^2 estimated as 0.001727
#forecast
Uni.nna <- forecast(Uni.nn,h=24)
autoplot(Uni.nna)+xlab("Month")+ ylab("Monthly Adjusted Close Price") 

##The model chose a NNAR(1,1,2) for this 24 month forecast 

##Comparing this to a non-bootstrap example 

Uni.nn2 <- nnetar(Uni.ts, lambda = 0, bootstrap=FALSE)
Uni.nn2
## Series: Uni.ts 
## Model:  NNAR(1,1,2)[12] 
## Call:   nnetar(y = Uni.ts, lambda = 0, bootstrap = FALSE)
## 
## Average of 20 networks, each of which is
## a 2-2-1 network with 9 weights
## options were - linear output units 
## 
## sigma^2 estimated as 0.001674
##Forecast

autoplot(forecast(Uni.nn2,h=24))

The autoselection system chose the same model for both forecasts. However, there is a slight change observed in the model without the bootstrap method.