Introduction

The aim of this assignment is to analyze the trend and seasonality of the data ASX All Ordinaries Price Index between January 2003 and May 2017 in Australia Share Market and come to an end with a forecast for 5 months ahead of all ords price index.

setwd("~/Downloads")
library(expsmooth)
## Loading required package: forecast
library(forecast)
ASX <- read.csv("ASX.csv", header = TRUE, sep = ',')
View(ASX)
class(ASX)
## [1] "data.frame"
ASX.ts <- ts(ASX$price, start = c(2003,1), end = c(2017,5), frequency = 12)
ASX.ts
##          Jan     Feb     Mar     Apr     May     Jun     Jul     Aug
## 2003 5761.30 5947.60 5903.80 5761.00 5675.00 5719.10 5502.40 5402.40
## 2004 5447.80 5316.00 5151.80 4947.90 5056.60 5344.60 5218.20 5288.60
## 2005 5774.90 5773.67 5861.90 5898.50 5551.60 5388.60 5298.10 5505.02
## 2006 5473.80 5470.80 5403.00 5415.40 5205.10 5353.10 5314.30 5420.30
## 2007 4914.00 5168.60 4979.90 5120.40 4901.00 4664.60 4518.00 4535.40
## 2008 4133.70 4467.20 4420.00 4388.10 4325.70 4111.00 4184.67 4360.50
## 2009 4788.90 4899.00 4928.60 4923.60 4849.90 4846.90 4676.40 4733.40
## 2010 4453.60 4833.90 4893.10 4651.10 4596.90 4882.70 4715.50 4646.90
## 2011 3813.30 3744.70 3532.30 3296.90 3478.10 3659.30 3672.70 3982.70
## 2012 5773.90 5656.90 5409.70 5674.70 5697.00 6421.00 6593.60 6779.10
## 2013 6341.80 6158.30 5978.80 5816.50 5757.70 5644.30 5461.60 5352.90
## 2014 4972.30 5207.00 5087.20 4878.40 4880.20 5644.30 5461.60 5352.90
## 2015 4972.30 5207.00 5087.20 4878.40 4880.20 4053.10 3942.80 3786.30
## 2016 3456.90 3407.70 3416.40 3372.50 3283.60 3306.00 3195.70 3282.40
## 2017 2979.80 2970.90 2848.60 2778.40 2935.40                        
##          Sep     Oct     Nov     Dec
## 2003 5525.20 5529.40 5644.00 5310.40
## 2004 5058.60 5222.10 5681.70 5451.20
## 2005 5296.80 5624.60 5623.10 5382.00
## 2006 5217.70 5125.30 5035.70 4775.40
## 2007 4406.30 4339.00 4289.40 4135.50
## 2008 4070.10 4369.90 4500.50 4659.80
## 2009 4636.90 4438.80 4507.40 4324.80
## 2010 4739.30 4484.10 4249.50 3947.80
## 2011 4631.30 5215.50 5052.60 5332.80
## 2012 6580.90 6248.30 6187.50 6310.60
## 2013 5113.00 5079.80 4957.10 5034.00
## 2014 5113.00 5079.80 4957.10 5034.00
## 2015 3674.70 3561.90 3546.10 3530.30
## 2016 3176.20 3202.90 3106.70 2999.70
## 2017

The question 1: Checking whether the seasonality has seasonality

1 - Visualization of times series

par(mfrow = c(1,1))
plot(ASX.ts, ylab = "The price Index (AUD) ", xlab = " Year", main = " The ASX All Ordinaries Price index", type = "o")

From the plot above, we can see that there is not any seasonality in the series. But we need further proof by using ACF and PACF

par(mfrow = c(1,2))
acf(ASX.ts, main = " Sample ACF for ASX All Ordinaries Price index ")
pacf(ASX.ts, main = "Sample PACF for ASX All Ordinaries Price index")

Because we have a slowly decreasing pattern in ACF and a very high PACF value at the first lag, we infer that there is a trend in the series which dominates the series correlation properties of the series. But, in addition to trend, we observe that there is no existence of seasonality since the lack of wave pattern within the slowly decreasing pattern in ACF in this series. Also, the number of lags on x-axis does not shows the periods.

The question 2: Nonstationarity and Stationarity of data

To check the nonstationarity or stationarity of data, we are going to run the Unit root tests. The aim of this checking is to clarify whether or not the behavior of the process changes over time. we are using the 95% CI to make the conclusion of these tests.

