## Exam 1 - 2026 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_slb <- SFX_da$SLB x_cat <- SFX_da$CAT 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_HS <- SFX_da$House_starts x_Com <- SFX_da$Commodities 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_slb <- log(x_slb[-1]/x_slb[-T]) lr_cat <- log(x_cat[-1]/x_cat[-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]) lr_hs <- log(x_HS[-1]/x_HS[-T]) lr_com <- log(x_Com[-1]/x_Com[-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 cat_x <- lr_cat - RF # SLB excess returns #### QUESTION 1 x <- lr_hs ## 1.a. Histogram n_breaks <- 40 h <- hist(x, breaks=n_breaks, col="red", xlab="% Change House Starts", main = "Distribution - Histogram for HS") # 1.b. Report moments for changes in HS (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.c Test H0: HS changes are normal JB <- (b1^2+(b2-3)^2/4)*T/6 # if JB > 5.99, reject H0 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.d Test H0: mean of HS changes = 1% se_m1 <- sd/sqrt(T) t <- (m1-0.01)/se_m1 # if |t| > 1.96, reject H0 t ## 1.f Empirical Bootstrap 95% C.I. for correlation between lr_hs & cat_x (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="basic") # Q: Does CI include 0? #### QUESTION 2 ## Regression y <- cat_x fit_ff4 <- lm(y ~ Mkt_RF + SMB + HML + lr_hs) # Model ## 2.a Report Regression summary(fit_ff4) ## 2.b Drivers (significant variables) ## 2.c Interpret R^2 and report F-goodness of fit test ## 2.d Interpret Beta_1 ## 2.e Is CAT a value stock? (check sign of HML) ## 2.f Check for multicollinearity (using olsrr package) ols_vif_tol(fit_ibm_ff3) ols_eigen_cindex(fit_ibm_ff3) ## 2.g Check for outliers (using olsrr package) x_resid <- residuals(fit_ff4) x_stand_resid <- x_resid/sd(x_resid) # standardized residuals sum(abs(x_stand_resid) > 2)/T # Rule of thumg count (5% count is OK)- proportion of "outliers" library(olsrr) # need to install package olsrr cooksd <- cooks.distance(fit_mod) sum(cooksd > 4/T)/T # Rule of thumb count (5% count is OK) ## 2.e Compute expected returns according to Model b_ff4 <- fit_ff4$coefficients mean_x <- c(mean(Mkt_RF), mean(SMB), mean(HML), mean(lr_cs), mean(lr_gold)) exp_ret <- t(b_ff4[2:5])%*% mean_x # Expected returns, can be computed using mean of fitted values # over/underperfromance of CAT mean(y) - exp_ret #### QUESTION 3 ## 3.a beta_1 = 1. t_beta_1 <- (summary(fit_ff4)$coefficients[2,1] - 1)/summary(fit_ff4)$coefficients[2,2] t_beta_1 ## 3.b Test H0: SMB=HML=0. e_ff4 <- fit_ff4$residuals RSS_U <- sum(e_ff4^2) # Restricted Model fit_r <- lm(y ~ Mkt_RF + lr_hs) # t-test on US_I: is it significant? e_r <- fit_r$residuals RSS_R <- sum(e_r^2) k <- length(fit_ff4$coefficients) # k: number of coefficients in Unrestricted Model k2 <- length(fit_r$coefficients) # k2: number of coefficients in Restricted Model J <- k - k2 # J: number of restrictions (= k - k2) T <- length(e_ff4) 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_ff4, c("SMB = 0","HML = 0"), test="F") ## 3.c Test H0: Beta_HML = Beta_hs = 0.1 (using car) linearHypothesis(fit_ff4, c("HML = -0.1","lr_hs = 0.1"), test="F") ## 3.d Wald Test to check if GOLD is missing (using lmtest package) library(lmtest) fit_ff4_RMW <- lm(y ~ Mkt_RF + SMB + HML + lr_hs + lr_gold) #Now, U Model waldtest(fit_ff4_gold, fit_ff4) ## 3.e Wald Test to check if Commodity price changes are missing (using lmtest) fit_ff4_IP <- lm(y ~ Mkt_RF + SMB + HML + lr_hs + lr_com) #Now, U Model waldtest(fit_ff4_IP, fit_ff4) ## 3.f Chow test (with package strucchange) x_dat[429] x_break <- 428 # We lost one observation when taking log changes library(strucchange) sctest(cat_x ~ Mkt_RF + SMB + HML + lr_hs, type = "Chow", point = x_break) #### QUESTION 4 ## Check answers in solutions