Check the Stationary and Normality assumption of TimeSeries data (S&P500 stock)

In this short article, I will briefly discuss how to check the stationary and normality assumptions for the time series data using S&P500 stock. For simplicity, I will not include math notation in this article.

Most of the statistical models required the data to be stationary. By stationary, we mean that the statistical properties (such as mean and variance) are not changing (keep constant over time). We will use R libraries to check this assumption along with normality checks.

## First, you have to load the required packages. 
###installing required packages if not already installed.
library(fGarch)
library(PerformanceAnalytics)
library(rugarch)
library(tseries)
library(xts)
library(FinTS)
library(quantmod)
library(ggplot2)
library(forecast)
library(urca)

## Then you need to upload the data ( use S&P 500) as an example 
stock_data <- getSymbols(
  "^GSPC", src = "yahoo", 
                         from = "2020-01-01", 
                         to = "2022-01-01", 
                         auto.assign = FALSE, 
                         warnings = FALSE)$GSPC.Close

## Then I calculate the log return of the data and removing the first NA value
LogReturn <-Return.calculate(stock_data, method = "log")[-1]
## I then apply the ADF test to check the stationary assumption
ADFlogRe = ur.df(LogReturn, type = "drift",selectlags = "AIC" )
#summary of the test
summary(ADFlogRe)        

Here is the result of the test; the data is stationary. We come to this conclusion by comparing the absolute value of the test statistics with teh three values of the critical values.


#conduct Jarque-Bera test for normality
jarque.bera.test(Return.BMW)        


The Jarque Bera Test allows us to reject the null hypothesis and conclude that the data is not normally distributed.



要查看或添加评论,请登录

社区洞察

其他会员也浏览了