Acitve Portfolio Regret Optimizer¶
The ActivePortfolioRegretOptimizer
inherits the RegretOptimizer
. The minimum regret optimization is a technique under decision theory on making decisions under uncertainty.
The methods in the ActivePortfolioRegretOptimizer
are only applied at the first stage of the procedure. ActivePortfolioRegretOptimizer
houses the following convenience methods:
 maximize_eva
Maximize the expected value added of the portfolio. The objective function is the same with maximize returns as it just maximizes the total returns. For risk constraints, this method by default will constrain on tracking error and total CVaR. That is the volatility (tracking error) is calculated with the first variable (usually a passive portion) set to 0. Total CVaR has no treatments done to it. You can override these defaults in the method itself.
 minimize_tracking_error
Minimizes the tracking error of the portfolio. Tracking error is calculated by setting the first variable to 0 whilst the rest are updated by the optimizer.
 minimize_volatility
Minimizes the total portfolio volatility
 minimize_cvar
Minimizes the conditional value at risk (expected shortfall of the portfolio)
 maximize_info_ratio
Maximizes the information ratio of the portfolio. The information ratio of the portfolio is calculated like the Sharpe ratio. The only difference is the first variable is set to 0.
 maximize_sharpe_ratio
Maximizes the Sharpe ratio of the portfolio.

class
allopy.optimize.
ActivePortfolioRegretOptimizer
(data, cvar_data=None, prob=None, rebalance=False, sum_to_1=False, time_unit='quarterly', **kwargs)[source]¶ 
__init__
(data, cvar_data=None, prob=None, rebalance=False, sum_to_1=False, time_unit='quarterly', **kwargs)[source]¶ PortfolioRegretOptimizer houses several common prespecified regret optimization routines. Regret optimization is a scenario based optimization.
Notes
The term regret refers to the instance where after having decided on one alternative, the choice of a different alternative would have led to a more optimal (better) outcome when the eventual scenario transpires.
The RegretOptimizer employs a 2 stage optimization process. In the first step, the optimizer calculates the optimal weights for each scenario. In the second stage, the optimizer minimizes the regret function to give the final optimal portfolio weights.
Assuming the objective is to maximize returns subject to some volatility constraints, the first stage optimization will be as listed
\[\begin{split}\begin{gather*} \underset{w_s}{\max} R_s(w_s) \forall s \in S \\ s.t. \\ \sigma_s(w_s) \leq \Sigma \end{gather*}\end{split}\]where \(R_s(\cdot)\) is the returns function for scenario \(s\), \(\sigma_s(\cdot)\) is the volatility function for scenario \(s\) and \(\Sigma\) is the volatility threshold. Subsequently, to minimize the regret across all scenarios, \(S\),
\[\begin{gather*} \underset{w}{\min} \sum_{s \in S} p_s \cdot D(R_s(w_s)  R_s(w)) \end{gather*}\]Where \(D(\cdot)\) is a distance function (usually quadratic) and \(p_s\) is the discrete probability of scenario \(s\) occurring.
 Parameters
data (
List
[Union
[OptData
,ndarray
]]) – Scenario data. Each data must be a 3 dimensional tensor. Thus data will be a 4D tensor.cvar_data (optional) – CVaR scenario data. Each data must be a 3 dimensional tensor. Thus data will be a 4D tensor.
prob (
Union
[Iterable
[float
],Iterable
[int
],ndarray
,None
]) – Vector containing probability of each scenario occurringrebalance (bool, optional) – Whether the weights are rebalanced in every time instance. Defaults to False
sum_to_1 – If True, portfolio weights must sum to 1. Defaults to False
time_unit ({int, 'monthly', 'quarterly', 'semiannually', 'yearly'}, optional) – Specifies how many units (first axis) is required to represent a year. For example, if each time period represents a month, set this to 12. If quarterly, set to 4. Defaults to 12 which means 1 period represents a month. Alternatively, specify one of ‘monthly’, ‘quarterly’, ‘semiannually’ or ‘yearly’
kwargs – Other keyword arguments to pass to the
RegretOptimizer
base class
See also
RegretOptimizer
RegretOptimizer

