Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 290

Case Study: Returns on the Stock Exchange

Оглавление

In this simple illustration, we will compare the returns of the index S&P500 to the Normal distribution. The output of the following code is Figure 8.2 on this page.


Figure 8.2: The same plot for the returns of the SP500 index seems acceptable, though there are outliers (where the normal distribution converges fast to zero).

library(MASS) ## ## Attaching package: ‘MASS’ ## The following object is masked from ‘package:dplyr’:## ##select hist(SP500,col=“khaki3”,freq=FALSE,border=“khaki3”) x <- seq(from=-5,to=5,by=0.001) lines(x, dnorm(x,mean(SP500),sd(SP500)),col=“blue”,lwd=2)

A better way to check for normality is to study the Q-Q plot. A Q-Q plot compares the sample quantiles with the quantiles of the distribution and it makes very clear where deviations appear.

Q-Q plot

library(MASS)

qqnorm(SP500,col=“red”); qqline(SP500,col=“blue”)

From the Q-Q plot in Figure 8.3 on page 153 (that is generated by the aforementioned code block), it is clear that the returns of the S&P-500 index are not Normally distributed. Outliers far from the mean appear much more often than the Normal distribution would predict. In other words: returns on stock exchanges have “fat tales.”


Figure 8.3: A Q-Q plot is a good way to judge if a set of observations is normally distributed or not.

The Big R-Book

Подняться наверх