R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

### 1. Consider the daily stock returns of American Express (AXP), Caterpillar (CAT), and Starbucks (SBUX) from January 1999 to December 2008. The data are simple returns given in the file d-3stocks9908.txt (date, axp, cat, sbux).
require(fBasics)
## Loading required package: fBasics
## Loading required package: timeDate
## Loading required package: timeSeries
require(data.table)
## Loading required package: data.table
da1<-fread("d-cat0716-3dx.txt",header=T)
#### (a) Compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each simple return series. (Hint: use the R command basicStats of fBasics) 
basicStats(da1[,2:4])
##                      date          VOL         RET
## nobs         2.518000e+03 2.518000e+03 2518.000000
## NAs          0.000000e+00 0.000000e+00    0.000000
## Minimum      2.007010e+07 1.507800e+06   -0.114340
## Maximum      2.016123e+07 6.278930e+07    0.147229
## 1. Quartile  2.009070e+07 4.762675e+06   -0.009175
## 3. Quartile  2.014070e+07 8.911900e+06    0.010480
## Mean         2.011567e+07 7.454280e+06    0.000495
## Median       2.011123e+07 6.453857e+06    0.000468
## Sum          5.065126e+10 1.876988e+10    1.245288
## SE Mean      5.726652e+02 8.310100e+04    0.000417
## LCL Mean     2.011455e+07 7.291326e+06   -0.000323
## UCL Mean     2.011679e+07 7.617233e+06    0.001312
## Variance     8.257666e+08 1.738875e+13    0.000438
## Stdev        2.873616e+04 4.169982e+06    0.020929
## Skewness     8.390000e-04 2.942660e+00    0.230429
## Kurtosis    -1.226700e+00 2.054754e+01    5.029022
#### (b) Transform the simple returns to log returns. Compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each log return series.
da2=log(da1[,2:4]+1)
basicStats(da2)
##                     date          VOL         RET
## nobs         2518.000000  2518.000000 2518.000000
## NAs             0.000000     0.000000    0.000000
## Minimum        16.814742    14.226163   -0.121422
## Maximum        16.819272    17.955295    0.137349
## 1. Quartile    16.815768    15.376320   -0.009218
## 3. Quartile    16.818253    16.002898    0.010425
## Mean           16.817009    15.704996    0.000276
## Median         16.816789    15.680188    0.000468
## Sum         42345.228001 39545.179140    0.695105
## SE Mean         0.000028     0.009484    0.000417
## LCL Mean       16.816953    15.686398   -0.000541
## UCL Mean       16.817065    15.723594    0.001093
## Variance        0.000002     0.226501    0.000437
## Stdev           0.001429     0.475921    0.020900
## Skewness       -0.000820     0.292141    0.016469
## Kurtosis       -1.226698     0.354101    4.739097
#### (c) Test the null hypothesis that the mean of the log returns of AXP is zero. (Hint: use the R command t.test)
#t.test(da2$axp)
#### (d) Obtain the histogram (with nclass=40) and sample density plot of the daily log returns of AXP stock.
#hist(da2$axp,nclass=40)
#plot(density(da2$axp))
#### (e) Test if log return of AXP follows normal distribution by using at least two methods. (Need to give explanation)
normalTest(da2$axp,method="jb")
## 
## Title:
##  Jarque - Bera Normalality Test
## 
## Test Results:
##   STATISTIC:
##   P VALUE:
## 
## Description:
##  Thu Sep 26 21:38:01 2019 by user: Setsnee

Since p value < 5%, we should reject H0. Thus the log return of AXP does not follow normal distribution. ### 2. Answer the same questions as Problem 1 but using monthly returns for General Motors (GM), CRSP value-weighted index (VW), CRSP equal-weighted index (EW) and S&P composite index from January 1975 to December 2008. The returns of the indexes include dividend distributions. Data file is m-gm3dx7508.txt (date, gm, vw, ew, sp).

(a) Compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each simple return series.

da3<-fread("d-cat0716-3dx.txt",header=T)
basicStats(da3[,2:5])
##                      date          VOL         RET      vwretd
## nobs         2.518000e+03 2.518000e+03 2518.000000 2518.000000
## NAs          0.000000e+00 0.000000e+00    0.000000    0.000000
## Minimum      2.007010e+07 1.507800e+06   -0.114340   -0.089771
## Maximum      2.016123e+07 6.278930e+07    0.147229    0.114887
## 1. Quartile  2.009070e+07 4.762675e+06   -0.009175   -0.004608
## 3. Quartile  2.014070e+07 8.911900e+06    0.010480    0.006023
## Mean         2.011567e+07 7.454280e+06    0.000495    0.000337
## Median       2.011123e+07 6.453857e+06    0.000468    0.000795
## Sum          5.065126e+10 1.876988e+10    1.245288    0.849174
## SE Mean      5.726652e+02 8.310100e+04    0.000417    0.000263
## LCL Mean     2.011455e+07 7.291326e+06   -0.000323   -0.000179
## UCL Mean     2.011679e+07 7.617233e+06    0.001312    0.000853
## Variance     8.257666e+08 1.738875e+13    0.000438    0.000174
## Stdev        2.873616e+04 4.169982e+06    0.020929    0.013207
## Skewness     8.390000e-04 2.942660e+00    0.230429   -0.187913
## Kurtosis    -1.226700e+00 2.054754e+01    5.029022    9.140960

(b) Transform the simple returns to log returns. Compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each log return series.

da4=log(da3[,2:5]+1)
basicStats(da4)
##                     date          VOL         RET      vwretd
## nobs         2518.000000  2518.000000 2518.000000 2518.000000
## NAs             0.000000     0.000000    0.000000    0.000000
## Minimum        16.814742    14.226163   -0.121422   -0.094059
## Maximum        16.819272    17.955295    0.137349    0.108753
## 1. Quartile    16.815768    15.376320   -0.009218   -0.004618
## 3. Quartile    16.818253    16.002898    0.010425    0.006005
## Mean           16.817009    15.704996    0.000276    0.000250
## Median         16.816789    15.680188    0.000468    0.000795
## Sum         42345.228001 39545.179140    0.695105    0.629078
## SE Mean         0.000028     0.009484    0.000417    0.000264
## LCL Mean       16.816953    15.686398   -0.000541   -0.000267
## UCL Mean       16.817065    15.723594    0.001093    0.000767
## Variance        0.000002     0.226501    0.000437    0.000175
## Stdev           0.001429     0.475921    0.020900    0.013231
## Skewness       -0.000820     0.292141    0.016469   -0.405221
## Kurtosis       -1.226698     0.354101    4.739097    9.027875

(c) Test the null hypothesis that the mean of the log returns of GM is zero.

#t.test(da4$gm)

(d) Obtain the histogram (with nclass=40) and sample density plot of the daily log returns of GM stock.

#hist(da4$gm,nclass=40)
#plot(density(da4$gm))

(e) Test if log return of GM follows normal distribution by using at least two methods. (Need to give explanation)

Method 1: Jarque-Bera test

normalTest(da4$gm,method="jb")
## 
## Title:
##  Jarque - Bera Normalality Test
## 
## Test Results:
##   STATISTIC:
##   P VALUE:
## 
## Description:
##  Thu Sep 26 21:38:01 2019 by user: Setsnee

Since |S1| > Z_{1-5%/2} = 1.96, we should reject H0. Thus the log return of AXP does not follow normal distribution.

Since p-value > 5%, we can not reject H0. Thus the true mean is equal to zero.