Entropy Pooling
This page illustrates the views and stress-testing functionality of the Entropy Pooling object. See Fully Flexible Views: Theory and Practice for the original article including a description of views confidence and opinion pooling, and Sequential Entropy Pooling Heuristics for a documentation of the sequential heuristics H1 and H2.
Control Parameters
The Entropy Pooling object has two common solver control parameters:
'obj_scalar'Scalar value for the relative entropy objective function. Default:
100.'maxiter'Maximum number of objective function evaluations. Default:
10000.
These can be set globally using the ep_options dictionary, e.g.,
from fortitudo.tech import investment_analysis as ia
ia.ep_options['obj_scalar'] = 10
ia.ep_options['maxiter'] = 1000
or for a particular Entropy Pooling instance:
ep = ia.EntropyPooling(pnl, options={'obj_scalar': 10, 'maxiter': 1000})
In addition, it is possible to directly use the options that are available for
the algorithms used to solve the Entropy Pooling problem. For problems with only
equality constraints, the
Newton-CG
algorithm is used. For problems with inequality constraints, the
TNC
algorithm is used. The algorithm specific options are set to their default values
except for 'ftol' for the
TNC
algorithm, which we set to 1e-12 by default.
Similar to the common control parameters, the algorithm specific parameters can be set globally:
ia.ep_options['TNC'] = {'ftol': 1e-8}
or for a particular Entropy Pooling instance:
ep = ia.EntropyPooling(pnl, options={'TNC': {'ftol': 1e-8}})
Fortitudo Technologies’ default values have been thoroughly tested with “percentage
return” P&L and work well with posterior parameters being accurate to a precision
below 1e-6. If you experience any convergence issues or want faster
computations with less accuracy, the control parameters can be relaxed.
- class EntropyPooling(pnl, p=None, **kwargs)
Entropy Pooling object that keeps track of P&L, prior probability, and views.
- Parameters:
pnl (
DataFrame) – P&L / risk factor simulation with shape (S, I).p (
ndarray) – Prior probability vector with shape (S,) for the S scenarios in pnl. Set to np.ones(S) / S by default.kwargs (
dict) – Options dictionary containing control parameters.
- Raises:
TypeError – If pnl is not a pd.DataFrame.
ValueError – If p is not a vector with shape (S,) containing strictly positive elements that sum to 1.
- add_rank_view(view_parameter, index, scalar=1.0, view_type='<=', confidence=1.0)
Method for adding a rank view.
- Parameters:
view_parameter (
str) – Parameter of the view: {‘mean’, ‘vol’, ‘skew’, ‘kurt’, ‘corr’}.index (
list) – List of indices for the view. For corr views a list[list[int, int], list[int, int]].scalar (
float) – Scalar value for the rank view of the form param1 <= scalar * param2. Default: 1.view_type (
str) – Type of equality or inequality view: {‘<=’, ‘=’}. Default: ‘<=’.confidence (
float) – View confidence. Default: 1.
- Raises:
TypeError – If scalar is not an integer or a float.
ValueError – If view_type not in {‘<=’, ‘=’}.
ValueError – If view_parameter not in {‘mean’, ‘vol’, ‘skew’, ‘kurt’, ‘corr’}.
TypeError – If index is not a list.
ValueError – If length of index is not 2.
TypeError – If one or more indices are not integers.
ValueError – If confidence is not in the interval (0, 1].
- add_view(view_parameter, index, view_type, view_value, confidence=1.0)
Method for adding a regular view.
- Parameters:
view_parameter (
str) – Parameter of the view: {‘mean’, ‘var’, ‘cvar’, ‘vol’, ‘skew’, ‘kurt’, ‘corr’}.index (
Union[int,list]) – Index(es) for the view. For corr views a list[int, int].view_type (
str) – Type of equality or inequality view: {‘<=’, ‘=’, ‘>=’}.view_value (
float) – View value.confidence (
float) – View confidence. Default: 1.
- Raises:
ValueError – If view_parameter not in {‘mean’, ‘alpha-var’, ‘alpha-cvar’ (for appropiate alpha), ‘vol’, ‘skew’, ‘kurt’, ‘corr’}.
ValueError – If view_type not in {‘<=’, ‘=’ ‘>=’}.
TypeError – If any index(es) is not an integer.
ValueError – If index is not a list of two integers for view_parameter=’corr’.
ValueError – If confidence is not in the interval (0, 1].
ValueError – If view_value is not in interval [-1, 1] for view_parameter=’corr’.
ValueError – If view_value is not positive for view_parameter=’vol’.
ValueError – If the view is an inequality view whose value is conflicting with an existing lower or upper bound.
- compute_posterior_probability(heuristic='H1', verbose=True)
Method for computing posterior probabilities.
- Parameters:
heuristic (
str) – Heuristic used for solving the Entropy Pooling problem: {‘H1’, ‘H2’, ‘Original’}. Default: ‘H1’.verbose (
bool) – Boolean indicating whether computation time, effective number of scenarios, and relative entropy should be printed once the computation is complete. Default: True.
- Return type:
ndarray- Returns:
Posterior probability vector with shape (S,).
- Raises:
ValueError – If heuristic not in {‘H1’, ‘H2’, ‘Original’}.