UncertaintyPenalty

class allopy.penalty.UncertaintyPenalty(uncertainty, alpha=0.95, method='direct', dim=None)[source]
__init__(uncertainty, alpha=0.95, method='direct', dim=None)[source]

The uncertainty penalty. It penalizes the objective function relative to the level of uncertainty for the given asset

Notes

Given an initial maximizing objective, this penalty will change the objective to

\[f(w) - \lambda \sqrt{w^T \Phi w}\]

where \(\Phi\) represent the uncertainty matrix. \(\lambda = 0\) or a 0-matrix is a special case where there are no uncertainty in the projections.

If using \(\chi^2\) method, the \(\lambda\) value is given by

\[\lambda = \frac{1}{\chi^2_{n - 1}(\alpha)}\]

where \(n\) is the number of asset classes and \(\alpha\) is the confidence interval. Otherwise the “direct” method will have \(\lambda = \alpha\).

Parameters
  • uncertainty (Union[Iterable[Union[int, float]], ndarray]) – A 1D vector or 2D matrix representing the uncertainty for the given asset class. If a 1D vector is provided, it will be converted to a diagonal matrix

  • alpha (float) – A constant controlling the intensity of the penalty

  • method ("chi2" or "direct") – Method used to construct the lambda parameter. If “direct”, the exact value specified by the alpha parameter is used. If “chi2”, the value is determined using the inverse of the chi-square quantile function. In that instance, the alpha parameter will be the confidence level. See Notes.

  • dim (int) – If provided, it will override the default dimension of the penalty which is determined by the length of the uncertainty vector/matrix provided

cost(w)[source]

Calculates the penalty to apply

\[p(w) = \lambda \sqrt{w^T \Phi w}\]
Return type

float