Financial Econometrics - Homework 2

Instructor: Dr. Nguyen Phuong Anh


1 Group Members

  1. Nguyen Minh Quan - MAMAIU19036
  2. Lam Hue Dung - MAMAIU18060
  3. Le Nguyen Dang Khoa - MAMAIU19008

For further discussion, please contact us via email: quannguyenuw@gmail.com.


2 Libraries

library(readxl)
library(rio)
library(psych)
library(graphics)
library(car)

3 UKHP

url = 'https://raw.githubusercontent.com/QuanNguyenIU/Res_Med_Fin/main/UKHP.xls'
UKHP = rio::import(file = url)
head(UKHP, 6)
##        Month Average House Price
## 1 1991-01-01            53051.72
## 2 1991-02-01            53496.80
## 3 1991-03-01            52892.86
## 4 1991-04-01            53677.44
## 5 1991-05-01            54385.73
## 6 1991-06-01            55107.38
summary(UKHP)
##      Month                     Average House Price
##  Min.   :1991-01-01 00:00:00   Min.   : 49602     
##  1st Qu.:1997-10-16 12:00:00   1st Qu.: 61654     
##  Median :2004-08-01 00:00:00   Median :150946     
##  Mean   :2004-07-31 17:54:29   Mean   :124660     
##  3rd Qu.:2011-05-16 12:00:00   3rd Qu.:169239     
##  Max.   :2018-03-01 00:00:00   Max.   :211756
describe(UKHP$'Average House Price')
##    vars   n     mean       sd   median trimmed      mad      min      max
## X1    1 327 124660.5 56387.17 150946.1  123820 68175.33 49601.66 211755.9
##       range  skew kurtosis      se
## X1 162154.3 -0.11    -1.59 3118.22
names(UKHP)[2] = 'hp'
UKHP$dhp = c(NA, 100 * diff(UKHP$hp) / UKHP$hp[1:nrow(UKHP) - 1])
par(cex.axis = 1.5, cex.lab = 1.5, lwd = 2)
plot(UKHP$Month, UKHP$hp, type = 'l', 
     xlab = 'Date', ylab = 'House Price')

hist(UKHP$dhp)


4 SandPhedge

url = 'https://raw.githubusercontent.com/QuanNguyenIU/Res_Med_Fin/main/SandPhedge.xls'
SandPhedge = rio::import(file = url)
head(SandPhedge, 6)
##         Date    Spot Futures
## 1 1997-09-01  947.28  954.50
## 2 1997-10-01  914.62  924.00
## 3 1997-11-01  955.40  955.00
## 4 1997-12-01  970.43  979.25
## 5 1998-01-01  980.28  987.75
## 6 1998-02-01 1049.34 1050.50
SandPhedge$rspot = c(NA, 100 * diff(log(SandPhedge$Spot)))
SandPhedge$rfutures = c(NA, 100 * diff(log(SandPhedge$Futures)))
summary(SandPhedge[c('rspot', 'rfutures')])
##      rspot             rfutures       
##  Min.   :-18.5636   Min.   :-18.9447  
##  1st Qu.: -1.8314   1st Qu.: -1.9314  
##  Median :  0.9185   Median :  0.9976  
##  Mean   :  0.4168   Mean   :  0.4140  
##  3rd Qu.:  3.2765   3rd Qu.:  3.1336  
##  Max.   : 10.2307   Max.   : 10.3872  
##  NA's   :1          NA's   :1
describe(SandPhedge[c('rspot', 'rfutures')])
##          vars   n mean   sd median trimmed  mad    min   max range  skew
## rspot       1 246 0.42 4.33   0.92     0.7 3.85 -18.56 10.23 28.79 -0.84
## rfutures    2 246 0.41 4.42   1.00     0.7 3.90 -18.94 10.39 29.33 -0.88
##          kurtosis   se
## rspot        1.73 0.28
## rfutures     2.02 0.28
plot(SandPhedge$rfutures, SandPhedge$rspot, pch = 19)

lm_returns = lm(rspot ~ rfutures, data = SandPhedge)
summary(lm_returns)
## 
## Call:
## lm(formula = rspot ~ rfutures, data = SandPhedge)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.45284 -0.16401  0.00236  0.23692  2.33789 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.013077   0.029473   0.444    0.658    
## rfutures    0.975077   0.006654 146.543   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4602 on 244 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.9888, Adjusted R-squared:  0.9887 
## F-statistic: 2.147e+04 on 1 and 244 DF,  p-value: < 2.2e-16
linearHypothesis(lm_returns, c('rfutures = 1'))
## Linear hypothesis test
## 
## Hypothesis:
## rfutures = 1
## 
## Model 1: restricted model
## Model 2: rspot ~ rfutures
## 
##   Res.Df    RSS Df Sum of Sq     F    Pr(>F)    
## 1    245 54.656                                 
## 2    244 51.684  1    2.9718 14.03 0.0002246 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(SandPhedge$Futures, SandPhedge$Spot, pch = 19)

