library(tseries)
library(zoo)
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(forecast)
## Loading required package: timeDate
## This is forecast 6.2

DATA SELECTION:

Real Gross Private Domestic Investment FRED/GPDIC1

ABOUT THE DATA:

Here Real Gross Domestic Private Invesmtment is Analyzed from 1947 to 2045. The data is collected by Quandl.

DATA

rgpd_t <- read.csv(file = "C:\\Users\\t420\\Desktop\\GOD.csv", header=TRUE, sep=",")
                   
rgpd <- ts(rgpd_t[,2], start=c(1947,1),frequency=4)
head(rgpd)
## [1] 2842.0 2859.7 2864.8 2830.2 2772.5 2758.1
tail(rgpd)
## [1] 278.9 262.6 238.2 199.6 205.6 222.7
str(rgpd)
##  Time-Series [1:276] from 1947 to 2016: 2842 2860 2865 2830 2772 ...
tsdisplay(rgpd, lag.max= 75, xlab="Years from 1947 to 2015", ylab=" Gross Domestic Investment", main="Quarterly Real Gross Domestic Investment from 1947 to 2015")

The plot above shows the decreasing trend of private investment over time. The data shows the data is decaying continuously. Therefore,taking difference will be the option. Let’s look at the first difference data and logged data and comapre.

lrgpd <- log(rgpd)
par(mfrow=c(2,1))
plot (rgpd, xlab=" Years 1947-2015", ylab="Private Gross Investment", main="Original Private Gross Investment" )
plot (lrgpd, xlab=" Years 1947-2015", ylab="Private Gross Investment", main="log transformed Privately Gross Invesment")

#From the charts above, I came to the conclusion that log transformation doesn't make the data stationary. Let's look at first difference case.
drgpd <- diff(rgpd)
par(mfrow=c(2,1))
plot(rgpd, xlab="Years", ylab="Gross Domestic Investment Private", main="Original Total Gross Domestic Investment from 1947 to 2015")
plot(drgpd, xlab="Years",ylab="Gross Domestic Investment Private", main="First Differenced Total Gross Domestic Invesmtne from 1947 to 2015")

#conducting KPSS and ADF test to check stationarity
#Log Transformed Data and ADF and KPSS test
adf.test(lrgpd)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  lrgpd
## Dickey-Fuller = -3.0376, Lag order = 6, p-value = 0.1389
## alternative hypothesis: stationary
kpss.test(lrgpd, null="Trend")
## Warning in kpss.test(lrgpd, null = "Trend"): p-value smaller than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  lrgpd
## KPSS Trend = 0.44857, Truncation lag parameter = 3, p-value = 0.01
#ADF test failed to reject the null hypothesis of non-stationary data.
adf.test(drgpd)
## Warning in adf.test(drgpd): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  drgpd
## Dickey-Fuller = -5.3952, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(drgpd,null="Trend")
## Warning in kpss.test(drgpd, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  drgpd
## KPSS Trend = 0.034064, Truncation lag parameter = 3, p-value = 0.1
#KPSS test failed to reject the null hypothesis of non-stationarity.

CATEGORY B

Dow Jones Industrial Average:YAHOO/INDEX_DJI

Shanghai Composite Index: YAHOO/INDEX_SSEC

NYSE Composite Index: YAHOO/INDEX_NYA

DATA SELECTION

I have selected Sanghai Composite Index for further analysis.

ABOUT THE DATA

The data contains Sanghai Composite Index from 1997 to 2016.The data is collected by Quandl.

sci_m <- read.csv(file="C:\\Users\\t420\\Desktop\\ChinaTown.csv", header=TRUE, sep=",")

sci <- ts(sci_m[,7], start=c(1997,7))
#using the Ajusted Close Sanghai Index

str(sci)
##  Time-Series [1:4518] from 2003 to 6520: 2903 2927 2860 2863 2867 ...
head(sci)
## [1] 2903.331 2927.175 2860.021 2862.893 2867.338 2836.571
tail(sci)
## [1] 1120.841 1109.666 1096.819 1159.342 1150.623 1199.061
tsdisplay(sci, lag.max = 200, xlab=" Years 1997-2016", ylab="Sanghai Composite Index", main="Daily Sanghai Composite Index from 1997 to 2016")

#The plots above shows the continuously decreasing index of Sanghai Composite. Let's find out which of the tools i.e. log transformation and first differencing makes the data stationary.
#First Difference Transformation Test
dlsci <- diff(sci)
par(mfrow=c(2,1))
plot (sci,xlab=" Years 1997 to 2016", ylab="Sanghai Composite Index", main="Daily Sanghai Index")
plot (dlsci,xlab=" Years 1997 to 2016", ylab="First Difference Transformed Sanghai Composite Index", main="Daily Sanghai Index")

#Log Transformation Test
lsci <- log(sci)
par(mfrow=c(2,1))
plot (sci,xlab=" Years 1997-2016", ylab="Sanghai Compostie Index", main="Sanghai Composite Index")
plot (lsci,xlab=" Years 1997-2016", ylab="Sanghai Composite Index", main="Logarithmically Transformed Sanghai Composite Index")