maximize_eva
(max_vol=None, max_cvar=None, percentile=5.0, *, as_tracking_error=True, as_active_cvar=False, x0_first_level=None, x0_prop=None, approx=True, dist_func=<ufunc 'square'>, initial_solution='random', random_state=None)[source]¶ Optimizes the expected value added of the actively managed portfolio subject to max volatility and/or cvar constraint. At least one of the tracking error or cvar constraint must be defined.
If max_vol is defined, the tracking error will be offset by that amount. Maximum tracking error is usually defined by a positive number. Meaning if you would like to cap tracking error to 3%, max_te should be set to 0.03.
 Parameters
max_vol (float or list of floats, optional) – Maximum tracking error allowed. If a scalar, the same value will be used for each scenario optimization.
max_cvar (float or list of floats, optional) – Maximum cvar_data allowed. If a scalar, the same value will be used for each scenario optimization.
percentile (float) – The CVaR percentile value. This means to the expected shortfall will be calculated from values below this threshold
as_active_cvar (bool) – If True, the cvar constraint is calculated using the active portion of the weights. That is, the first value is forced to 0. If False, the cvar constraint is calculated using the entire weight vector.
as_tracking_error (bool) – If True, the volatility constraint is calculated using the active portion of the weights. That is, the first value is forced to 0. If False, the volatility constraint is calculated using the entire weight vector. This is also known as tracking error.
x0_first_level (list of list of floats or ndarray, optional) – List of initial solution vector for each scenario optimization. If provided, the list must have the same length at the first dimension as the number of solutions.
x0_prop (list of floats, optional) – Initial solution vector for the regret optimization (2nd level). This can either be the final optimization weights if
approx
isFalse
or the scenario proportion otherwise.approx (bool) – If True, a linear approximation will be used to calculate the regret optimal
dist_func (Callable) – A callable function that will be applied as a distance metric for the regret function. The default is a quadratic function. See Notes.
initial_solution (str, optional) – The method to find the initial solution if the initial vector
x0
is not specified. Set asNone
to disable. However, if disabled, the initial vector must be supplied.random_state (int, optional) – Random seed. Applicable if
initial_solution
is notNone

maximize_info_ratio
(*, x0_first_level=None, x0_prop=None, approx=True, dist_func=<ufunc 'square'>, initial_solution='random', random_state=None)[source]¶ Maximizes the information ratio the portfolio.
 Parameters
x0_first_level (list of list of floats or ndarray, optional) – List of initial solution vector for each scenario optimization. If provided, the list must have the same length at the first dimension as the number of solutions.
x0_prop (list of floats, optional) – Initial solution vector for the regret optimization (2nd level). This can either be the final optimization weights if
approx
isFalse
or the scenario proportion otherwise.approx (bool) – If True, a linear approximation will be used to calculate the regret optimal
dist_func (Callable) – A callable function that will be applied as a distance metric for the regret function. The default is a quadratic function. See Notes.
initial_solution (str, optional) – The method to find the initial solution if the initial vector
x0
is not specified. Set asNone
to disable. However, if disabled, the initial vector must be supplied.random_state (int, optional) – Random seed. Applicable if
initial_solution
is notNone
 Returns
Optimal weights
 Return type
ndarray

maximize_sharpe_ratio
(*, x0_first_level=None, x0_prop=None, approx=True, dist_func=<ufunc 'square'>, initial_solution='random', random_state=None)[source]¶ Maximizes the sharpe ratio the portfolio.
 Parameters
x0_first_level (list of list of floats or ndarray, optional) – List of initial solution vector for each scenario optimization. If provided, the list must have the same length at the first dimension as the number of solutions.
x0_prop (list of floats, optional) – Initial solution vector for the regret optimization (2nd level). This can either be the final optimization weights if
approx
isFalse
or the scenario proportion otherwise.approx (bool) – If True, a linear approximation will be used to calculate the regret optimal
dist_func (Callable) – A callable function that will be applied as a distance metric for the regret function. The default is a quadratic function. See Notes.
initial_solution (str, optional) – The method to find the initial solution if the initial vector
x0
is not specified. Set asNone
to disable. However, if disabled, the initial vector must be supplied.random_state (int, optional) – Random seed. Applicable if
initial_solution
is notNone
 Returns
Optimal weights
 Return type
ndarray

minimize_cvar
(min_ret=None, percentile=5.0, *, as_active_cvar=False, as_active_return=False, x0_first_level=None, x0_prop=None, approx=True, dist_func=<ufunc 'square'>, initial_solution='random', random_state=None)[source]¶ Minimizes the conditional value at risk of the portfolio. The present implementation actually minimizes the expected shortfall.
If the min_ret is specified, the optimizer will search for an optimal portfolio where the returns are at least as large as the value specified (if possible).
 Parameters
