6

.pdf

School

University of Toronto *

*We aren’t endorsed by this school

Course

374

Subject

Economics

Date

Jan 9, 2024

Type

pdf

Pages

6

Uploaded by SargentSquidPerson1009

Case Study 1 ECO374 Install and load required R packages if (!require( "quantmod" )) install.packages( "quantmod" ) if (!require( "ggplot2" )) install.packages( "ggplot2" ) if (!require( "stats" )) install.packages( "stats" ) if (!require( "tsDyn" )) install.packages( "tsDyn" ) if (!require( "forecast" )) install.packages( "forecast" ) if (!require( "urca" )) install.packages( "urca" ) library(quantmod) # functions: getSymbols library(ggplot2) # functions: ggplot library(stats) # functions: arima library(tsDyn) # functions: SETAR library(forecast) # functions: auto.arima, nnetar library(urca) # functions: ur.kpss 1. Data Data: iShares Core S&P Total U.S. Stock Market ETF ( Source ) ITOT <- getSymbols( "ITOT" , src= "yahoo" , return.class= "xts" , auto.assign= F) ITOT <- window(ITOT, start= as.Date( "2022-11-01" ), end= as.Date( "2023-09-01" )) ITOT.c <- ITOT$ITOT.Close # extract close price seed <- 2345 Plot data ggplot(ITOT.c, aes( x= index(ITOT.c), y= ITOT.Close)) + geom_line( color= "springgreen4" ) + labs( x= "" , y= "" , title= "Core S&P Total U.S. Stock Market, Close" ) + theme_minimal() + theme( plot.title = element_text( size= 10 )) + scale_x_date( date_breaks= "1 months" , date_labels = "%Y-%m" ) 85 90 95 100 2022-11 2022-12 2023-01 2023-02 2023-03 2023-04 2023-05 2023-06 2023-07 2023-08 2023-09 Core S&P Total U.S. Stock Market, Close 1
Difference data and plot D_ITOT.c <- na.omit(diff(ITOT.c, lag= 1 , differences= 1 )) ggplot(D_ITOT.c, aes( x= index(D_ITOT.c), y= ITOT.Close)) + geom_line( color= "darkblue" ) + labs( x= "" , y= "" , title= "Differenced Core S&P Total U.S. Stock Market, Close" ) + theme_minimal() + theme( plot.title = element_text( size= 10 )) + scale_x_date( date_breaks= "3 months" , date_labels = "%Y-%m" ) -2.5 0.0 2.5 5.0 2023-01 2023-04 2023-07 Differenced Core S&P Total U.S. Stock Market, Close 2. Stationarity (unit root) test ur.test <- ur.kpss(ITOT.c) summary(ur.test) ## ## ####################### ## # KPSS Unit Root Test # ## ####################### ## ## Test is of type: mu with 4 lags. ## ## Value of test-statistic is: 3.4622 ## ## Critical value for a significance level of: ## 10pct 5pct 2.5pct 1pct ## critical values 0.347 0.463 0.574 0.739 We reject at 5% level the null hypothesis that the data is stationary. Let’s test the differenced data. ur.test.d <- ur.kpss(D_ITOT.c) summary(ur.test.d) ## ## ####################### ## # KPSS Unit Root Test # ## ####################### ## 2
## Test is of type: mu with 4 lags. ## ## Value of test-statistic is: 0.05 ## ## Critical value for a significance level of: ## 10pct 5pct 2.5pct 1pct ## critical values 0.347 0.463 0.574 0.739 We do not reject at 5% the null of stationarity and conclude that the differenced data is stationary. 3. ACF and PACF Plot ACF of differenced data par( mar= c( 4 , 4 , 0.5 , 0 )) # set margin sizes ACF <- acf(D_ITOT.c, lag.max= 20 , plot= FALSE, demean= TRUE) plot(ACF[ 1 : 20 ], main= "" , cex.lab= 0.75 , cex.axis= 0.75 , xaxt= "n" ) axis( 1 , at= ACF$lag, cex.axis= 0.75 ) # put a label at each lag value -0.10 0.00 0.05 0.10 Lag ACF 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Plot PACF of differenced data par( mar= c( 4 , 4 , 0.5 , 0 )) # set margin sizes PACF <- pacf(D_ITOT.c, lag.max= 20 , plot= FALSE, demean= TRUE) plot(PACF[ 1 : 20 ], main= "" , cex.lab= 0.75 , cex.axis= 0.75 , xaxt= "n" ) axis( 1 , at= PACF$lag, cex.axis= 0.75 ) # put a label at each lag value 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help