calc_skew: Calculate the skewness or kurtosis of a time series of...

View source: R/rutils.R

calc_skewR Documentation

Calculate the skewness or kurtosis of a time series of returns.

Description

Calculate the skewness or kurtosis of a time series of returns.

Usage

calc_skew(retp, expn = 3)

Arguments

retp

A time series of returns, with multiple columns.

expn

The power (exponent) to raise the returns (the default is 3 for skewness).

Details

The function calc_skew() calculates the skewness or kurtosis of a time series of returns.

The function calc_skew() performs an sapply() loop over the columns of the retp argument. It raise the returns to the power expn. If expn = 3 it calculates the skewness. If expn = 4 it calculates the kurtosis.

The skewness \varsigma is defined as:

\varsigma = \frac{1}{n-1} \sum_{i=1}^n {(\frac{r - \bar{r}}{\sigma})^3}

Where r are the daily returns, \bar{r} are the average returns, and \sigma is their standard deviation.

The kurtosis \kappa is defined as:

\kappa = \frac{1}{n-1} \sum_{i=1}^n {(\frac{r - \bar{r}}{\sigma})^4}

Value

A matrix of the skewness or kurtosis values.

Examples

# Calculate the kurtosis of VTI and IEF returns
rutils::calc_skew(rutils::etfenv$returns[, c("VTI", "IEF")], expn=4)

algoquant/rutils documentation built on June 10, 2025, 3:55 p.m.