min_ret (float or list of floats, optional) – The minimum returns required for the portfolio. If a scalar, the same value will be used for each scenario optimization.
percentile (float) – The CVaR percentile value for the objective. This is the average expected shortfall from values below this threshold
as_active_cvar (bool, optional) – If True, minimizes the active cvar instead of the entire portfolio cvar. If False, minimizes the entire portfolio’s cvar
as_active_return (bool, optional) – If True, the returns constraint is calculated using the active portion of the weights. That is, the first value is forced to 0. If False, the returns constraint is calculated using the entire weight vector.
x0_first_level (list of list of floats or ndarray, optional) – List of initial solution vector for each scenario optimization. If provided, the list must have the same length at the first dimension as the number of solutions.
x0_prop (list of floats, optional) – Initial solution vector for the regret optimization (2nd level). This can either be the final optimization weights if
approx
isFalse
or the scenario proportion otherwise.approx (bool) – If True, a linear approximation will be used to calculate the regret optimal
dist_func (Callable) – A callable function that will be applied as a distance metric for the regret function. The default is a quadratic function. See Notes.
initial_solution (str, optional) – The method to find the initial solution if the initial vector
x0
is not specified. Set asNone
to disable. However, if disabled, the initial vector must be supplied.random_state (int, optional) – Random seed. Applicable if
initial_solution
is notNone
 Returns
Optimal weights
 Return type
ndarray

minimize_tracking_error
(min_ret=None, *, as_active_return=False, x0_first_level=None, x0_prop=None, approx=True, dist_func=<ufunc 'square'>, initial_solution='random', random_state=None)[source]¶ Minimizes the tracking error of the portfolio
If the min_ret is specified, the optimizer will search for an optimal portfolio where the returns are at least as large as the value specified (if possible).
 Parameters
min_ret (float or list of floats, optional) – The minimum returns required for the portfolio. If a scalar, the same value will be used for each scenario optimization.
as_active_return (boolean, optional) – If True, the returns constraint is calculated using the active portion of the weights. That is, the first value is forced to 0. If False, the returns constraint is calculated using the entire weight vector.
x0_first_level (list of list of floats or ndarray, optional) – List of initial solution vector for each scenario optimization. If provided, the list must have the same length at the first dimension as the number of solutions.
x0_prop (list of floats, optional) – Initial solution vector for the regret optimization (2nd level). This can either be the final optimization weights if
approx
isFalse
or the scenario proportion otherwise.approx (bool) – If True, a linear approximation will be used to calculate the regret optimal
dist_func (Callable) – A callable function that will be applied as a distance metric for the regret function. The default is a quadratic function. See Notes.
initial_solution (str, optional) – The method to find the initial solution if the initial vector
x0
is not specified. Set asNone
to disable. However, if disabled, the initial vector must be supplied.random_state (int, optional) – Random seed. Applicable if
initial_solution
is notNone

minimize_volatility
(min_ret=None, *, as_active_return=False, x0_first_level=None, x0_prop=None, approx=True, dist_func=<ufunc 'square'>, initial_solution='random', random_state=None)[source]¶ Minimizes the volatility of the portfolio
If the min_ret is specified, the optimizer will search for an optimal portfolio where the returns are at least as large as the value specified (if possible).
 Parameters
min_ret (float or list of floats, optional) – The minimum returns required for the portfolio. If a scalar, the same value will be used for each scenario optimization.
as_active_return (boolean, optional) – If True, the returns constraint is calculated using the active portion of the weights. That is, the first value is forced to 0. If False, the returns constraint is calculated using the entire weight vector.
x0_first_level (list of list of floats or ndarray, optional) – List of initial solution vector for each scenario optimization. If provided, the list must have the same length at the first dimension as the number of solutions.
x0_prop (list of floats, optional) – Initial solution vector for the regret optimization (2nd level). This can either be the final optimization weights if
approx
isFalse
or the scenario proportion otherwise.approx (bool) – If True, a linear approximation will be used to calculate the regret optimal
dist_func (Callable) – A callable function that will be applied as a distance metric for the regret function. The default is a quadratic function. See Notes.
initial_solution (str, optional) – The method to find the initial solution if the initial vector
x0
is not specified. Set asNone
to disable. However, if disabled, the initial vector must be supplied.random_state (int, optional) – Random seed. Applicable if
initial_solution
is notNone