#ADF and KPSS Test for Log Transformed Data
adf.test(lsci)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  lsci
## Dickey-Fuller = -2.2461, Lag order = 16, p-value = 0.4741
## alternative hypothesis: stationary
# ADF test fail to reject the null hypothesis and the logarithmically transformed data is not stationary.
kpss.test(lsci,null="Trend")
## Warning in kpss.test(lsci, null = "Trend"): p-value smaller than printed p-
## value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  lsci
## KPSS Trend = 1.031, Truncation lag parameter = 15, p-value = 0.01
#KPSS test rejects the null hypothesis. That means it has difference stationarity.
#ADF and KPSS Test for First Differenced Data
adf.test(dlsci)
## Warning in adf.test(dlsci): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dlsci
## Dickey-Fuller = -14.242, Lag order = 16, p-value = 0.01
## alternative hypothesis: stationary
#ADF test rejected the null hypothesis. That means the first differenced data is stationary.
kpss.test(dlsci,null="Trend")
## Warning in kpss.test(dlsci, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dlsci
## KPSS Trend = 0.051405, Truncation lag parameter = 15, p-value =
## 0.1
# KPSS test failed to reject the null hypothesis. This means the first differenced data is stationary.

Category 3

10-Year Treasury Constant Maturity Rate, FRED/DGS10

3-Month Treasury Bills Secondary Market Rate, FRED/TB3MS

Yield on BAA Corporate Bonds, FED/RIMLPBAAR_N_M

DATA CHOICE:

I choose the yield of BAA Corporate Bonds. The data contains Moody’s Yield on Seasoned Corporate Bond from 1919 to 2015.

DATA

myscb_p <- read.csv(file="C:\\Users\\t420\\Desktop\\USHighway.csv", header=TRUE, sep=",")

myscb <- ts(myscb_p[,2], start=c(1991,1))

str(myscb)
##  Time-Series [1:1165] from 1991 to 3155: 5.45 5.46 5.46 5.34 5.34 5.19 5.2 5.13 4.89 4.48 ...
head(myscb)
## [1] 5.45 5.46 5.46 5.34 5.34 5.19
tail(myscb)
## [1] 7.04 7.09 7.23 7.15 7.20 7.12
tsdisplay(myscb, lag.max = 200 , xlab=" Years 1919 to 2016", ylab="Moody's Yield on Seasoned Corporate Bonds", main="Moody's Yield on Seasoned Corporate Bonds from 1919 to 2016")

# The data shows the continous decrease of data over time. Let's conduct log transformation test and differencing test so that tools making the origina;l data stationary can be known.
#First Difference Transformation Test
dlmyscb <- diff(myscb)
par(mfrow=c(2,1))
plot (myscb,xlab=" Years 1919 to 2016", ylab="Moody's Yield on Seasoned Corporate Bonds", main="Moody's Yield on Seasoned Corporate Bonds from 1919 to 2016")
plot (dlmyscb,xlab=" Years 1919 to 2016 ", ylab="Moody's Yield on Seasoned Corporate Bonds", main="Moody's Yield on Seasoned Corporate Bonds from 1919 to 2016")

# Log Transformation Test
lmyscb <- log(myscb)
par(mfrow=c(2,1))
plot (myscb,xlab="Years 1919 to 2016 ", ylab=" Yield on  Corporate Bonds", main="Moody's Yield on Seasoned Corporate Bonds from 1919 to 2016")
plot (lsci,xlab=" Years 19919-2016", ylab=" Yield Corporate Bonds", main="Logarithmically Transformed Moody's Yield on Seasoned Corporate Bonds")

#ADF and KPSS Test for Logarithmic Transformed Data
adf.test(lmyscb)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  lmyscb
## Dickey-Fuller = -2.1529, Lag order = 10, p-value = 0.5136
## alternative hypothesis: stationary
#ADF test shows that it rejects to avoid the null hypothesis. Therefore, the logarithmically transformed data isn't stationary.
kpss.test(lmyscb, null="Trend")
## Warning in kpss.test(lmyscb, null = "Trend"): p-value smaller than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  lmyscb
## KPSS Trend = 1.5639, Truncation lag parameter = 7, p-value = 0.01
#KPSS test rejects the null hypothesis. That means it has difference stationarity.
# ADF and KPSS Test for First Differenced Data
adf.test(dlmyscb)
## Warning in adf.test(dlmyscb): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dlmyscb
## Dickey-Fuller = -8.1346, Lag order = 10, p-value = 0.01
## alternative hypothesis: stationary
#ADF test rejected the null hypothesis. That means the first differenced data is stationary.
kpss.test(dlmyscb,null="Trend")
## Warning in kpss.test(dlmyscb, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dlmyscb
## KPSS Trend = 0.10662, Truncation lag parameter = 7, p-value = 0.1
#KPSS test failed to reject the null hypothesis. This means the first differenced data is stationary.