empirical_stats {ffp} | R Documentation |
Summary Statistics for Empirical Distributions
Description
Computes the mean, standard deviation, skewness, kurtosis, Value-at-Risk (VaR) and Conditional Value-at-Risk CVaR) under flexible probabilities.
Usage
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)
Arguments
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
|
Details
The data in x
and p
are expected to have the same number of rows
(size).
Value
A tidy tibble
with 3 columns:
stat: a column with
Mu
,Std
,Skew
,Kurt
,VaR
andCVaR
.name: the asset names.
value: the computed value for each statistic.
Examples
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)
[Package ffp version 0.2.2 Index]