## Exam 1 - 2024 SFX_da <- read.csv("http://www.bauer.uh.edu/rsusmel/4397/Stocks_FX_1973.csv",head=TRUE,sep=",") names(SFX_da) x_dat <- SFX_da$Date x_unp<- SFX_da$UNP x_S <- SFX_da$USD_EUR x_wti <- SFX_da$Crude_WTI x_gold <- SFX_da$Gold x_cs <- SFX_da$Cons_sent x_ip <- SFX_da$IP x_Mkt_RF<- SFX_da$Mkt_RF x_SMB <- SFX_da$SMB x_HML <- SFX_da$HML x_CMA <- SFX_da$CMA x_RMW <- SFX_da$RMW x_RF <- SFX_da$RF T <- length(x_slb) e <- log(x_S[-1]/x_S[-T]) lr_wti <- log(x_wti[-1]/x_wti[-T]) lr_cs <- log(x_cs[-1]/x_cs[-T]) lr_ge <- log(x_ge[-1]/x_ge[-T]) lr_slb <- log(x_slb[-1]/x_slb[-T]) lr_unp <- log(x_unp[-1]/x_unp[-T]) lr_gold <- log(x_gold[-1]/x_gold[-T]) lr_oil <- log(x_wti[-1]/x_wti[-T]) lr_ip <- log(x_ip[-1]/x_ip[-T]) x0 <- matrix(1,T-1,1) Mkt_RF <- x_Mkt_RF[-1]/100 SMB <- x_SMB[-1]/100 HML <- x_HML[-1]/100 CMA <- x_CMA[-1]/100 RMW <- x_RMW[-1]/100 RF <- x_RF[-1]/100 unp_x <- lr_unp - RF # SLB excess returns #### QUESTION 1 x <- lr_oil # compute moments for changes in oil (lr_oil) T <- length(x) m1 <- sum(x)/T ## Mean m1 m2 <- sum((x-m1)^2)/T ## Var sd <- sqrt(m2) ## SD sd m3 <- sum((x-m1)^3)/T ## For numerator of S m4 <- sum((x-m1)^4)/T ## For numerator of K b1 <- m3/m2^(3/2) ## Sample Skewness b1 b2 <- (m4/m2^2) ## Sample Kurtosis b2 ## 1.a Test H0: mean of oil changes = 0 se_m1 <- sd/sqrt(T) t <- m1/se_m1 t ## 1.b Test H0: oil changes are normal JB <- (b1^2+(b2-3)^2/4)*T/6 JB qchisq(.95, df = 2) # chi-squared (df=2) value at 5% level p_val <- 1 - pchisq(JB, df = 2) # p-value of LM_test p_val ## 1.c 95% C.I. for correlation between lr_oil & Mkt_RF (Need to use boot package) library(boot) dat_c <- data.frame(lr_oil, Mkt_RF) library(boot) # function to obtain cor from the data cor_xy <- function(data, i) { d <-data[i,] return(cor(d$lr_oil,d$Mkt_RF)) } boot.samps <- boot(data=dat_c, statistic=cor_xy, R=1000) boot.ci(boot.samps, type="perc") # Note: You can also build a 95% CI assuming a Normal approximation for SD m_cor <- boot.samps$t0 sd_cor <- sqrt(1-m_cor^2)/sqrt(T-2) cor_lb <- m_cor - 1.96 * sd_cor cor_lb cor_ub <- m_cor + 1.96 * sd_cor cor_ub #### QUESTION 2 ## Regression y <- unp_x fit_ff5 <- lm(y ~ Mkt_RF + SMB + HML + lr_cs + lr_oil) # Model ## 2.a Report Regression summary(fit_ff5) ## 2.b Drivers (significant variables) ## 2.c Interpret R^2 and report F-goodness of fit test ## 2.d Interpret Beta_1 ## 2.e Check for outliers (using olsrr package) x_resid <- residuals(fit_ff5) x_stand_resid <- x_resid/sd(x_resid) # standardized residuals sum(x_stand_resid > 2)/T # Rule of thumg count (5% count is OK)- proportion of "outliers" library(olsrr) # need to install package olsrr x_lev <- ols_leverage(fit_ibm_ff3) # leverage residuals sum(x_lev > (2*k+2)/T) # Rule of thumb count (5% count is OK) - proportion of "levarage observations" ## 2.f Check for multicollinearity (using olsrr package) ols_vif_tol(fit_ibm_ff3) ols_eigen_cindex(fit_ibm_ff3) ## 2.e Compute expected returns according to Model b_ff5 <- fit_ff5$coefficients mean_x <- c(mean(Mkt_RF), mean(SMB), mean(HML), mean(lr_cs), mean(lr_gold)) exp_ret <- t(b_ff5[2:6])%*% mean_x # over/underperfromance of CAT mean(y) - exp_ret #### QUESTION 3 ## 3.a beta_1 = 1. t_beta_1 <- (summary(fit_ff5)$coefficients[2,1] - 1)/summary(fit_ff5)$coefficients[2,2] t_beta_1 ## 3.b Test H0: CAPM true. e_ff5 <- fit_ff5$residuals RSS_U <- sum(e_ff5^2) # Restricted Model fit_capm <- lm(y ~ Mkt_RF) # t-test on US_I: is it significant? e_capm <- fit_capm$residuals RSS_R <- sum(e_capm^2) k <- length(fit_ff5$coefficients) # k: number of coefficients in Unrestricted Model k2 <- length(fit_capm$coefficients) # k2: number of coefficients in Restricted Model J <- k - k2 # J: number of restrictions (= k - k2) T <- length(e_ff5) F_test <- ((RSS_R - RSS_U)/J)/(RSS_U/(T-k)) F_test qf(.95, df1=J, df2=(T-k)) p_val <- 1 - pf(F_test, df1=J, df2=(T-k)) p_val # NOTE: You can also do the test using the car package library(car) linearHypothesis(fit_ff5, c("SMB = 0","HML = 0", "lr_cs = 0", "lr_oil = 0"), test="F") ## 3.c Test H0: Beta_CS = Beta_oil = -0.3 (using car) linearHypothesis(fit_ff5, c("lr_cs = -0.1","lr_oil = 0.3"), test="F") ## 3.d Wald Test to check if RMW is missing (using lmtest package) library(lmtest) fit_ff5_RMW <- lm(y ~ Mkt_RF + SMB + HML + lr_cs + lr_oil + RMW) #Now, U Model waldtest(fit_ff5_RMW, fit_ff5) ## 3.e Wald Test to check if IP changes are missing (using lmtest) fit_ff5_IP <- lm(y ~ Mkt_RF + SMB + HML + lr_cs + lr_oil + RMW) #Now, U Model waldtest(fit_ff5_IP, fit_ff5) ## 3.f Chow test (with package strucchange) x_dat[429] x_break <- 428 # We lost one observation when taking log changes library(strucchange) sctest(unp_x ~ Mkt_RF + SMB + HML + lr_cs + lr_oil, type = "Chow", point = x_break) #### QUESTION 4 ## Check answers in solutions