Documentation
Data
The P&L parameters from Vorobets [2022] and simulation from Vorobets [2021] follow with this package. The simulation assumes that returns follow a log-normal distribution, while the parameters are given by the Danish common return expectations for the 2nd half of 2021.
The parameters and simulation are used in the examples and allows you to immediately start exploring the functionality of this package. You can also use it to test your understanding of the theory by replicating results.
- load_parameters()
Function for loading the P&L parameters from Vorobets (2022).
- Return type
Tuple
[list
,ndarray
,ndarray
]- Returns
Instrument names, means vector, and covariance matrix.
- load_pnl()
Function for loading the P&L simulation from Vorobets (2021).
- Return type
DataFrame
- Returns
P&L simulation.
Entropy Pooling
The Entropy Pooling method solves the problem
subject to the constraints
The method was first introduced by Meucci [2008], while the code is implemented using notation from Vorobets [2021].
- entropy_pooling(p, A, b, G=None, h=None)
Function for computing Entropy Pooling posterior probabilities.
- Parameters
p (
ndarray
) – Prior probability vector with shape (S, 1).A (
ndarray
) – Equality constraint matrix with shape (M, S).b (
ndarray
) – Equality constraint vector with shape (M, 1).G (
Optional
[ndarray
]) – Inequality constraint matrix with shape (N, S).h (
Optional
[ndarray
]) – Inequality constraint vector with shape (N, 1).
- Return type
ndarray
- Returns
Posterior probability vector with shape (S, 1).
Optimization
The MeanCVaR and MeanVariance objects solve the problem
with \(\mathcal{R}\left(w\right)\) being the CVaR or variance risk measure, subject to the constraints
A method for solving the CVaR problem was first introduced by Rockafellar and Uryasev [2000], while the implemented algorithm is based on Künzi-Bay and Mayer [2006]. The notation in relation to the P&L simulations \(R\) follows Vorobets [2021]. For the variance risk measure, a standard quadratic programming solver is used.
- class MeanCVaR(R, A=None, b=None, G=None, h=None, p=None, alpha=None, **kwargs)
Class for efficient mean-CVaR optimization using Benders decomposition.
- Parameters
R (
ndarray
) – Matrix with P&L simulations and shape (S, I).A (
Optional
[ndarray
]) – Equality constraints matrix with shape (M, I).b (
Optional
[ndarray
]) – Equality constraints matrix with shape (M,).G (
Optional
[ndarray
]) – Inequality constraints matrix with shape (N, I).h (
Optional
[ndarray
]) – Inequality constraints vector with shape (N,).p (
Optional
[ndarray
]) – Vector containing scenario probabilities with shape (S, 1). Default: np.ones((S, 1)) / S.alpha (
Optional
[float
]) – Alpha value for alpha-VaR and alpha-CVaR. Default: 0.95.kwargs (
dict
) – options dictionary with Benders algorithm parameters.
- efficient_frontier(num_portfolios=None)
Method for computing the efficient frontier.
- Parameters
num_portfolios (
Optional
[int
]) – Number of portfolios used to span the efficient frontier. Default: 9.- Return type
ndarray
- Returns
Efficient frontier with shape (I, num_portfolios).
- Raises
ValueError – If constraints are infeasible or max_expected_return is unbounded.
- efficient_portfolio(return_target=None)
Method for computing a mean-CVaR efficient portfolio with return a target.
- Parameters
return_target (
Optional
[float
]) – Return target for the efficient portfolio. The minimum CVaR portfolio is computed by default.- Return type
ndarray
- Returns
Efficient portfolio exposures with shape (I, 1).
- class MeanVariance(mean, covariance_matrix, A=None, b=None, G=None, h=None)
Class for efficient mean-variance optimization.
- Parameters
mean (
ndarray
) – Mean vector with shape (I,).covariance_matrix (
ndarray
) – Covariance matrix with shape (I, I).A (
Optional
[ndarray
]) – Equality constraints matrix with shape (M, I).b (
Optional
[ndarray
]) – Equality constraints matrix with shape (M,).G (
Optional
[ndarray
]) – Inequality constraints matrix with shape (N, I).h (
Optional
[ndarray
]) – Inequality constraints vector with shape (N,).
- efficient_frontier(num_portfolios=None)
Method for computing the efficient frontier.
- Parameters
num_portfolios (
Optional
[int
]) – Number of portfolios used to span the efficient frontier. Default: 9.- Return type
ndarray
- Returns
Efficient frontier with shape (I, num_portfolios).
- Raises
ValueError – If constraints are infeasible or max_expected_return is unbounded.
- efficient_portfolio(return_target=None)
Method for computing a mean-variance efficient portfolio with a return target.
- Parameters
return_target (
Optional
[float
]) – Return target for the efficient portfolio. The minimum variance portfolio is computed by default.- Return type
ndarray
- Returns
Efficient portfolio exposures with shape (I, 1).
Algorithm Parameters
For the variance risk measure, CVXOPT’s default values are used. These can be adjusted directly following the instructions given in the link.
For the CVaR risk measure, control parameters can be set globally using the cvar_options dictionary, e.g.,
import fortitudo.tech as ft
ft.cvar_options['demean'] = False
ft.cvar_options['R_scalar'] = 10000
or for a particular instance of the MeanCVaR class:
opt = ft.MeanCVaR(R, A, b, G, h, options={'demean': False, 'R_scalar': 10000})
The following parameters can be adjusted:
'demean'
Whether to use demeaned P&L when calculating CVaR. Default:
True
.'R_scalar'
Scaling factor for the P&L simulation. Default:
1000
.'maxiter'
Maximum number of iterations for the decomposition algorithm, i.e., maximum number of relaxed master problems the algorithm is allowed to solve. Default:
500
.'reltol'
Relative tolerance for the difference between the currently best upper and lower bounds. Default:
1e-8
.'abstol'
Absolute tolerance for the difference between the currently best upper and lower bounds if the lower bound is less than
1e-10
. Default:1e-8
.
The algorithm stops when one of the 'maxiter'
, 'reltol'
,
or 'abstol'
conditions are satisfied. The parameters have been tested
with “percentage return” P&L and work well. In most cases, the algorithm stops
due to relative convergence in less than 100 iterations. If you use P&L
simulations that are scaled differently, you might need to adjust them.