Session Ready
Exercise

Compute univariate descriptive statistics

Having the returns in a matrix (return_matrix) allows you to compute several descriptive statistics for each return series with the apply() function. The apply() function takes three elements as input:

  • An array (in this case a matrix) on which you want to "apply" a certain function.
  • The subscripts which the function will be applied over. E.g. for a matrix 1 indicates rows, and 2 indicates columns.
  • The function to be applied. The code on the right computes for example the mean, the variance and the standard deviation for each return series.

The PerformanceAnalytics package offers you specific descriptive statistics that are useful for returns: e.g. skewness and kurtosis. Furthermore, the package offers one simple function, table.Stats, that takes the return series as input and returns a table with numerous useful descriptive statistics.

Instructions
100 XP
  • Use the apply() function to print the skewness of the three assets to the console.
  • Use the apply() function to print the kurtosis of the three assets to the console.
  • Print numerous descriptive statistics to the console with the table.Stats() function.