lm_prices = lm(Spot ~ Futures, data = SandPhedge)
summary(lm_prices)
## 
## Call:
## lm(formula = Spot ~ Futures, data = SandPhedge)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -64.576  -1.996   1.436   4.309  16.612 
## 
## Coefficients:
##               Estimate Std. Error  t value Pr(>|t|)    
## (Intercept) -2.8378335  1.4889725   -1.906   0.0578 .  
## Futures      1.0016065  0.0009993 1002.331   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.908 on 245 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9998 
## F-statistic: 1.005e+06 on 1 and 245 DF,  p-value: < 2.2e-16
linearHypothesis(lm_prices, c('Futures = 1'))
## Linear hypothesis test
## 
## Hypothesis:
## Futures = 1
## 
## Model 1: restricted model
## Model 2: Spot ~ Futures
## 
##   Res.Df   RSS Df Sum of Sq      F Pr(>F)
## 1    246 11816                           
## 2    245 11693  1    123.35 2.5846 0.1092

5 CAPM

url = 'https://raw.githubusercontent.com/QuanNguyenIU/Res_Med_Fin/main/capm.xls'
capm = rio::import(file = url)
head(capm, 6)
##         Date   SANDP  FORD    GE MICROSOFT ORACLE USTB3M
## 1 2002-01-01 1130.20 15.30 37.15    31.855  17.26   1.68
## 2 2002-02-01 1106.73 14.88 38.50    29.170  16.62   1.76
## 3 2002-03-01 1147.39 16.49 37.40    30.155  12.80   1.83
## 4 2002-04-01 1076.92 16.00 31.55    26.130  10.04   1.75
## 5 2002-05-01 1067.14 17.65 31.14    25.455   7.92   1.76
## 6 2002-06-01  989.82 16.00 29.05    27.350   9.47   1.73
capm$rsandp = c(NA, 100 * diff(log(capm$SANDP)))
capm$rford = c(NA, 100 * diff(log(capm$FORD)))
capm$rge = c(NA, 100 * diff(log(capm$GE)))
capm$rmsoft = c(NA, 100 * diff(log(capm$MICROSOFT)))
capm$roracle = c(NA, 100 * diff(log(capm$ORACLE)))

capm$USTB3M = capm$USTB3M/12
capm$ersandp = capm$rsandp - capm$USTB3M
capm$erford = capm$rford - capm$USTB3M
capm$erge = capm$rge - capm$USTB3M
capm$ermsoft = capm$rmsoft - capm$USTB3M
capm$eroracle = capm$roracle - capm$USTB3M
par(cex.axis = 1.5, cex.lab = 1.5, lwd = 2)
plot(capm$Date, capm$ersandp, type = 'l',
     col = 'red', ylim = c(-100, 100))
lines(capm$Date, capm$erford, lwd = 1)
legend('topright', c('SP500', 'Ford'), col = c('red', 'black'),
       lty = 1, cex = 1.5)

lm_capm = lm(erford ~ ersandp, data = capm)
summary(lm_capm)
## 
## Call:
## lm(formula = erford ~ ersandp, data = capm)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -50.727  -5.027  -1.080   3.482  65.145 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -0.9560     0.7931  -1.205     0.23    
## ersandp       1.8898     0.1916   9.862   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 10.98 on 191 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.3374, Adjusted R-squared:  0.3339 
## F-statistic: 97.26 on 1 and 191 DF,  p-value: < 2.2e-16
alpha = lm_capm$coefficients[1]
beta = lm_capm$coefficients[2]
plot(capm$ersandp, capm$erford, pch = 19)
lines(capm$ersandp, alpha + beta * capm$ersandp, lwd = 1, col = 'red')

linearHypothesis(lm_capm, c('ersandp = 1'))
## Linear hypothesis test
## 
## Hypothesis:
## ersandp = 1
## 
## Model 1: restricted model
## Model 2: erford ~ ersandp
## 
##   Res.Df   RSS Df Sum of Sq     F    Pr(>F)    
## 1    192 25618                                 
## 2    191 23020  1    2598.5 21.56 6.365e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1