Skip to content
Vladislav Pyatnitskiy edited this page Sep 7, 2023 · 33 revisions

Welcome to the stockanalytics wiki!

Descriptive Statistics

Mean

  • Default R script: mean(x)

Median

  • Default R script: median(x) or quantile(x, 0.5)

Mode

Rarely used in Finance, but can be referred as the 'height' of distribution, representing the most frequent observation value.

  • Default R script: mode(x)

Standard Deviation

  • Default R script: sd()
  • Advanced R script: apply(x,2, function(col) sd(col))

Skewness

Comparing to previous statistical measures, skewness can be applied to only one set at the time. However, this functional limitation is possible to overcome without any libraries using apply(). Otherwise, try timeSeries library with colSkewness().

  • Default R script: skewness()
  • fBasics library: colSkewness()
  • Advanced R script: apply(x,2, function(col) skewness(col))

Kurtosis

Same story as with Skewness.

  • Default R script: kurtosis()
  • fBasics library: colKurtosis()
  • Advanced R script: apply(x,2, function(col) kurtosis(col))

Other methods

Correlation

R code: cor()

Regression

R code: summary(lm(formula = y ~ x)

Beta

Normality test

Jacque-Bera test

Mostly used by economists.

  • R script: jarqueberaTest() or jbTest()

Shapiro-Wilk test

Kolmogorov-Smirnov test

Often used in Life Sciences.

  • R script: ksnormTest()

Securities & Portfolio Performance Assessment

Here are represented scripts to calculate ratios that enable to assess performance of the financial instruments.

Sharpe ratio

The most popular ratio to assess asset and portfolio performance. It is a ratio of market premium (Rp - Rf, difference between asset/portfolio return and risk free rate) and standard deviation of the asset/portfolio. The higher Sharpe, the better the performance has been for the selected period.

Treynor ratio

Alternative to Sharpe ratio, where denominator is beta of the asset/portfolio.

Sortinto ratio

The least popular ratio due to its complexity to calculate.

l

Clone this wiki locally