Numerical tests of normality
The moments package contains functions for computing the kurtosis and skewness of data and well as for implementing the Jarque-Bera test, which is a test of normality based on these higher-order moments. In one command, it compares the skewness and kurtosis of the data with the theoretical values for the normal distribution, which are 0 and 3, respectively.
jarque.test(x)
skewness(x, na.rm = FALSE)
kurtosis(x, na.rm = FALSE)
In this exercise, you will calculate the skewness and kurtosis for the djx
, the Dow Jones index from 2008-2011, and apply the Jarque-Bera test of normality. You will then apply the same methods to djreturns
, which contains 29 of the Dow Jones stocks for the same period.
Recall that you can use apply(X, MARGIN, FUN, …)
to apply functions over array margins. The MARGIN
parameter is a vector indicating where the function will be applied; in this instance, you will use 2
to specify that the function FUN
should be applied to the columns in matrix X
.
The moments
package has been imported for you, and the djx
and djreturns
data is in your workspace.
This exercise is part of the course
Quantitative Risk Management in R
Exercise instructions
- Calculate the skewness and kurtosis of the Dow Jones index returns in
djx
usingskewness()
andkurtosis()
, respectively. - Carry out a Jarque-Bera test of normality for
djx
usingjarque.test()
. - Use
apply()
to calculate the skewness and kurtosis of the individual equity returns indjreturns
assigning the results tos
andk
, respectively. - Fill in
plot()
to plotk
againsts
with parametertype = "n"
, and then place the stock symbols at the points with the commandtext()
(this has been done for you). - Use
apply()
to carry out the Jarque-Bera test for each of the Dow Jones constituents indjreturns
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate skewness and kurtosis of djx
___(___)
___(___)
# Carry out a Jarque-Bera test for djx
___(___)
# Calculate skewness and kurtosis of djreturns
s <- ___(___)
k <- ___(___)
# Plot k against s and add text labels to identify stocks
plot(___, ___, ___)
text(s, k, names(s), cex = 0.6)
# Carry out Jarque-Bera tests for each constituent in djreturns
___(___)