library("zoo")
## Warning: package 'zoo' was built under R version 3.2.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library("forecast")
## Warning: package 'forecast' was built under R version 3.2.3
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.2.3
## This is forecast 6.2
library("tseries")
## Warning: package 'tseries' was built under R version 3.2.3
Choose one time series from each of the following categories A, B, and C:
For each of the three time series you choose determine whether to transform it using logartihm,plot the original and transformed time series, plot first differences of either orignal or log-transformed time series. Peform ADF and KPSS tests on time series. For difference stationary series also perfom these tests for diffferenced series.
Category A:
I choose Industrial Production: Total index FRED/IPB50001SQ
In this problem, data is analysed about quaterly Industrial Production Total index from 1919 to 2015.
The data for this problem is collectd from Quand.The Industrial Production Total index used in this anlaysis is quaterly data from 1919 to 2015.
ipti_d<- read.csv(file = "C:/Users/kluitel/Desktop/ECO 5316 Time serice Econometrics/HW3/FRED-IPB50001SQ.csv", header=TRUE, sep=",")
ipti<- ts(ipti_d[,2], start=c(1919,1), frequency = 4)
str(ipti)
## Time-Series [1:388] from 1919 to 2016: 107 108 107 107 108 ...
head(ipti)
## [1] 106.6033 107.5328 106.8008 107.4248 107.5189 106.2906
tail(ipti)
## [1] 5.5083 5.7772 5.2857 5.4156 4.8777 4.8406
tsdisplay(ipti, lag.max = 100, xlab=" Years 1962-2016", ylab="Industrial Production Total index", main="Industrial Production Total index, QUATERLY")
The plot above indicate decreasing trend over the time frame.There data is continous decay rather than expontential decay. This suggests not to log transformation the data to make the data stationary but take first difference. lets see the orogianl and log transfered data plot.
lipti <- log(ipti)
par(mfrow=c(2,1))
plot (ipti, xlab=" Years 1962-2016", ylab="Industrial Production Total index", main=" Original Industrial Production Total index, QUATERLY" )
plot (lipti, xlab=" Years 1962-2016", ylab="Industrial Production Total index", main="log transformed Industrial Production Total index, QUATERLY")
As indicated before log transfer did not make the data stationary. lets look at the first difference.
dipti <- diff(ipti)
par(mfrow=c(2,1))
plot (ipti, xlab=" Years 1962-2016", ylab="Industrial Production Total index", main=" Original Industrial Production Total index, QUATERLY" )
plot (dipti, xlab=" Years 1962-2016", ylab="Industrial Production Total index", main=" First DIfference transformed Industrial Production Total index, QUATERLY")
Lets conduct the ADF adn KPSS test to ckeck if the data is stationary
#log tranformed data ADF AND KPSS stationary test
adf.test(lipti)
##
## Augmented Dickey-Fuller Test
##
## data: lipti
## Dickey-Fuller = -2.8517, Lag order = 7, p-value = 0.2175
## alternative hypothesis: stationary
kpss.test(lipti, null="Trend")
## Warning in kpss.test(lipti, null = "Trend"): p-value smaller than printed
## p-value
##
## KPSS Test for Trend Stationarity
##
## data: lipti
## KPSS Trend = 1.0812, Truncation lag parameter = 4, p-value = 0.01
ADF test fail to reject the null hypothesis of non-stationary data.
#First difference tranformed data ADF AND KPSS stationary test
adf.test(dipti)
## Warning in adf.test(dipti): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: dipti
## Dickey-Fuller = -7.3985, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(dipti, null="Trend")
## Warning in kpss.test(dipti, null = "Trend"): p-value greater than printed
## p-value
##
## KPSS Test for Trend Stationarity
##
## data: dipti
## KPSS Trend = 0.039771, Truncation lag parameter = 4, p-value = 0.1
KPSS test fail to reject the null hypothesis of non-stationary data.
Category B:
I choose Dow Jones Industrial Average YAHOO/INDEX_DJI
In this problem, data is analysed about Daily Dow Jones Industrial Average from 1992 to 2016.
The data for this problem is collectd from Quand.The Dow Jones Industrial Average used in this anlaysis is daily data from 1992 to 2016.
djia_d<- read.csv(file="C:/Users/kluitel/Desktop/ECO 5316 Time serice Econometrics/HW3/YAHOO-INDEX_DJI.csv", header=TRUE, sep =",")
djia<- ts(djia_d[,7], start=c(1992,1)) # using adjusted closing price
str(djia)
## Time-Series [1:6081] from 1992 to 8072: 16621 16392 16413 16454 16196 ...
head(djia)
## [1] 16620.66 16391.99 16413.43 16453.83 16196.41 15973.84
tail(djia)
## [1] 3209.5 3203.9 3204.8 3200.1 3201.5 3172.4
tsdisplay(djia, lag.max = 100, xlab=" Years 1992-2016", ylab="Dow Jones Industrial Average", main="Dow Jones Industrial Average, daily")
The plot above indicate higher variance in data set with downward trend. There is also expontential decay in the data set. This suggests the log transformation to make the data stationary.
#Log Transformation
ldjia <- log(djia)
par(mfrow=c(2,1))
plot (djia,xlab=" Years 1992-2016", ylab="Dow Jones Industrial Average", main="Dow Jones Industrial Average, daily")
plot (ldjia,xlab=" Years 1992-2016", ylab="Dow Jones Industrial Average", main="Lof Transformed Dow Jones Industrial Average, daily")
The data still has the downward trend. th elog transformation decreased the variance among the observation. The first difference should remove the trend in the data set to convert it to stationary data.
# First Difference Transformaion
dldjia <- diff(ldjia)
par(mfrow=c(2,1))
plot (djia,xlab=" Years 1992-2016", ylab="Dow Jones Industrial Average", main="Dow Jones Industrial Average, daily")
plot (dldjia,xlab=" Years 1992-2016", ylab="First Difference Transformed Dow Jones Industrial Average", main="Dow Jones Industrial Average, daily")
The plot, the data looks stationary data set. lets test with ADF and KPSS test.
# ADF AND KPSS TEST FOR LOG TRANSFORMED DATA ONLY
adf.test(ldjia)
##
## Augmented Dickey-Fuller Test
##
## data: ldjia
## Dickey-Fuller = -1.2788, Lag order = 18, p-value = 0.8838
## alternative hypothesis: stationary
kpss.test(ldjia, null="Trend")
## Warning in kpss.test(ldjia, null = "Trend"): p-value smaller than printed
## p-value
##
## KPSS Test for Trend Stationarity
##
## data: ldjia
## KPSS Trend = 4.7173, Truncation lag parameter = 17, p-value = 0.01
ADF test fail to reject the null hypothesis of non-stationary data.
# ADF AND KPSS TEST FOR LOG TRANSFORMED and FIRST DIFFERENCE DATA
adf.test(dldjia)
## Warning in adf.test(dldjia): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: dldjia
## Dickey-Fuller = -18.71, Lag order = 18, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(dldjia, null="Trend")
## Warning in kpss.test(dldjia, null = "Trend"): p-value greater than printed
## p-value
##
## KPSS Test for Trend Stationarity
##
## data: dldjia
## KPSS Trend = 0.07084, Truncation lag parameter = 17, p-value = 0.1
ADF test rejects the null hypothesis of non-stationary data. KPSS test fail to reject the null hypothesis of non-stationary data.
Category C:
I choose 10-Year Treasury Constant Maturity Rate, FRED/DGS10
In this problem, data is analysed about daily 10-Year Treasury Constant Maturity Rate from 1962 to 2016.
The data for this problem is collectd from Quand.Quandl collected the data from Federal Reserve Economic Data website. The 10-Year Treasury Constant Maturity Rate used in this anlaysis is daily data from 1962 to 2016.
D10y_tres_rate_d<- read.csv(url("https://research.stlouisfed.org/fred2/data/DGS10.csv"))
D10y_tres_rate<- ts(D10y_tres_rate_d[,2], start=c(1962,1))
str(D10y_tres_rate)
## Time-Series [1:14125] from 1962 to 16086: 731 728 724 727 728 730 732 733 733 735 ...
## - attr(*, "levels")= chr [1:1311] "." "1.43" "1.44" "1.45" ...
head(D10y_tres_rate)
## [1] 731 728 724 727 728 730
tail(D10y_tres_rate)
## [1] 1 34 37 31 32 33
tsdisplay(D10y_tres_rate, lag.max = 300 , xlab=" Years 1962-2016", ylab="10-Year Treasury Constant Maturity Rate", main="10-Year Treasury Constant Maturity Rate, daily")
The plot above indicate higher variance in data set. There is sudden decrease and incresae in value.There is also some downward and upward tend in the data.
lD10y_tres_rate <- log(D10y_tres_rate)
par(mfrow=c(2,1))
plot (D10y_tres_rate, xlab=" Years 1962-2016", ylab="10-Year Treasury Constant Maturity Rate", main="10-Year Treasury Constant Maturity Rate, daily")
plot (lD10y_tres_rate, xlab=" Years 1962-2016", ylab="10-Year Treasury Constant Maturity Rate", main="LOG TRANSFORMED 10-Year Treasury Constant Maturity Rate, daily")
The log transformed has decreased the variance. lets do the first diffrence for the log transformed data.
dlD10y_tres_rate <- diff(lD10y_tres_rate)
par(mfrow=c(2,1))
plot (D10y_tres_rate, xlab=" Years 1962-2016", ylab="10-Year Treasury Constant Maturity Rate", main="10-Year Treasury Constant Maturity Rate, daily")
plot (dlD10y_tres_rate, xlab=" Years 1962-2016", ylab="10-Year Treasury Constant Maturity Rate", main=" FIRST DIFFERENCE 10-Year Treasury Constant Maturity Rate, daily")
It seems the first difference has made the data stationary. Lets test ADF and KPSS test for stationary.
#log transformed data ADF AND KPSS TEST
adf.test(lD10y_tres_rate)
## Warning in adf.test(lD10y_tres_rate): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: lD10y_tres_rate
## Dickey-Fuller = -8.5687, Lag order = 24, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(lD10y_tres_rate, null="Trend")
## Warning in kpss.test(lD10y_tres_rate, null = "Trend"): p-value smaller than
## printed p-value
##
## KPSS Test for Trend Stationarity
##
## data: lD10y_tres_rate
## KPSS Trend = 1.6456, Truncation lag parameter = 27, p-value = 0.01
The log transformed has coverted the data into stationary data. It seem there is no need for additional transformation. However, lets see the impact of first difference in the stationary of the data.
#FIRST DIFFERENCE with log transformed data ADF AND KPSS TEST
adf.test(dlD10y_tres_rate)
## Warning in adf.test(dlD10y_tres_rate): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: dlD10y_tres_rate
## Dickey-Fuller = -43.621, Lag order = 24, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(dlD10y_tres_rate, null="Trend")
## Warning in kpss.test(dlD10y_tres_rate, null = "Trend"): p-value greater
## than printed p-value
##
## KPSS Test for Trend Stationarity
##
## data: dlD10y_tres_rate
## KPSS Trend = 0.001547, Truncation lag parameter = 27, p-value =
## 0.1
KPSS test fail to reject the null hypothesis of non-stationary data. This may suggest the first difference should not be done for the data.