What is stationary?

The statistical characteristics or moments (such as mean and variance) in a stationary time series do not change over time. Therefore, a stationary time series state is defined as being stationary. On the other hand, a time series is said to be nonstationary if its statistical characteristics change with time.

Although stationarity may be precisely defined mathematically, for our purposes, we refer to a series that appears flat, has no trend, has constant variance over time, has a consistent autocorrelation structure across time, and does not exhibit periodic fluctuations (seasonality). 

Why Stationarity is essential in the Time Series Analysis?

Time series analysis relies heavily on stationarity, which has a major impact on how the data is interpreted and forecasted. Most time series models make the assumption that every point is independent of every other point for forecasting or predicting the future. 

Testing for stationarity is critical because the entire model results could be falsified. In simple terms, trended series are non-stationary, whereas non-trended series are stationary. Many tests are available to check whether the data is stationary or non-stationary. Two tests that are more famous than others are the Augmented Dicky Fuller (ADF) Test and Phillips-Perron (PP) Test.

Example:

Apple stock price from Jan 2000 to Dec 2021 is used here to check whether the time series is stationary or non-stationary. The null and alternative hypothesis for the both Augmented Dicky fuller test and Phillips-Perron (PP) Test.

Null Hypothesis H0:  Non-Stationary.
Alternative Hypothesis H1: Stationary.

We reject the null hypothesis if the p-value is less than 0.05. Or else we fail to reject the null hypothesis which means we can accept the null hypothesis (the time series is non-stationary). Let's see the R code:

Reading the data from the excel file (.xlsx).
library(readxl)
data = read_excel("file_path/AAPL.xlsx")
Importing the required package and testing the series:
library(tseries)

adf.test(data$Close) # Augmented Dicky Fuler test

pp.test(data$Close, alternative ="stationary") # Philips-Perron test
OUTPUT: 

Here p-value is greater than 0.05. So we need to reject the null hypothesis. Results show this time series is non-stationary. So, we have to convert the non-stationary time series data into stationary time series. There are many transformation techniques used to convert the time series into stationary, some of them are listed below:

  • Differentiation
  • Log
  • Square root
  • Box-cox Transformation

We are using the differentiation transformation technique here to convert the stock data. 

dif_data = diff(data$Close)
Then, again we use tests to check the stationary for the time series.
adf.test(dif_data)
pp.test(dif_data, alternative ="stationary")
OUTPUT:


Here p-value is less than 0.05. So we can reject the null hypothesis. Results show this time series is stationary. 

Post a Comment

The more you ask questions, that will enrich the answer, so whats your question?

Previous Post Next Post

Translate

AKSTATS

Learn it 🧾 --> Do it 🖋 --> Get it 🏹📉📊