1- Assumption: * Ho: The series is nonstationary * Ha: The series is stationary

The ADF test:

library(tseries)
k = ar(ASX.ts)$order
print(k)
## [1] 2
adf.test(ASX.ts, k = k)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  ASX.ts
## Dickey-Fuller = -1.7984, Lag order = 2, p-value = 0.6605
## alternative hypothesis: stationary

Note that the P value for this test is 0.6605 >> 0.05, therefore, we do not have proof to reject Ho. That means the series is non-stationary.

The PP test

PP.test(ASX.ts, lshort = TRUE)
## 
##  Phillips-Perron Unit Root Test
## 
## data:  ASX.ts
## Dickey-Fuller = -1.7556, Truncation lag parameter = 4, p-value =
## 0.6783
PP.test(ASX.ts, lshort = FALSE) 
## 
##  Phillips-Perron Unit Root Test
## 
## data:  ASX.ts
## Dickey-Fuller = -1.9666, Truncation lag parameter = 13, p-value =
## 0.5902

According to the PP test, ASX.ts series is nonstationary at 5% level.

Making them stationary

Because the series is not seasonal, then we use the ordinary differencing to make them stationary.

ASX1 <- ts.intersect(ASX.ts, diff(ASX.ts) , diff(ASX.ts, differences = 2))
colnames(ASX1) = c("Original", "1st difference", "2nd difference")
plot(ASX1, yax.flip = T)

The second differencing made it bounce more closely around the mean level. That means, the second difference make the series stationary.

In the first question, through visualision of series, ACF and PACF, we can partly define that the series has a downward trend but does not have any seasonality. Now by using STL Decomposition of time series, we are going to analyze deeply into the observation of the individual effects namely trend effect and seasonal effect.

The question 3: The effection of trend on the series

fit.ASX <- stl(ASX.ts, t.window = 15, s.window = "periodic", robust = TRUE)
plot(fit.ASX)

fit.ASX.trend = fit.ASX$time.series[,"trend"]
ASX.ts.trend.adjusted = ASX.ts - fit.ASX.trend
par(mfrow = c(1,2))
plot(ASX.ts.trend.adjusted, ylab = "The price Index (AUD)", xlab = "Time", main = "Trend adjusted ASX All Ordinaries Price index")
plot(ASX.ts, ylab = "The price Index (AUD) ", xlab = " Year", main = " The ASX All Ordinaries Price index", type = "o")

The plot of the series after trend adjusted looks different from the original one, therefore we surely confirm that there is a trend in the series and it is a downward trend.

Question 4: The seasonal effect

We are going to use the same method with the trend effect above to investigate the seasonal effect on the series.

fit.ASX.seasonal = fit.ASX$time.series[, "seasonal"]
ASX.ts.seasonally.adjusted = ASX.ts - fit.ASX.seasonal
par(mfrow = c(1,2))
plot(ASX.ts.seasonally.adjusted, ylab = "The price Index (AUD)", xlab = "Time", main = " Seasonal adjusted ASX All Ordinaries Price index")
plot(ASX.ts, ylab = "The price Index (AUD) ", xlab = " Year", main = " The ASX All Ordinaries Price index", type = "o")

The visualization for seasonal adjusted ASX is not different from the orginal one. Then I can firmly believe that there is no seasonal effect on the series.

Question 5: Forecast for 5 month ahead.

This is a forecast with decomposition. We use the decomposition model to produce forecasts for the future time points. By testing the seasonal effect in the question 4, we have seasonal component is unchanging.

library(forecast)
forecasts <- forecast(fit.ASX, method="naive", h=5)
plot(forecasts, ylab="New orders index")

print(forecasts)
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jun 2017       2951.226 2696.626 3205.825 2561.849 3340.602
## Jul 2017       2874.439 2514.381 3234.497 2323.777 3425.101
## Aug 2017       2961.601 2520.621 3402.580 2287.180 3636.021
## Sep 2017       2847.123 2337.924 3356.323 2068.370 3625.877
## Oct 2017       2931.374 2362.072 3500.677 2060.701 3802.047

Diagnostic checking

par(mfrow = c(1,2))
acf(ASX.ts.trend.adjusted, main = " Sample ACF for ASX trend adjusted All Ordinaries Price index ")
pacf(ASX.ts.trend.adjusted, main = "Sample PACF for ASX trend adjusted All Ordinaries Price index")

Conclusion: If the series has a trend or seasonality, we should adjust the orginal trend or seasonality to make the data much reliable to forecast.