View source: R/empirical_stats.R
empirical_stats | R Documentation |
Computes the mean, standard deviation, skewness, kurtosis, Value-at-Risk (VaR) and Conditional Value-at-Risk CVaR) under flexible probabilities.
empirical_stats(x, p, level = 0.01) ## Default S3 method: empirical_stats(x, p, level = 0.01) ## S3 method for class 'numeric' empirical_stats(x, p, level = 0.01) ## S3 method for class 'matrix' empirical_stats(x, p, level = 0.01) ## S3 method for class 'xts' empirical_stats(x, p, level = 0.01) ## S3 method for class 'ts' empirical_stats(x, p, level = 0.01) ## S3 method for class 'data.frame' empirical_stats(x, p, level = 0.01) ## S3 method for class 'tbl_df' empirical_stats(x, p, level = 0.01)
x |
A time series defining the scenario-probability distribution. |
p |
An object of the |
level |
A number with the desired probability level. The default is
|
The data in x
and p
are expected to have the same number of rows
(size).
A tidy tibble
with 3 columns:
stat: a column with Mu
, Std
, Skew
, Kurt
, VaR
and CVaR
.
name: the asset names.
value: the computed value for each statistic.
library(dplyr, warn.conflicts = FALSE) library(ggplot2) ret <- diff(log(EuStockMarkets)) # with equal weights (standard scenario) ew <- rep(1 / nrow(ret), nrow(ret)) empirical_stats(x = ret, p = as_ffp(ew)) %>% ggplot(aes(x = name, y = value)) + geom_col() + facet_wrap(~stat, scales = "free") + labs(x = NULL, y = NULL) # with ffp exp_smooth <- exp_decay(ret, 0.015) empirical_stats(ret, exp_smooth) %>% ggplot(aes(x = name, y = value)) + geom_col() + facet_wrap(~stat, scales = "free") + labs(x = NULL, y = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.