# Portfolio Regret Optimizer¶

The PortfolioRegretOptimizer inherits the RegretOptimizer. The minimum regret optimization is a technique under decision theory on making decisions under uncertainty.

The methods in the PortfolioRegretOptimizer are only applied at the first stage of the procedure. The PortfolioRegretOptimizer houses the following convenience methods:

maximize_returns

Maximize the returns of the portfolio. You may put in volatility or CVaR constraints for this procedure.

minimize_volatility

Minimizes the total portfolio volatility

minimize_cvar

Minimizes the conditional value at risk (expected shortfall of the portfolio)

maximize_sharpe_ratio

Maximizes the Sharpe ratio of the portfolio.

class allopy.optimize.PortfolioRegretOptimizer(data, cvar_data=None, prob=None, rebalance=True, sum_to_1=True, time_unit='quarterly', **kwargs)[source]
__init__(data, cvar_data=None, prob=None, rebalance=True, sum_to_1=True, time_unit='quarterly', **kwargs)[source]

PortfolioRegretOptimizer houses several common pre-specified 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 4-D tensor.

• cvar_data (optional) – CVaR scenario data. Each data must be a 3 dimensional tensor. Thus data will be a 4-D tensor.

• prob (Union[Iterable[float], Iterable[int], ndarray, None]) – Vector containing probability of each scenario occurring

• rebalance (bool, optional) – Whether the weights are rebalanced in every time instance. Defaults to True

• sum_to_1 – If True, portfolio weights must sum to 1. Defaults to True

• time_unit ({int, 'monthly', 'quarterly', 'semi-annually', '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’, ‘semi-annually’ or ‘yearly’

• kwargs – Other keyword arguments to pass to the RegretOptimizer base class

RegretOptimizer

RegretOptimizer

maximize_returns(max_vol=None, max_cvar=None, percentile=5.0, *, x0_first_level=None, x0_prop=None, approx=True, dist_func=<ufunc 'square'>, initial_solution='random', random_state=None)[source]

Optimizes the expected returns of the 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

• 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 is False 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 as None to disable. However, if disabled, the initial vector must be supplied.

• random_state (int, optional) – Random seed. Applicable if initial_solution is not None

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 is False 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 as None to disable. However, if disabled, the initial vector must be supplied.

• random_state (int, optional) – Random seed. Applicable if initial_solution is not None

Returns

Optimal weights

Return type

ndarray

minimize_cvar(min_ret=None, percentile=5.0, *, 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

• 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 is False 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 as None to disable. However, if disabled, the initial vector must be supplied.

• random_state (int, optional) – Random seed. Applicable if initial_solution is not None

Returns

Optimal weights

Return type

ndarray

minimize_volatility(min_ret=None, *, 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.

• 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 is False 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 as None to disable. However, if disabled, the initial vector must be supplied.

• random_state (int, optional) – Random seed. Applicable if initial_solution is not None