SyScSelection v1.0.1

0

Monthly downloads

0th

Percentile

Systemic Scenario Selection for Stress Testing

Quasi-Monte-Carlo algorithm for systematic generation of shock scenarios from an arbitrary multivariate elliptical distribution. The algorithm selects a systematic mesh of arbitrary fineness that approximately evenly covers an isoprobability ellipsoid in d dimensions (Flood, Mark D. & Korenko, George G. (2013) <doi:10.1080/14697688.2014.926018>). This package is the 'R' analogy to the 'Matlab' code published by Flood & Korenko in above-mentioned paper.

Readme

SyScSelection

Quasi-Monte-Carlo algorithm for systematic generation of shock scenarios from an arbitrary multivariate elliptical distribution. The algorithm selects a systematic mesh of arbitrary fineness that approximately evenly covers an isoprobability ellipsoid in d dimensions.
(Flood, Mark D. & Korenko, George G. "Systematic Scenario Selection", Office of Financial Research Working Paper #0005, 2013)

Installation:

install.packages("devtools")
library(devtools)
install_github("mvk222/SyScSelection")
library(SyScSelection)

Usage:

Example ellipsodial mesh for a normal distribution:

  • Estimate the mean and covariance matrix from the data:
    mu <- colMeans(data)
    sig <- cov(data)

  • The number of dimensions, d, is taken directly from the data:
    d <- length(data[1,])

  • Get the size parameter for a normal dist’n at a 95% threshold:
    calpha <- sizeparam_normal_distn(.95, d)

  • Create a hyperellipsoid object. Note that the constructor takes the inverse of the disperion matrix:
    hellip <- hyperellipsoid(mu, solve(sig), calpha)

  • Scenarios are calculated as a mesh of fineness 3. The number of scenarios is a function of the dimensionality of the hyperellipsoid and the fineness of the mesh:
    scenarios <- hypercube_mesh(3, hellip)

Example ellipsodial mesh for a t distribution:

  • Estimate the mean, covariance, and degrees of freedom from the data:
    mu <- colMeans(data)
    sig <- cov(data)
    nu <- dim(data)[1] - 1

  • The number of dimensions, d, is taken directly from the data:
    d <- length(data[1,])

  • Get the size parameter for a normal dist’n at a 95% threshold:
    calpha <- sizeparam_t_distn(.95, d, nu)

  • Create a hyperellipsoid object. Note that the constructor takes the inverse of the disperion matrix:
    hellip <- hyperellipsoid(mu, solve(sig), calpha)

  • Scenarios are calculated as a mesh of fineness 3. The number of scenarios is a function of the dimensionality of the hyperellipsoid and the fineness of the mesh:
    scenarios <- hypercube_mesh(3, hellip)

Functions in SyScSelection

Name Description
calc_mesh_size Calculates the number of points in a mesh of fineness phi, covering a hypercube in d dimensions
fill_adj_2Dface_beta Calculates the factor, beta in [0, 1], that interpolates the pth equidistant point between the two endpoints, z_one and z_phi, for and adjusted 2D mesh of fineness phi in d dimensions.
new_baseb_expansion Creates a new base-b sequence of a designated length
make_faces Fills a mesh with d-dimensional points representing all non-edge face points of a d-dimensional cube encompassing a d-dimensional unit spheroid.
fill_corners Systematically fills a given mesh array (cmesh) with d-dimensional points representing every corner of a d-dimensional hypercube. The function fills the successive dimensions of each point via depth-first recursion across all d dimensions.
rotate_to_coordaxes Rotates the ellipsoid (hellip) so its principal axes align with the coordinate axes. Both ellipsoids are centered at the origin. Note that there are (2^d)*d! valid ways to rotate the ellipsoid to the axes. This algorithm does not prescribe which solution will be provided.
sizeparam_normal_distn Calculates the size paramater for a d-dimensional hyperellipsoid conforming to a normal (i.e., Gaussian) distribution.
vertices Finds the d d-dimensional positive vertices for the given ellipsoid. A "positive" vertex is one where a principal axis for the ellipsoid intersects the surface of the ellipsoid in the direction of the corresponding eigenvector. (Recall that each of the eigenvectors of the ellipsoid's shape matrix is collinear with one of the principal axes.) This function does not assume that the ellipsoid is centered at the origin. Because the direction of each unit eigenvector is arbitrary (i.e., multiplication by -1 still yields a unit eigenvector), a simple algorithm is used to pick a consistent orientation for the vertex points.
univariate_shocks Calculates 2d d-dimensional univariate shocks (up and down in each of the d dimensions) based on the given ellipsoid. Univariate shocks are points on the surface of the ellipsoid that differ from the center of the ellipsoid in only one dimension. Thus, for an ellipsoid centered at the origin, only one element of a d-dimensional shock will be non-zero.This function does not assume that the ellipsoid is centered at the origin.
center_at_origin Creates a new ellipsoid object equivalent to the given hyperellipsoid (hellipse), but centered at the origin.
fill_adj_2Dface Creates a phi x phi grid (i.e., the mesh on a single two-dimensional face of a larger hypercube) of d-dimensional points, where the regularity of the grid has been adjusted to avoid clustering in the corners.
sizeparam_t_distn Calculates the size paramater for a d-dimensional hyperellipsoid conforming to a Student's t distribution.
make_corners Fills a mesh (corn_mesh) with d-dimensional points representing all corners of a d-dimensional cube encompassing a d-dimensional unit spheroid.
hyperellipsoid Hyperellipsoid class constructor
spheroid_mesh Generates a Cartesian mesh of d-dimensional scenarios based on the given ellipsoid. This function does not assume that the ellipsoid is centered at the origin.
hypercube_mesh Generates a Cartesian mesh of d-dimensional scenarios based on the given ellipsoid. This function does not assume that the ellipsoid is centered at the origin.
transform_ellipsoid Applies the given linear transformation, tfm, to the given ellipsoid. The ellipsoid (hellip) must be centered at the origin.
stretch_to_unitspheroid Stretches the ellipsoid (hellip) to the unit spheroid of the same dimension. Both the input ellipsoid and unit spheroid are centered at the origin.
get Get hyperellipsoid property from the specified object and return the value. Property names are: center, shape, and size
make_edges Fills a mesh with d-dimensional points representing all non-corner edge points of a d-dimensional cube encompassing a d-dimensional unit spheroid.
make_ellipsoid_from_vertices Constructs a new d-dimensional ellipsoid with the given "positive vertices", and size parameter, c. The constructed ellipsoid is centered at the origin.Note that the input vertices (i.e., the columns of V) must therefore be orthogonal vectors, themselves centered at the origin.The size parameter, c, may be needed because the points alone only determine the eigenvalues up to a positive constant. For vertices which fall on the constructed ellipsoid, choose as the size parameterc = 1.The new ellipsoid is centered at the origin.
baseb_expansion Adds the next base-b element to an existing base-b sequence
No Results!

Vignettes of SyScSelection

Name
Usage.Rmd
No Results!

Last month downloads

Details

Type Package
License CC0
Encoding UTF-8
LazyData true
RoxygenNote 7.1.0
VignetteBuilder knitr
NeedsCompilation no
Packaged 2020-06-30 09:34:39 UTC; merlin
Repository CRAN
Date/Publication 2020-06-30 09:50:02 UTC
suggests knitr , rmarkdown
imports pracma , stats
Contributors Merlin Kopfmann

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/SyScSelection)](http://www.rdocumentation.org/packages/SyScSelection)