Convex Portfolio Optimization





https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86
Buy Me a Coffee at ko-fi.com

Convex Portfolio Models

Mean Risk Portfolio Optimization

Riskfolio-Lib allows to calculate optimum portfolios that results from optimize one of the following 4 objective functions:

  • Maximum Return Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad R (w)\\ \text{s.t.} & \quad Aw \leq b\\ & \quad A_{\text{RC}} \text{RC}(w) \leq b_{\text{RC}} \text{Tr} \left ( \Sigma W \right)(w)\\ & \quad \varrho_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,24] \\ & \quad R (w) \geq \overline{\mu} \\ \end{aligned}\end{split}\]
  • Minimum Risk Portfolio:

\[\begin{split}\begin{aligned} \min_{w} & \quad \varrho_{k}(w)\\ \text{s.t.} & \quad A w \leq b\\ & \quad A_{\text{RC}} \text{RC}(w) \leq b_{\text{RC}} \text{Tr} \left ( \Sigma W \right)(w)\\ & \quad \varrho_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,24] \\ & \quad R (w) \geq \overline{\mu} \\ \end{aligned}\end{split}\]
  • Maximum Risk Adjusted Return Ratio Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad \frac{R (w) - r_{f}}{\varrho_{k}(w)}\\ \text{s.t.} & \quad Aw \leq b\\ & \quad A_{\text{RC}} \text{RC}(w) \leq b_{\text{RC}} \text{Tr} \left ( \Sigma W \right)(w)\\ & \quad \varrho_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,24] \\ & \quad R (w) \geq \overline{\mu} \\ \end{aligned}\end{split}\]
  • Maximum Utility Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad R (w) - \lambda \varrho_{k}(w)\\ \text{s.t.} & \quad Aw \leq b\\ & \quad A_{\text{RC}} \text{RC}(w) \leq b_{\text{RC}} \text{Tr} \left ( \Sigma W \right)(w)\\ & \quad \varrho_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,24] \\ & \quad R (w) \geq \overline{\mu} \\ \end{aligned}\end{split}\]

where:

\(R (w)\) is the return function, possible values are:

  • \(\mu w\): arithmetic return.

  • \(\mu w - 0.5 w^{\tau} \Sigma w\): approximate logarithmic return [A1].

  • \(\frac{1}{T} \sum^{T}_{i=1} \ln (1+ r_{i} w)\): exact logarithmic return [A2].

\(w\): is the vector of weights of the optimum portfolio.

\(W\): is the symmetric matrix variable that approximates \(w w^{\prime}\).

\(\mu\): is the vector of expected returns.

\(\Sigma\): is the covariance matrix of assets returns.

\(r\): is the matrix of assets returns.

\(c_i\): is the upper bound of risk measure \(i\).

\(Aw \leq b\): is a set of linear constraints.

\(A_{\text{RC}} \text{RC}(w) \leq b_{\text{RC}} \text{Tr} \left ( \Sigma W \right)(w)\) is a set of linear risk contribution constraints for variance based on [A3].

\(\varrho_{i}(w)\): are 24 available risk measures. The available risk measures are:

  • Standard Deviation [A4].

  • Square Root Kurtosis [A5], [A6].

  • p-th Root Even Moment of Order 2p [A7].

  • Mean Absolute Deviation [A8].

  • Gini Mean Difference [A9], [A10], [A11].

  • Conditional Value at Risk Range [A10], [A12].

  • Tail Gini Range [A10], [A12].

  • Entropic Value at Risk Range [A12].

  • Relativistic Value at Risk Range.:cite:a-Cajas2025book.

  • Range [A10].

  • Semi Standard Deviation [A13].

  • Square Root Semi Kurtosis [A5], [A6].

  • p-th Root Even Semi Moment of Order 2p [A7].

  • First Lower Partial Moment (Omega Ratio) [A14].

  • Second Lower Partial Moment (Sortino Ratio) [A14].

  • Conditional Value at Risk [A15].

  • Tail Gini [A16], [A10], [A11].

  • Entropic Value at Risk [A17], [A18], [A19].

  • Relativistic Value at Risk [A20].

  • Worst Realization (Minimax) [A21].

  • Average Drawdown of uncompounded cumulative returns [A22].

  • Ulcer Index of uncompounded cumulative returns [A23].

  • Conditional Drawdown at Risk of uncompounded cumulative returns [A22].

  • Entropic Drawdown at Risk of uncompounded cumulative returns [A19].

  • Relativistic Drawdown at Risk of uncompounded cumulative returns [A20].

  • Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio) [A22].

\(c_{i}\): are maximum values on each risk measure.

\(r_{f}\): is the risk free rate. When the risk measure is the first or second lower partial moment, \(r_{f}\) is the minimum acceptable return \(\text{MAR}\).

\(\lambda\): is the risk aversion coefficient of the investor.

Risk Parity Portfolio Optimization

Riskfolio-Lib allows to calculate optimum portfolios that results from optimize the general vanilla risk parity model [A24] [A25]:

\[\begin{split}\begin{aligned} \min_{w} & \quad \varrho(w) \\ \text{s.t.} & \quad \mathbf{b}^{\prime} \log(w) \geq c \\ & \quad \mu w \geq \overline{\mu} \\ & \quad Aw \leq b \\ & \quad w \geq 0 \\ \end{aligned}\end{split}\]

where:

\(w\): is the vector of weights of the optimum portfolio.

\(\mu\): is the vector of expected returns.

\(\mathbf{b}\): is a vector of risk contribution targets.

\(Aw \leq b\): is a set of linear constraints.

\(c\): is an arbitrary constant.

\(\varrho(w)\): are 20 available risk measures. The available risk measures are:

  • Standard Deviation [A4].

  • Square Root Kurtosis [A5], [A6].

  • Mean Absolute Deviation [A8].

  • Gini Mean Difference [A9], [A10], [A11].

  • Conditional Value at Risk Range [A10], [A12].

  • Tail Gini Range [A10], [A12].

  • Entropic Value at Risk Range [A12].

  • Relativistic Value at Risk Range [A12].

  • Semi Standard Deviation [A13].

  • Square Root Semi Kurtosis [A5], [A6].

  • First Lower Partial Moment (Omega Ratio) [A14].

  • Second Lower Partial Moment (Sortino Ratio) [A14].

  • Conditional Value at Risk [A15].

  • Tail Gini [A16], [A10], [A11].

  • Entropic Value at Risk [A17], [A18], [A19].

  • Relativistic Value at Risk [A20].

  • Ulcer Index of uncompounded cumulative returns [A23].

  • Conditional Drawdown at Risk of uncompounded cumulative returns [A22].

  • Entropic Drawdown at Risk of uncompounded cumulative returns [A19].

  • Relativistic Drawdown at Risk of uncompounded cumulative returns [A20].

\(c\): is an arbitrary constant.

Relaxed Risk Parity Portfolio Optimization

Riskfolio-Lib allows to calculate optimum portfolios that results from optimize the relaxed risk parity model [A26]:

\[\begin{split}\begin{aligned} \min_{w} & \quad \psi - \gamma & \\ \text{s.t.} & \quad \zeta = \Sigma w \\ & \quad w^{\prime} \Sigma w \leq \left ( \psi^{2} - \rho^{2} \right ) & \\ & \quad w_{i} \zeta_{i} \geq \gamma^{2} b_{i} & \forall i=1 , \ldots , N \\ & \quad \lambda w^{\prime} \Theta w \leq \rho^{2} & \\ & \quad \mu w \geq \overline{\mu} & \\ & \quad Aw \leq b & \\ & \quad \sum^{N}_{i=1} w_{i} = 1 & \\ & \quad \psi, \gamma, \rho, w \geq 0 & \\ \end{aligned}\end{split}\]

where:

\(w\): is the vector of weights of the optimum portfolio.

\(\mu\): is the vector of expected returns.

\(\Sigma\): is the covariance matrix of assets returns.

\(\psi\): is the average risk of the portfolio.

\(\gamma\): is the lower bound of each asset risk contribution.

\(\mathbf{b}\): is the vector of risk contribution targets.

\(\zeta_{i}\): is the marginal risk of asset \(i\).

\(\rho\): is a regularization variable.

\(\lambda\): is a penalty parameter of \(\rho\).

\(\Theta = \text{diag}(\Sigma)\)

\(Aw \leq b\): is a set of linear constraints.

Worst Case Mean Variance Portfolio Optimization

Riskfolio-Lib allows to calculate worst case mean variance optimum portfolios [A27] [A28] [A29] [A30] that results from optimize one of the following 4 objective functions:

  • Worst Case Maximum Return Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad \min_{\mu \, \in \, U_{\mu}} \mu w\\ \text{s.t.} & \quad Aw \leq b\\ \end{aligned}\end{split}\]
  • Worst Case Minimum Risk Portfolio:

\[\begin{split}\begin{aligned} \min_{w} & \quad \max_{\Sigma \, \in \, U_{\Sigma}} w^{\prime} \Sigma w\\ \text{s.t.} & \quad Aw \leq b\\ \end{aligned}\end{split}\]
  • Worst Case Maximum Risk Adjusted Return Ratio Portfolio:

\[\begin{split}\begin{aligned} \underset{w}{\max} & \quad \cfrac{\min_{\mu \, \in \, U_{\mu}} \mu w - r_{f}} {\max_{\Sigma \, \in \, U_{\Sigma}} \sqrt{w^{\prime} \Sigma w}}\\ \text{s.t.} & \quad Aw \leq b\\ \end{aligned}\end{split}\]
  • Worst Case Maximum Utility Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad \min_{\mu \, \in \, U_{\mu}} \mu w - \max_{\Sigma \, \in \, U_{\Sigma}} \lambda w^{\prime} \Sigma w\\ \text{s.t.} & \quad Aw \leq b\\ \end{aligned}\end{split}\]

where:

\(w\) are the weights of the portfolio.

\(\mu\): is the vector of expected returns.

\(\Sigma\) is the covariance matrix.

\(U_{\mu}\) is the uncertainty set of the mean vector. The uncertainty sets can be:

\[\begin{split}\begin{aligned} U^{box}_{\mu} & = \left \{ \mu \, | \, | \mu - \hat{\mu} | \leq \delta \right \} \\ U^{ellip}_{\mu} & = \left \{ \mu \, | \left ( \mu - \hat{\mu} \right ) \Sigma^{-1}_{\mu} \left ( \mu - \hat{\mu} \right )^{\prime} \leq k^{2}_{\mu} \right \} \\ \end{aligned}\end{split}\]

\(U_{\Sigma}\) is the uncertainty set of the covariance matrix. The uncertainty sets can be:

\[\begin{split}\begin{aligned} U^{box}_{\Sigma} & = \left \{ \Sigma \, | \, \Sigma_{lower} \leq \Sigma \leq \Sigma_{upper} \, , \, \Sigma \succeq 0 \right \} \\ U^{ellip}_{\Sigma} & = \left \{ \Sigma \, | \left ( \text{vec}(\Sigma) - \text{vec}(\hat{\Sigma}) \right ) \Sigma^{-1}_{\Sigma} \left ( \text{vec}(\Sigma) - \text{vec}(\hat{\Sigma}) \right )^{\prime} \leq k^{2}_{\Sigma} \, , \, \Sigma \succeq 0 \right \} \\ \end{aligned}\end{split}\]

\(Aw \leq b\): is a set of linear constraints.

\(r_{f}\): is the risk free rate.

\(\lambda\): is the risk aversion coefficient of the investor.

Mean Variance Portfolio Optimization with Factor Risk Contribution Constraints

Riskfolio-Lib allows to calculate optimum portfolios that results from optimize one of the following 4 objective functions:

  • Maximum Return Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad R (w)\\ \text{s.t.} & \quad \begin{bmatrix} W_{F} & W_{F} \\ w^{\prime}_{F} & 1 \end{bmatrix} \succeq 0 \\ & \quad w = (B^{\prime})^{+} W_{F} \\ & \quad Aw \leq b\\ & \quad A_{\text{FRC}} \text{diag}\left ( \bar{\Sigma} W_{F} \right) \leq b_{\text{FRC}} \, \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \\ & \quad \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \leq c \\ & \quad R (w) \geq \overline{\mu} \\ & \quad W_{F} \in \mathbf{S}^{m}\\ \end{aligned}\end{split}\]
  • Minimum Risk Portfolio:

\[\begin{split}\begin{aligned} \min_{w} & \quad \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \\ \text{s.t.} & \quad \begin{bmatrix} W_{F} & w_{F} \\ w^{\prime}_{F} & 1 \end{bmatrix} \succeq 0 \\ & \quad w = (B^{\prime})^{+} w_{F} \\ & \quad Aw \leq b\\ & \quad A_{\text{FRC}} \text{diag}\left ( \bar{\Sigma} W_{F} \right) \leq b_{\text{FRC}} \, \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \\ & \quad \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \leq c \\ & \quad R (w) \geq \overline{\mu} \\ & \quad W_{F} \in \mathbf{S}^{m}\\ \end{aligned}\end{split}\]
  • Maximum Risk Adjusted Return Ratio Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad \frac{R (w) - r_{f}}{\text{Tr} \left ( \bar{\Sigma} W_{F} \right )}\\ \text{s.t.} & \quad \begin{bmatrix} W_{F} & w_{F} \\ w^{\prime}_{F} & 1 \end{bmatrix} \succeq 0 \\ & \quad w = (B^{\prime})^{+} w_{F} \\ & \quad Aw \leq b\\ & \quad A_{\text{FRC}} \text{diag}\left ( \bar{\Sigma} W_{F} \right) \leq b_{\text{FRC}} \, \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \\ & \quad \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \leq c \\ & \quad R (w) \geq \overline{\mu} \\ & \quad W_{F} \in \mathbf{S}^{m}\\ \end{aligned}\end{split}\]
  • Maximum Utility Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad R (w) - \lambda \text{Tr} \left ( \bar{\Sigma} W_{F} \right )\\ \text{s.t.} & \quad \begin{bmatrix} W_{F} & w_{F} \\ w^{\prime}_{F} & 1 \end{bmatrix} \succeq 0 \\ & \quad w = (B^{\prime})^{+} w_{F} \\ & \quad Aw \leq b\\ & \quad A_{\text{FRC}} \text{diag}\left ( \bar{\Sigma} W_{F} \right) \leq b_{\text{FRC}} \, \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \\ & \quad \text{Tr} \left ( \bar{\Sigma} W_{F} \right ) \leq c \\ & \quad R (w) \geq \overline{\mu} \\ & \quad W_{F} \in \mathbf{S}^{m}\\ \end{aligned}\end{split}\]

where:

\(R (w)\) is the return function, possible values are:

  • \(\mu w\): arithmetic return.

  • \(\mu w - 0.5 w^{\tau} \Sigma w\): approximate logarithmic return [A1].

  • \(\frac{1}{T} \sum^{T}_{i=1} \ln (1+ r_{i} w)\): exact logarithmic return [A2].

\(w_f\) are the weights of the risk factors.

\(W_f\): is the symmetric matrix variable that approximates \(w_f w^{\prime}_f\).

\(B\) is the loadings matrix.

\(\mu\): is the vector of expected returns.

\(\Sigma\): is the covariance matrix of assets returns.

\(r\): is the matrix of assets returns.

\(c\): is the upper bound of risk measure.

\(\bar{\Sigma} = \left ((B^{\prime})^{+} \right )^{\prime} \Sigma (B^{\prime})^{+}\).

\(Aw \leq b\): is a set of linear constraints.

\(A_{\text{FRC}} \text{diag}\left ( \bar{\Sigma} W_{F} \right) \leq b_{\text{FRC}} \, \text{Tr} \left ( \bar{\Sigma} W_{F} \right )\) is a set of linear factor risk contribution constraints for variance based on [A3].

Ordered Weighted Averaging (OWA) Portfolio

Riskfolio-Lib allows to calculate the OWA portfolio optimization model [A10]. We can use this function to calculate the Higher L-Moment portfolio optimization model [A31].

  • Maximum Return Portfolio:

\[\begin{split}\begin{aligned} \min_{w} & \quad R (w) \\ \text{s.t.} & \quad Aw \leq b\\ & \quad y = rw \\ & \quad \sum^{T}_{i=0} v_{[i]}y_{[i]} \leq c \\ \end{aligned}\end{split}\]
  • Minimum Risk Portfolio:

\[\begin{split}\begin{aligned} \min_{w} & \quad \sum^{T}_{i=0} v_{[i]}y_{[i]} \\ \text{s.t.} & \quad Aw \leq b\\ & \quad y = rw \\ & \quad R (w) \geq \overline{\mu} \\ \end{aligned}\end{split}\]
  • Maximum Risk Adjusted Return Ratio Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad \frac{R (w) - r_{f}}{\sum^{T}_{i=0} v_{[i]}y_{[i]}}\\ \text{s.t.} & \quad Aw \leq b\\ & \quad y = rw \\ & \quad R (w) \geq \overline{\mu} \\ \end{aligned}\end{split}\]
  • Maximum Utility Portfolio:

\[\begin{split}\begin{aligned} \max_{w} & \quad R (w) - \lambda \left ( \sum^{T}_{i=0} v_{[i]}y_{[i]} \right) \\ \text{s.t.} & \quad Aw \leq b\\ & \quad y = rw \\ & \quad R (w) \geq \overline{\mu} \\ \end{aligned}\end{split}\]

Where:

\(w\) are the weights of the portfolio.

\(v\) are the weights of the owa operator.

\(c\): is the upper bound of risk measure.

\(\mu\): is the vector of expected returns.

\(X_{[i]}\): is the element of order \(i\) in ascending order of vector \(X\).

Mean-Variance-Skewness-Kurtosis (MVSK) Portfolio

Riskfolio-Lib allows to calculate the utility function version of the MVSK portfolio optimization model based on the semidefinite relaxation proposed by [A32].

  • Maximum Return Portfolio:

\[\begin{split}\begin{aligned} \max_{w, \, W^{(2)}, \, W^{(3)*}, \, W^{(4)*}} \; & \quad M^{\prime}_{1}w \\ \text{s.t.} \qquad \,\,\, & \quad M^{(4)*} \succeq 0 \\ & \quad M^{(4)*} = \begin{bmatrix} 1 \qquad & \quad w^{\prime} \quad & \text{vec}(W^{(2)})^{\prime} L^{\prime}_{2} \\ w \qquad & \quad W^{(2)} \quad & \quad W^{(3)*\prime} & \\ L_{2}\text{vec}(W^{(2)}) &\quad W^{(3)*} \quad & \quad W^{(4)*} \\ \end{bmatrix} \\ & \quad \text{Tr}(\Sigma_{2} \, W^{(2)}) \leq \overline{\mu}_{2}\\ & \quad \text{Tr}(M_{3} \, D_{2} \, W^{(3)*}) \geq \overline{\mu}_{3} \\ & \quad - \lambda_{4} \text{Tr}(S_{2} \, \Sigma_{4} \, S^{\prime}_{2} \, W^{(4)*}) \leq \overline{\mu}_{4}\\ & \quad W^{(2)} \in \mathbf{S}^{n}\\ & \quad W^{(4)*} \in \mathbf{S}^{n(n+1)/2} \\ & \quad Aw \leq b\\ \end{aligned}\end{split}\]
  • Minimum Risk Portfolio:

\[\begin{split}\begin{aligned} \min_{w, \, W^{(2)}, \, W^{(3)*}, \, W^{(4)*}} \; & \quad \lambda_{2} \text{Tr}(\Sigma_{2} \, W^{(2)}) - \lambda_{3} \text{Tr}(M_{3} \, D_{2} \, W^{(3)*}) \\ & \quad + \lambda_{4} \text{Tr}(S_{2} \, \Sigma_{4} \, S^{\prime}_{2} \, W^{(4)*})\\ \text{s.t.} \qquad \,\,\, & \quad M^{(4)*} \succeq 0 \\ & \quad M^{(4)*} = \begin{bmatrix} 1 \qquad & \quad w^{\prime} \quad & \text{vec}(W^{(2)})^{\prime} L^{\prime}_{2} \\ w \qquad & \quad W^{(2)} \quad & \quad W^{(3)*\prime} & \\ L_{2}\text{vec}(W^{(2)}) &\quad W^{(3)*} \quad & \quad W^{(4)*} \\ \end{bmatrix} \\ & \quad M^{\prime}_{1}w \geq \overline{\mu}_{1} \\ & \quad W^{(2)} \in \mathbf{S}^{n}\\ & \quad W^{(4)*} \in \mathbf{S}^{n(n+1)/2} \\ & \quad Aw \leq b\\ \end{aligned}\end{split}\]
  • Maximum Risk Adjusted Return Ratio Portfolio:

\[\begin{split}\begin{aligned} \min_{w, \, W^{(2)}, \, W^{(3)*}, \, W^{(4)*}} \; & \quad \frac{M^{\prime}_{1}w - r_{f}}{\lambda_{2} \text{Tr}(\Sigma_{2} \, W^{(2)}) - \lambda_{3} \text{Tr}(M_{3} \, D_{2} \, W^{(3)*}) + \lambda_{4} \text{Tr}(S_{2} \, \Sigma_{4} \, S^{\prime}_{2} \, W^{(4)*})}\\ \text{s.t.} \qquad \,\,\, & \quad M^{(4)*} \succeq 0 \\ & \quad M^{(4)*} = \begin{bmatrix} 1 \qquad & \quad w^{\prime} \quad & \text{vec}(W^{(2)})^{\prime} L^{\prime}_{2} \\ w \qquad & \quad W^{(2)} \quad & \quad W^{(3)*\prime} & \\ L_{2}\text{vec}(W^{(2)}) &\quad W^{(3)*} \quad & \quad W^{(4)*} \\ \end{bmatrix} \\ & \quad W^{(2)} \in \mathbf{S}^{n}\\ & \quad W^{(4)*} \in \mathbf{S}^{n(n+1)/2} \\ & \quad Aw \leq b\\ \end{aligned}\end{split}\]
  • Maximum Utility Portfolio:

\[\begin{split}\begin{aligned} \max_{w, \, W^{(2)}, \, W^{(3)*}, \, W^{(4)*}} \; & \quad M^{\prime}_{1}w - \lambda_{2} \text{Tr}(\Sigma_{2} \, W^{(2)}) + \lambda_{3} \text{Tr}(M_{3} \, D_{2} \, W^{(3)*}) \\ & \quad - \lambda_{4} \text{Tr}(S_{2} \, \Sigma_{4} \, S^{\prime}_{2} \, W^{(4)*})\\ \text{s.t.} \qquad \,\,\, & \quad M^{(4)*} \succeq 0 \\ & \quad M^{(4)*} = \begin{bmatrix} 1 \qquad & \quad w^{\prime} \quad & \text{vec}(W^{(2)})^{\prime} L^{\prime}_{2} \\ w \qquad & \quad W^{(2)} \quad & \quad W^{(3)*\prime} & \\ L_{2}\text{vec}(W^{(2)}) &\quad W^{(3)*} \quad & \quad W^{(4)*} \\ \end{bmatrix} \\ & \quad W^{(2)} \in \mathbf{S}^{n}\\ & \quad W^{(4)*} \in \mathbf{S}^{n(n+1)/2} \\ & \quad Aw \leq b\\ \end{aligned}\end{split}\]

Where:

\(w\) are the weights of the portfolio.

\(W^{(2)}\) is a variable representing \(ww^{\prime}\).

\(W^{(3)*}\) is a variable representing \(L_{2}(w \otimes w)w^{\prime}\).

\(W^{(4)*}\) is a variable representing \(L_{2}(w \otimes w)(w \otimes w)^{\prime}L^{\prime}_{2}\).

\(L_{2}\): is the duplication elimination matrix defined in [A33].

\(D_{2}\): is the duplication matrix defined in [A33].

\(S_{2}\): is the duplication summation matrix defined in [A5].

\(M_{1}\): is the vector of expected returns.

\(\Sigma_{2}\): is the covariance matrix of asset returns.

\(M_{3}\): is the coskewness tensor of asset returns.

\(\Sigma_{4}\): is the cokurtosis matrix of asset returns.

\(\lambda_{i}\): is the risk aversion parameter for the \(i\)-th moment.

Module Methods

class Portfolio.Portfolio(returns=None, sht=False, uppersht=0.2, upperlng=1, lowerlng=0, budget=1, budgetsht=0.2, nea=None, card=None, factors=None, B=None, alpha=0.05, a_sim=100, beta=None, b_sim=None, kappa=0.3, kappa_g=None, n_max_kurt=50, kindbench=True, allowTO=False, turnover=0.05, allowTE=False, TE=0.05, benchindex=None, benchweights=None, ainequality=None, binequality=None, arcinequality=None, brcinequality=None, afrcinequality=None, bfrcinequality=None, aintinequality=None, bintinequality=None, cintinequality=None, dintinequality=None, eintinequality=None, fintinequality=None, b=None, network_sdp=None, cluster_sdp=None, network_ip=None, cluster_ip=None, graph_penalty=0.05, acentrality=None, bcentrality=None, lowerret=None, upperdev=None, lowerskew=None, upperkt=None, uppermad=None, uppergmd=None, uppersdev=None, upperskt=None, upperflpm=None, upperslpm=None, upperCVaR=None, uppertg=None, upperEVaR=None, upperRLVaR=None, upperwr=None, uppercvrg=None, uppertgrg=None, upperevrg=None, upperrvrg=None, upperrg=None, uppermdd=None, upperadd=None, upperCDaR=None, upperEDaR=None, upperRLDaR=None, upperuci=None, upperem=None, upperesm=None, p_1=2, p_2=3, p_3=4, p_4=10, p_5=50, p_em=2, p_esm=2)[source]

Class that creates a portfolio object with all properties needed to calculate optimal portfolios.

Parameters:
returns : DataFrame of shape (n_samples, n_assets), optional

Assets returns DataFrame, where n_samples is the number of observations and n_assets is the number of assets. The default is None.

sht : bool, optional

Indicate if the portfolio consider short positions (negative weights). The default is False.

uppersht : float, optional

Indicate the maximum absolute value of short positions (negative weights). The default is 0.2.

upperlng : float, optional

Indicate the maximum value of long positions (positive weights). The default is 1.

budget : float, optional

Indicate the maximum value of the sum of long positions (positive weights) and short positions (negative weights). The default is 1.

budgetsht : float, optional

Indicate the maximum value of the sum of absolute value of short positions (negative weights). The default is 0.2.

nea : int, optional

Indicate the minimum number of effective assets (NEA) used in portfolio. This value is the inverse of Herfindahl-Hirschman index of portfolio’s weights. The default is None.

card : int, optional

Indicate the maximum number of assets used in portfolio. It requires a solver that supports Mixed Integer Programs (MIP), see Solvers for more details. This constraint is based on [A34]. The default is None.

factors : DataFrame, optional

A dataframe that containts the returns of the factors. The default is None.

B : DataFrame of shape (n_assets, n_factors), optional

Loadings matrix, where n_assets is the number assets and n_factors is the number of risk factors. The default is None.

alpha : float, optional

Significance level of CVaR, EVaR, CDaR, EDaR and Tail Gini of losses. The default is 0.05.

a_sim : float, optional

Number of CVaRs used to approximate Tail Gini of losses. The default is 100.

beta : float, optional

Significance level of CVaR and Tail Gini of gains. If None it duplicates alpha value. The default is None.

b_sim : float, optional

Number of CVaRs used to approximate Tail Gini of gains. If None it duplicates a_sim value. The default is None.

kappa : float, optional

Deformation parameter of RLVaR and RLDaR, must be between 0 and 1. The default is 0.30.

kappa_g : float, optional

Deformation parameter of RLVaR of gains used in RLVaR Range, must be between 0 and 1. The default is None.

n_max_kurt : int, optional

Maximum number of assets to use Kurtosis model based on semidefinte formulation. If number of assets is higher than n_max_kurt, it uses relaxed kurtosis model based on second order cone. The default is 50.

kindbench : bool, optional

True if the benchmark is a portfolio with detailed weights and False if the benchmark is an index. The default is True.

allowTO : bool, optional

Indicate if there is turnover constraints. The default is False.

turnover : float, optional

The maximum limit of turnover deviations. The default is 0.05.

allowTE : bool, optional

Indicate if there is tracking error constraints.. The default is False.

TE : float, optional

The maximum limit of tracking error deviations. The default is 0.05.

benchindex : DataFrame, optional

A dataframe that containts the returns of an index. If kindbench is False the tracking error constraints are calculated respect to this index. The default is None.

benchweights : DataFrame, optional

A dataframe that containts the weights of an index. The default is the equally weighted portfolio 1/N.

ainequality : nd-array, optional

The matrix \(A\) of the linear constraint \(A \leq b\). The default is None.

binequality : 1d-array, optional

The matrix \(b\) of the linear constraint \(A \leq b\). The default is None.

arcinequality : nd-array, optional

The matrix \(A_{rc}\) of the linear constraint \(A_{rc} \text{diag}(\text{Tr}(\Sigma X)) \leq b_{rc} \text{Tr}(\Sigma X)\). The default is None.

brcinequality : 1d-array, optional

The matrix \(B_{rc}\) of the linear constraint \(A_{rc} \text{diag}(\text{Tr}(\Sigma X)) \leq b_{rc} \text{Tr}(\Sigma X)\). The default is None.

afrcinequality : nd-array, optional

The matrix \(A_{frc}\) of the linear constraint \(A_{frc} \text{diag}\left ( \bar{\Sigma} W_{\text{f}} \right) \leq b_{frc} \, \text{Tr} \left ( \bar{\Sigma} W_{\text{f}} \right )\). The default is None.

bfrcinequality : 1d-array, optional

The matrix \(b_{frc}\) of the linear constraint \(A_{frc} \text{diag}\left ( \bar{\Sigma} W_{\text{f}} \right) \leq b_{frc} \, \text{Tr} \left ( \bar{\Sigma} W_{\text{f}} \right )\). The default is None.

aintinequality : nd-array, optional

The matrix \(A_{int}\) of the linear integer constraint \(A_{int}k \leq B_{int}\). The default is None.

bintinequality : 1d-array, optional

The matrix \(B_{int}\) of the linear integer constraint \(A_{int}k \leq B_{int}\). The default is None.

cintinequality : nd-array, optional

The matrix \(C_{int}\) of the linear integer constraint \(C_{int}k \leq D_{int} \odot k_{s}\). The default is None.

dintinequality : 1d-array, optional

The matrix \(D_{int}\) of the linear integer constraint \(C_{int}k \leq D_{int} \odot k_{s}\). The default is None.

eintinequality : nd-array, optional

The matrix \(E_{int}\) of the linear integer constraint \(E_{int} k_{s}\leq F_{int}\). The default is None.

fintinequality : 1d-array, optional

The matrix \(F_{int}\) of the linear integer constraint \(E_{int} k_{s}\leq F_{int}\). The default is None.

b : 1d-array, optional

The risk budgeting constraint vector. The default is None.

network_sdp : nd-array, optional

Connection matrix for semidefinite programming (SDP) network constraint. Users cannot use network_sdp and network_ip at the same time, when a value is assigned to network_sdp automatically network_ip becomes None. This constraint is based on [A35] and [A36]. The default is None.

cluster_sdp : nd-array, optional

Adjacency label matrix for semidefinite programming (SDP) cluster constraint. Users cannot use cluster_sdp and cluster_ip at the same time, when a value is assigned to cluster_sdp automatically cluster_ip becomes None. This constraint is based on [A35] and [A36]. The default is None.

network_ip : nd-array, optional

Connection matrix for integer programming (IP) network constraint. Users cannot use network_sdp and network_ip at the same time, when a value is assigned to network_ip automatically network_sdp becomes None. This constraint is based on [A35] and [A36]. The default is None.

cluster_ip : nd-array, optional

Adjacency label matrix for integer programming (IP) cluster constraint. Users cannot use cluster_sdp and cluster_ip at the same time, when a value is assigned to cluster_ip automatically cluster_sdp becomes None. This constraint is based on [A35] and [A36]. The default is None.

graph_penalty : float, optional

The weight of SDP network constraint when the risk measure is not ‘MV’. This constraint is based on [A35] and [A36]. The default is 0.05.

acentrality : nd-array, optional

The matrix \(A_c\) of the centrality constraint \(A_c = B_c\). This constraint is based on [A35]. The default is None.

bcentrality : nd-array, optional

The matrix \(B_c\) of the centrality constraint \(A_c = B_c\). This constraint is based on [A35]. The default is None.

lowerret : float, optional

Constraint on min level of expected return. The default is None.

upperdev : float, optional

Constraint on max level of standard deviation. The default is None.

lowerskew : float, optional

Constraint on min level of skewness. The default is None.

upperkt : float, optional

Constraint on max level of square root kurtosis. The default is None.

uppermad : float, optional

Constraint on max level of MAD. The default is None.

uppergmd : float, optional

Constraint on max level of GMD. The default is None.

uppersdev : float, optional

Constraint on max level of semi standard deviation. The default is None.

upperskt : float, optional

Constraint on max level of square root semi kurtosis. The default is None.

upperflpm : float, optional

Constraint on max level of first lower partial moment. The default is None.

upperslpm : float, optional

Constraint on max level of second lower partial moment. The default is None.

upperCVaR : float, optional

Constraint on max level of conditional value at risk (CVaR). The default is None.

uppertg : float, optional

Constraint on max level of Tail Gini. The default is None.

upperEVaR : float, optional

Constraint on max level of entropic value at risk (EVaR). The default is None.

upperRLVaR : float, optional

Constraint on max level of relativistic value at risk (RLVaR). The default is None.

upperwr : float, optional

Constraint on max level of worst realization. The default is None.

upperrg : float, optional

Constraint on max level of range. The default is None.

uppercvrg : float, optional

Constraint on max level of CVaR range. The default is None.

uppertgrg : float, optional

Constraint on max level of Tail Gini range. The default is None.

upperevrg : float, optional

Constraint on max level of EVaR range. The default is None.

upperrvrg : float, optional

Constraint on max level of RLVaR range. The default is None.

uppermdd : float, optional

Constraint on max level of maximum drawdown of uncompounded cumulative returns. The default is None.

upperadd : float, optional

Constraint on max level of average drawdown of uncompounded cumulative returns. The default is None.

upperCDaR : float, optional

Constraint on max level of conditional drawdown at risk (CDaR) of uncompounded cumulative returns. The default is None.

upperEDaR : float, optional

Constraint on max level of entropic drawdown at risk (EDaR) of uncompounded cumulative returns. The default is None.

upperRLDaR : float, optional

Constraint on max level of relativistic drawdown at risk (RLDaR) of uncompounded cumulative returns. The default is None.

upperuci : float, optional

Constraint on max level of ulcer index (UCI) of uncompounded cumulative returns. The default is None.

p_1 : float, optional

First p-norm used to approximate GMD, TG and TGRG. The default is 2.

p_2 : float, optional

Second p-norm used to approximate GMD, TG and TGRG. The default is 3.

p_3 : float, optional

Third p-norm used to approximate GMD, TG and TGRG. The default is 4.

p_4 : float, optional

Fourth p-norm used to approximate GMD, TG and TGRG. The default is 10.

p_5 : float, optional

Fifth p-norm used to approximate GMD, TG and TGRG. The default is 50.

p_em : int, optional

Order of the Even Moment of order 2 * p_em. It must be an integer higher equal than 2. The default value is 2.

p_esm : int, optional

Order of the Even Semi Moment of order 2 * p_esm. It must be an integer higher equal than 2. The default value is 2.

assets_stats(method_mu='hist', method_cov='hist', method_kurt=None, dict_mu={}, dict_cov={}, dict_kurt={})[source]

Calculate the inputs that will be used by the optimization method when we select the input model=’Classic’.

Parameters:
method_mu : str, optional

The method used to estimate the expected returns. The default value is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’JS’: James-Stein estimator. For more information see [A37] and [A38].

  • ’BS’: Bayes-Stein estimator. For more information see [A39].

  • ’BOP’: BOP estimator. For more information see [A40].

method_cov : str, optional

The method used to estimate the covariance matrix. The default is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

  • ’oas’: use the Oracle Approximation Shrinkage method.

  • ’shrunk’: use the basic Shrunk Covariance method.

  • ’gl’: use the basic Graphical Lasso Covariance method.

  • ’jlogo’: use the j-LoGo Covariance method. For more information see: [A41].

  • ’fixed’: denoise using fixed method. For more information see chapter 2 of [A42].

  • ’spectral’: denoise using spectral method. For more information see chapter 2 of [A42].

  • ’shrink’: denoise using shrink method. For more information see chapter 2 of [A42].

  • ’gerber1’: use the Gerber statistic 1. For more information see: [A43].

  • ’gerber2’: use the Gerber statistic 2. For more information see: [A43].

method_kurt : str, optional

The method used to estimate the kurtosis square matrix: The default is None. Possible values are:

  • None: do not calculate kurtosis square matrix.

  • ’hist’: use historical estimates. For more information see [A5].

  • ’fixed’: denoise using fixed method. For more information see chapter 2 of [A42].

  • ’spectral’: denoise using spectral method. For more information see chapter 2 of [A42].

  • ’shrink’: denoise using shrink method. For more information see chapter 2 of [A42].

dict_mu : dict

Other variables related to the mean vector estimation method.

dict_cov : dict

Other variables related to the covariance estimation method.

dict_kurt : dict

Other variables related to the cokurtosis estimation method.

See also

riskfolio.src.ParamsEstimation.mean_vector, riskfolio.src.ParamsEstimation.covar_matrix, riskfolio.src.ParamsEstimation.cokurt_matrix

blacklitterman_stats(P, Q, rf=0, w=None, delta=None, eq=True, method_mu='hist', method_cov='hist', dict_mu={}, dict_cov={})[source]

Calculate the inputs that will be used by the optimization method when we select the input model=’BL’.

Parameters:
P : DataFrame of shape (n_views, n_assets)

Analyst’s views matrix, can be relative or absolute.

Q : DataFrame of shape (n_views, 1)

Expected returns of analyst’s views.

delta : float

Risk aversion factor. The default value is 1.

rf : scalar, optional

Risk free rate. The default is 0.

w : DataFrame of shape (n_assets, 1)

Weights matrix, where n_assets is the number of assets. The default is None.

eq : bool, optional

Indicates if use equilibrium or historical excess returns. The default is True.

method_mu : str, optional

The method used to estimate the expected returns. The default value is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’JS’: James-Stein estimator. For more information see [A37] and [A38].

  • ’BS’: Bayes-Stein estimator. For more information see [A39].

  • ’BOP’: BOP estimator. For more information see [A40].

method_cov : str, optional

The method used to estimate the covariance matrix. The default is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

  • ’oas’: use the Oracle Approximation Shrinkage method.

  • ’shrunk’: use the basic Shrunk Covariance method.

  • ’gl’: use the basic Graphical Lasso Covariance method.

  • ’jlogo’: use the j-LoGo Covariance method. For more information see: [A41].

  • ’fixed’: denoise using fixed method. For more information see chapter 2 of [A42].

  • ’spectral’: denoise using spectral method. For more information see chapter 2 of [A42].

  • ’shrink’: denoise using shrink method. For more information see chapter 2 of [A42].

  • ’gerber1’: use the Gerber statistic 1. For more information see: [A43].

  • ’gerber2’: use the Gerber statistic 2. For more information see: [A43].

dict_mu : dict

Other variables related to the mean vector estimation method.

dict_cov : dict

Other variables related to the covariance estimation method.

See also

riskfolio.src.ParamsEstimation.black_litterman

factors_stats(method_mu='hist', method_cov='hist', method_kurt='hist', B=None, const=True, higher_comoments=False, dict_load={}, dict_mu={}, dict_cov={}, dict_kurt={})[source]

Calculate the inputs that will be used by the optimization method when we select the input model=’FM’.

Parameters:
method_mu : str, optional

The method used to estimate the expected returns. The default value is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’JS’: James-Stein estimator. For more information see [A37] and [A38].

  • ’BS’: Bayes-Stein estimator. For more information see [A39].

  • ’BOP’: BOP estimator. For more information see [A40].

method_cov : str, optional

The method used to estimate the covariance matrix. The default is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

  • ’oas’: use the Oracle Approximation Shrinkage method.

  • ’shrunk’: use the basic Shrunk Covariance method.

  • ’gl’: use the basic Graphical Lasso Covariance method.

  • ’jlogo’: use the j-LoGo Covariance method. For more information see: [A41].

  • ’fixed’: denoise using fixed method. For more information see chapter 2 of [A42].

  • ’spectral’: denoise using spectral method. For more information see chapter 2 of [A42].

  • ’shrink’: denoise using shrink method. For more information see chapter 2 of [A42].

  • ’gerber1’: use the Gerber statistic 1. For more information see: [A43].

  • ’gerber2’: use the Gerber statistic 2. For more information see: [A43].

method_kurt : str, optional

The method used to estimate the cokurtosis square matrix: The default is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’semi’: use semi lower cokurtosis square matrix.

  • ’fixed’: denoise using fixed method. For more information see chapter 2 of [B1].

  • ’spectral’: denoise using spectral method. For more information see chapter 2 of [B1].

  • ’shrink’: denoise using shrink method. For more information see chapter 2 of [B1].

B : DataFrame of shape (n_assets, n_factors), optional

Loadings matrix, where the number of rows represent the assets and the columns the risk factors. If is not specified, is estimated using stepwise regression. The default is None.

const : bool, optional

Indicate if the loadings matrix has a constant. The default is False.

dict_load : dict

Other variables related to the loadings matrix estimation.

dict_mu : dict

Other variables related to the mean vector estimation method.

dict_cov : dict

Other variables related to the covariance estimation method.

dict_kurt : dict

Other variables related to the cokurtosis estimation.

See also

riskfolio.src.ParamsEstimation.forward_regression, riskfolio.src.ParamsEstimation.backward_regression, riskfolio.src.ParamsEstimation.loadings_matrix, riskfolio.src.ParamsEstimation.risk_factors

blfactors_stats(flavor='BLB', B=None, P=None, Q=None, P_f=None, Q_f=None, rf=0, w=None, delta=None, eq=True, const=True, method_mu='hist', method_cov='hist', dict_load={}, dict_mu={}, dict_cov={})[source]

Calculate the inputs that will be used by the optimization method when we select the input model=’BL’.

Parameters:
flavor : str

Model used, can be ‘BLB’ for Black Litterman Bayesian or ‘ABL’ for Augmented Black Litterman. The default value is ‘BLB’.

B : DataFrame of shape (n_assets, n_features)

Loadings matrix. The default value is None.

P : DataFrame of shape (n_views, n_assets)

Analyst’s views matrix, can be relative or absolute.

Q : DataFrame of shape (n_views, 1)

Expected returns of analyst’s views.

P_f : DataFrame of shape (n_views, n_assets)

Analyst’s factors views matrix, can be relative or absolute.

Q_f : DataFrame of shape (n_views, 1)

Expected returns of analyst’s factors views.

delta : float

Risk aversion factor. The default value is 1.

rf : scalar, optional

Risk free rate. The default is 0.

w : DataFrame of shape (n_assets, 1)

Weights matrix, where n_assets is the number of assets. The default is None.

eq : bool, optional

Indicates if use equilibrium or historical excess returns. The default is True.

const : bool, optional

Indicate if the loadings matrix has a constant. The default is False.

method_mu : str, optional

The method used to estimate the expected returns. The default value is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’JS’: James-Stein estimator. For more information see [A37] and [A38].

  • ’BS’: Bayes-Stein estimator. For more information see [A39].

  • ’BOP’: BOP estimator. For more information see [A40].

method_cov : str, optional

The method used to estimate the covariance matrix: The default is ‘hist’. Possible values are:

  • ’hist’: use historical estimates.

  • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

  • ’ewma2’: use ewma with adjust=False, see EWM for more details.

  • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

  • ’oas’: use the Oracle Approximation Shrinkage method.

  • ’shrunk’: use the basic Shrunk Covariance method.

  • ’gl’: use the basic Graphical Lasso Covariance method.

  • ’jlogo’: use the j-LoGo Covariance method. For more information see: [A41].

  • ’fixed’: denoise using fixed method. For more information see chapter 2 of [A42].

  • ’spectral’: denoise using spectral method. For more information see chapter 2 of [A42].

  • ’shrink’: denoise using shrink method. For more information see chapter 2 of [A42].

  • ’gerber1’: use the Gerber statistic 1. For more information see: [A43].

  • ’gerber2’: use the Gerber statistic 2. For more information see: [A43].

dict_load : dict

Other variables related to the loadings matrix estimation.

dict_mu : dict

Other variables related to the mean vector estimation method.

dict_cov : dict

Other variables related to the covariance estimation method.

See also

riskfolio.src.ParamsEstimation.augmented_black_litterman, riskfolio.src.ParamsEstimation.black_litterman_bayesian

entropy_pooling_stats(P_eq: array = None, Q_eq: array = None, P_in: array = None, Q_in: array = None, higher_comoments: bool = False, solver: str = 'CLARABEL')[source]

Estimate the optimal scenario weights and comoments parameters using the Entropy Pooling model. The Entropy Pooling model consist in solve the following optimization problem:

Parameters:
P_eq : np.array, optional

Matrix P of views that can be expressed as equality constraints.

Q_eq : np.array, optional

Matrix Q of views that can be expressed as equality constraints.

P_in : np.array, optional

Matrix P of views that can be expressed as inequality constraints.

Q_in : np.array, optional

Matrix Q of views that can be expressed as inequality constraints.

higher_comoments : bool, optional

If True calculate coskewness tensor and cokurtosis square matrix.

solver : str, optional

Solver used to solve the Entropy Pooling problem. The default value is ‘CLARABEL’.

See also

riskfolio.src.ParamsEstimation.entropy_pooling

wc_stats(box='s', ellip='s', q=0.05, n_sim=3000, window=3, diag=False, threshold=1e-15, dmu=0.1, dcov=0.1, method_k_mu='normal', method_k_sigma='normal', seed=0)[source]

Calculate the inputs that will be used by the wc_optimization method.

Parameters:
box : string

The method used to estimate the box uncertainty sets. The default is ‘s’. Possible values are:

  • ’s’: stationary bootstrapping method.

  • ’c’: circular bootstrapping method.

  • ’m’: moving bootstrapping method.

  • ’n’: assuming normal returns to calculate confidence levels.

  • ’d’: delta method, this method increase and decrease by a percentage.

ellip : string

The method used to estimate the elliptical uncertainty sets. The default is ‘s’. Possible values are:

  • ’s’: stationary bootstrapping method.

  • ’c’: circular bootstrapping method.

  • ’m’: moving bootstrapping method.

  • ’n’: assuming normal returns to calculate confidence levels.

q : scalar

Significance level of the selected bootstrapping method. The default is 0.05.

n_sim : scalar

Number of simulations of the bootstrapping method. The default is 3000.

window=3

Block size of the bootstrapping method. Must be greather than 1 and lower than the n_samples - n_features + 1 The default is 3.

diag : bool

If consider only the main diagonal of covariance matrices of estimation errors following [A28]. The default is False.

threshold : float

Parameter used to fix covariance matrices in case they are not positive semidefinite. The default is 1e-10.

dmu : scalar

Percentage used by delta method to increase and decrease the mean vector in box constraints. The default is 0.1.

dcov : scalar

Percentage used by delta method to increase and decrease the covariance matrix in box constraints. The default is 0.1.

method_k_mu : string or int or float

Method used to calculate the distance parameter of the elliptical uncertainty set of the mean. The default is ‘normal’. Possible values are:

  • ’normal’: assumes normal distribution of returns. Uses a bootstrapping method. [A44] and [A45] .

  • ’general’: for any possible distribution of returns. Uses the ratio √((1-q)/q). [A46] and [A47].

  • int or float value: we can use a custom distance parameter, that following lobo could be 1 or a near parameter. [A27].

method_k_sigma : string or int or float

Method used to calculate the distance parameter of the elliptical uncertainty set of the covariance matrix. The default is ‘normal’. Possible values are:

  • ’normal’: assumes normal distribution of returns. Uses a bootstrapping method. [A44] and [A45] .

  • ’general’: for any possible distribution of returns. Uses the ratio √((1-q)/q). [A46] and [A47].

  • int or float value: we can use a custom distance parameter, that following lobo could be 1 or a near parameter. [A27].

seed : int

Seed used to generate the boostrapping sample. The defailt is 0.

See also

riskfolio.src.ParamsEstimation.bootstrapping

optimization(model='Classic', rm='MV', obj='Sharpe', kelly=None, rf=0, l=2, hist=True)[source]

This method that calculates the optimal portfolio according to the optimization model selected by the user. The general problem that solves is:

\[\begin{split}\begin{align} \underset{w}{\text{optimize}} & \quad F(w)\\ \text{s. t.} & \quad Aw \leq b\\ & \quad A RC(w) \leq b \sigma^{2}(w)\\ & \quad \phi_{i}(w) \leq c_{i}\\ \end{align}\end{split}\]

Where:

\(F(w)\) is the objective function.

\(Aw \leq b\) is a set of linear constraints on asset weights.

\(A RC(w) \leq b \sigma^{2}(w)\) is a set of linear risk contribution constraints for variance.

\(\phi_{i}(w) \leq c_{i}\) are constraints on maximum values of several risk measures.

Parameters:
model : str can be {'Classic', 'BL', 'FM', 'BLFM', 'EP'}

The model used for optimize the portfolio. The default is ‘Classic’. Possible values are:

  • ’Classic’: use estimates of expected return vector and covariance matrix that depends on historical data.

  • ’BL’: use estimates of expected return vector and covariance matrix based on the Black Litterman model.

  • ’FM’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on a Risk Factor model specified by the user.

  • ’BLFM’: use estimates of expected return vector and covariance matrix based on Black Litterman applied to a Risk Factor model specified by the user.

  • ’EP’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on Entropy Pooling model.

rm : str, optional

The risk measure used to optimize the portfolio. The default is ‘MV’. Possible values are:

  • ’MV’: Standard Deviation.

  • ’KT’: Square Root of Kurtosis.

  • ’EM’: p_em Root of Even Moment of order 2 * p_em.

  • ’MAD’: Mean Absolute Deviation.

  • ’GMD’: Gini Mean Difference.

  • ’MSV’: Semi Standard Deviation.

  • ’SKT’: Square Root of Semi Kurtosis.

  • ’ESM’: p_esm Root of Even Semi Moment of order 2 * p_esm.

  • ’FLPM’: First Lower Partial Moment (Omega Ratio).

  • ’SLPM’: Second Lower Partial Moment (Sortino Ratio).

  • ’CVaR’: Conditional Value at Risk.

  • ’TG’: Tail Gini.

  • ’EVaR’: Entropic Value at Risk.

  • ’RLVaR’: Relativistic Value at Risk. I recommend only use this function with MOSEK solver.

  • ’WR’: Worst Realization (Minimax).

  • ’RG’: Range of returns.

  • ’CVRG’: CVaR range of returns.

  • ’TGRG’: Tail Gini range of returns.

  • ’EVRG’: EVaR range of returns.

  • ’RVRG’: RLVaR range of returns. I recommend only use this function with MOSEK solver.

  • ’MDD’: Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).

  • ’ADD’: Average Drawdown of uncompounded cumulative returns.

  • ’CDaR’: Conditional Drawdown at Risk of uncompounded cumulative returns.

  • ’EDaR’: Entropic Drawdown at Risk of uncompounded cumulative returns.

  • ’RLDaR’: Relativistic Drawdown at Risk of uncompounded cumulative returns. I recommend only use this function with MOSEK solver.

  • ’UCI’: Ulcer Index of uncompounded cumulative returns.

obj : str can be {'MinRisk', 'Utility', 'Sharpe' or 'MaxRet'}.

Objective function of the optimization model. The default is ‘Sharpe’. Possible values are:

  • ’MinRisk’: Minimize the selected risk measure.

  • ’Utility’: Maximize the Utility function \(\mu w - l \phi_{i}(w)\).

  • ’Sharpe’: Maximize the risk adjusted return ratio based on the selected risk measure.

  • ’MaxRet’: Maximize the expected return of the portfolio.

kelly : str, optional

Method used to calculate mean return. Possible values are: None for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is None.

rf : float, optional

Risk free rate, must be in the same period of assets returns. The default is 0.

l : scalar, optional

Risk aversion factor of the ‘Utility’ objective function. The default is 2.

hist : bool, optional

Indicate what kind of returns are used to calculate risk measures that depends on scenarios (All except ‘MV’ risk measure). If model = ‘BL’, True means historical covariance and returns and False Black Litterman covariance and historical returns. If model = ‘FM’, True means historical covariance and returns and False Risk Factor model for covariance and returns. If model = ‘BL_FM’, True means historical covariance and returns, False Black Litterman with Risk Factor model for covariance and Risk Factor model for returns, and ‘2’ Risk Factor model for covariance and returns. The default is True.

Returns:

optimal – The weights of optimal portfolio.

Return type:

DataFrame

rp_optimization(model='Classic', rm='MV', rf=0, b=None, b_f=None, hist=True)[source]

This method that calculates the risk parity portfolio using the risk budgeting approach [A24] [A25] and the risk parity with risk factors approach [A48] according to the optimization model selected by the user. The general problem that solves is:

\[\begin{split}\begin{aligned} &\underset{w}{\min} & & \phi(w)\\ &\text{s.t.} & & \mathbf{b}^{\prime} \log(w) \geq c\\ & & & \mu w \geq \overline{\mu} \\ & & & Aw \leq b \\ & & & w \geq 0 \\ \end{aligned}\end{split}\]

Where:

\(w\) are the weights of the portfolio.

\(\mu\): is the vector of expected returns.

\(\mathbf{b}\) is a vector of risk contribution targets.

\(Aw \leq b\): is a set of linear constraints on asset weights.

\(\phi(w)\): is a risk measure.

\(c\): is an arbitrary constant.

Parameters:
model : str can be 'Classic' or 'FM'

The model used for optimize the portfolio. The default is ‘Classic’. Possible values are:

  • ’Classic’: uses estimates of expected return vector and covariance matrix that depends on historical data.

  • ’FM’: uses estimates of expected return vector and covariance matrix based on a Risk Factor model specified by the user.

  • ’FC’: uses risk contributions based on risk factors.

rm : str, optional

The risk measure used to optimize the portfolio. The default is ‘MV’. Possible values are:

  • ’MV’: Standard Deviation.

  • ’KT’: Square Root of Kurtosis.

  • ’EM’: p_em Root of Even Moment of order 2 * p_em.

  • ’MAD’: Mean Absolute Deviation.

  • ’GMD’: Gini Mean Difference.

  • ’MSV’: Semi Standard Deviation.

  • ’SKT’: Square Root of Semi Kurtosis.

  • ’ESM’: p_esm Root of Even Semi Moment of order 2 * p_esm.

  • ’FLPM’: First Lower Partial Moment (Omega Ratio).

  • ’SLPM’: Second Lower Partial Moment (Sortino Ratio).

  • ’CVaR’: Conditional Value at Risk.

  • ’TG’: Tail Gini.

  • ’EVaR’: Entropic Value at Risk.

  • ’RLVaR’: Relativistic Value at Risk.

  • ’CVRG’: CVaR range of returns.

  • ’TGRG’: Tail Gini range of returns.

  • ’EVRG’: EVaR range of returns.

  • ’RVRG’: RLVaR range of returns.

  • ’CDaR’: Conditional Drawdown at Risk of uncompounded cumulative returns.

  • ’EDaR’: Entropic Drawdown at Risk of uncompounded cumulative returns.

  • ’RLDaR’: Relativistic Drawdown at Risk of uncompounded cumulative returns.

  • ’UCI’: Ulcer Index of uncompounded cumulative returns.

rf : float, optional

Risk free rate, must be in the same period of assets returns. Used for ‘FLPM’ and ‘SLPM’. The default is 0.

b : float, optional

The vector of risk constraints per asset. The default is 1/n (number of assets).

b_f : float, optional

The vector of risk constraints per risk factor. The default is 1/n_f (number of risk factors).

hist : bool, optional

Indicate what kind of returns are used to calculate risk measures that depends on scenarios (All except ‘MV’ risk measure). If model = ‘FM’, True means historical covariance and returns and False means Risk Factor model for covariance and returns. The default is True.

Returns:

rp_optimal – The weights of optimal portfolio.

Return type:

DataFrame

rrp_optimization(model='Classic', version='A', l=1, b=None, hist=True)[source]

This method that calculates the relaxed risk parity portfolio according to the optimization model and version selected by the user [A26]. The general problem that solves is:

\[\begin{split}\begin{aligned} \min_{w} & \quad \psi - \gamma \\ \text{s.t.} & \quad \zeta = \Sigma w \\ & \quad w^{T} \Sigma w \leq \left ( \psi^{2} - \rho^{2} \right ) \\ & \quad w_{i} \zeta_{i} \geq \gamma^{2} \mathbf{b}_{i} & \forall i=1 , \ldots , N \\ & \quad \lambda w^{T} \Theta w \leq \rho^{2} \\ & \quad \mu w \geq \overline{\mu} \\ & \quad Aw \leq b \\ & \quad \sum^{N}_{i=1} w_{i} = 1 \\ & \quad \psi, \gamma, \rho, w \geq 0 \\ \end{aligned}\end{split}\]

Where:

\(w\): is the vector of weights of the optimum portfolio.

\(\mu\): is the vector of expected returns.

\(\Sigma\): is the covariance matrix of assets returns.

\(\psi\): is the average risk of the portfolio.

\(\gamma\): is the lower bound of each asset risk constribution.

\(\mathbf{b}\): is the vector of risk constribution targets.

\(\zeta_{i}\): is the marginal risk of asset \(i\).

\(\rho\): is a regularization variable.

\(\lambda\): is a penalty parameter of \(\rho\).

\(\Theta = \text{diag}(\Sigma)\)

\(Aw \leq b\): is a set of linear constraints on asset weights.

Parameters:
model : str can be 'Classic' or 'FM'

The model used for optimize the portfolio. The default is ‘Classic’. Possible values are:

  • ’Classic’: use estimates of expected return vector and covariance matrix that depends on historical data.

  • ’FM’: use estimates of expected return vector and covariance matrix based on a Risk Factor model specified by the user.

version : str can be 'A', 'B' or 'C'

Relaxed risk parity model version proposed in [A25]. The default is ‘A’. Possible values are:

  • ’A’: without regularization and penalization constraints.

  • ’B’: with regularization constraint but without penalization constraint.

  • ’C’: with regularization and penalization constraints.

l : float, optional

The penalization factor of penalization constraints. Only used with version ‘C’. The default is 1.

b : float, optional

The vector of risk constraints per asset. The default is 1/n (number of assets).

hist : bool, optional

Indicate what kind of covariance matrix is used. If model = ‘FM’, True means historical covariance and False means Risk Factor model for covariance. The default is True.

Returns:

rrp_optimal – The weights of optimal portfolio.

Return type:

DataFrame

wc_optimization(obj='Sharpe', rf=0, l=2, Umu='box', Ucov='box')[source]

This method that calculates the worst case mean variance portfolio according to the objective function and uncertainty sets selected by the user.

Parameters:
obj : str can be {'MinRisk', 'Utility', 'Sharpe' or 'MaxRet'}.

Objective function of the optimization model. The default is ‘Sharpe’. Possible values are:

  • ’MinRisk’: Minimize the worst case formulation of the selected risk measure.

  • ’Utility’: Maximize the worst case formulation of the Utility function \(\mu w - l \phi_{i}(w)\).

  • ’Sharpe’: Maximize the worst case formulation of the risk adjusted return ratio based on the selected risk measure.

  • ’MaxRet’: Maximize the worst case formulation of the expected return of the portfolio.

rf : float, optional

Risk free rate, must be in the same period of assets returns. The default is 0.

l : scalar, optional

Risk aversion factor of the ‘Utility’ objective function. The default is 2.

Umu : str, optional

The type of uncertainty set for the mean vector used in the model. The default is ‘box’. Possible values are:

  • ’box’: Use a box uncertainty set for the mean vector.

  • ’ellip’: Use a elliptical uncertainty set for the mean vector.

  • None: Don’t use an uncertainty set for mean vector.

Ucov : str, optional

The type of uncertainty set for the covariance matrix used in the model. The default is ‘box’. Possible values are:

  • ’box’: Use a box uncertainty set for the covariance matrix.

  • ’ellip’: Use a elliptical uncertainty set for the covariance matrix.

  • None: Don’t use an uncertainty set for covariance matrix.

Returns:

wc_optimal – The weights of optimal portfolio.

Return type:

DataFrame

frc_optimization(model='Classic', obj='Sharpe', kelly=None, rf=0, l=2, hist=True)[source]

This method that calculates the risk parity portfolio using the risk budgeting approach [A3] according to the objective function selected by the user. The general problem that solves is:

\[\begin{split}\begin{aligned} \underset{w_{f}}{\text{optimize}} & \quad F(w)\\ \text{s.t.} & \quad \begin{bmatrix} W_{\text{f}} & w_{\text{f}} \\ w^{\prime}_{\text{f}} & 1 \end{bmatrix} \succeq 0 \\ & \quad A w \leq b \\ & \quad w = (B^{\prime})^{+} w_{\text{f}} \\ & \quad A_{\text{frc}} \text{diag}\left ( \bar{\Sigma} W_{\text{f}} \right) \leq b_{\text{frc}} \, \text{Tr} \left ( \bar{\Sigma} W_{\text{f}} \right ) \\ & \quad W_{\text{f}} \in \mathbf{S}^{n}\\ \end{aligned}\end{split}\]

Where:

\(w_f\) are the weights of the risk factors.

\(W_f\): is the symmetric matrix variable that approximates \(w_f w^{\prime}_f\).

\(B\) is the loadings matrix.

\(Aw \leq b\): is a set of linear constraints on asset weights.

\(\bar{\Sigma} = \left ((B^{\prime})^{+} \right )^{\prime} \Sigma (B^{\prime})^{+} $, $X_{\text{f}}\).

\(A_{\text{frc}} \text{diag}\left ( \bar{\Sigma} W_{\text{f}} \right) \leq b_{\text{frc}} \, \text{Tr} \left ( \bar{\Sigma} W_{\text{f}} \right )\): is a set of linear factor risk contribution constraints.

Parameters:
model : str can be 'Classic' or 'FM'

The model used for optimize the portfolio. The default is ‘Classic’. Possible values are:

  • ’Classic’: uses estimates of expected return vector and covariance matrix that depends on historical data.

  • ’FM’: uses estimates of expected return vector and covariance matrix based on a Risk Factor model specified by the user.

obj : str can be {'MinRisk', 'Utility', 'Sharpe' or 'MaxRet'}.

Objective function of the optimization model. The default is ‘Sharpe’. Possible values are:

  • ’MinRisk’: Minimize the selected risk measure.

  • ’Utility’: Maximize the Utility function \(\mu w - l \phi_{i}(w)\).

  • ’Sharpe’: Maximize the risk adjusted return ratio based on the selected risk measure.

  • ’MaxRet’: Maximize the expected return of the portfolio.

kelly : str, optional

Method used to calculate mean return. Possible values are: None for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is None.

rf : float, optional

Risk free rate, must be in the same period of assets returns. The default is 0.

l : scalar, optional

Risk aversion factor of the ‘Utility’ objective function. The default is 2.

hist : bool, optional

Indicate what kind of returns are used to calculate risk measures that depends on scenarios (All except ‘MV’ risk measure). If model = ‘FM’, True means historical covariance and returns and False means Risk Factor model for covariance and returns. The default is True.

Returns:

frc_optimal – The weights of optimal portfolio.

Return type:

DataFrame

owa_optimization(obj='Sharpe', owa_w=None, kelly=None, rf=0, l=2)[source]

This method that calculates the owa optimal portfolio according to the weight vector given by the user. The general problem that solves is:

\[\begin{split}\begin{align} &\underset{w}{\text{optimize}} & & F(w)\\ &\text{s. t.} & & Aw \leq b\\ \end{align}\end{split}\]

Where:

\(F(w)\) is the objective function based on an owa risk measure.

\(Aw \leq b\) is a set of linear constraints on asset weights.

Parameters:
obj : str can be {'MinRisk', 'Utility', 'Sharpe' or 'MaxRet'}.

Objective function of the optimization model. The default is ‘Sharpe’. Possible values are:

  • ’MinRisk’: Minimize the selected risk measure.

  • ’Utility’: Maximize the Utility function \(\mu w - l \phi_{i}(w)\).

  • ’Sharpe’: Maximize the risk adjusted return ratio based on the selected risk measure.

  • ’MaxRet’: Maximize the expected return of the portfolio.

owa_w : 1darray, optional

The owa weight used to define the owa risk measure. The default is ‘MV’. Possible values are:

kelly : str, optional

Method used to calculate mean return. Possible values are: None for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is None.

rf : float, optional

Risk free rate, must be in the same period of assets returns. The default is 0.

l : scalar, optional

Risk aversion factor of the ‘Utility’ objective function. The default is 2.

Returns:

owa_optimal – The weights of optimal portfolio.

Return type:

DataFrame

mvsk_optimization(model='Classic', obj='Sharpe', rf=0, l=[2, 3, 4], solvers=['SCS'])[source]

This method that calculates the MVSK portfolio using a semidefinite relaxation of higher moments. The general problem that solves is:

\[\begin{split}\begin{align} \underset{w}{\text{optimize}} & \quad F(w)\\ \text{s. t.} & \quad Aw \leq b\\ \end{align}\end{split}\]

Where:

\(F(w)\) is a function based on the first fourth portfolio moments.

\(Aw \leq b\) is a set of linear constraints on asset weights.

Parameters:
model : str can be {'Classic', 'FM', 'EP'}

The model used for optimize the portfolio. The default is ‘Classic’. Possible values are:

  • ’Classic’: use estimates of expected return vector and covariance matrix that depends on historical data.

  • ’FM’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on a Risk Factor model specified by the user.

  • ’EP’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on Entropy Pooling model.

obj : str can be {'MinRisk', 'Utility', 'Sharpe' or 'MaxRet'}.

Objective function of the optimization model. The default is ‘Sharpe’. Possible values are:

  • ’MinRisk’: Minimize the risk function based on portfolio variance, skewness and kurtosis.

  • ’Utility’: Maximize the Utility function based on the first fourth portfolio moments.

  • ’Sharpe’: Maximize the risk adjusted return ratio based on portfolio variance, skewness and kurtosis.

  • ’MaxRet’: Maximize the expected return of the portfolio.

rf : float, optional

Risk free rate, must be in the same period of assets returns. The default is 0.

l : list, optional

List with the risk aversion factors of the portfolio variance, skewness and kurtosis. The default is ‘[2, 3, 4]’.

solvers : list, optional

List of solvers used to solve the MVSK problem. It is recommended to use solvers that supports first-order algorithms such as ‘SCS’ because the problem is hard and it consumes a lot of resources. The default value is’SCS’.

Returns:

mvsk_optimal – The weights of optimal MVSK portfolio.

Return type:

DataFrame

frontier_limits(model='Classic', rm='MV', kelly=None, rf=0, hist=True)[source]

Method that calculates the minimum risk and maximum return portfolios available with current assets and constraints.

Parameters:
model : str can be {'Classic', 'BL', 'FM', 'BLFM', 'EP'}

The model used for optimize the portfolio. The default is ‘Classic’. Possible values are:

  • ’Classic’: use estimates of expected return vector and covariance matrix that depends on historical data.

  • ’BL’: use estimates of expected return vector and covariance matrix based on the Black Litterman model.

  • ’FM’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on a Risk Factor model specified by the user.

  • ’BLFM’: use estimates of expected return vector and covariance matrix based on Black Litterman applied to a Risk Factor model specified by the user.

  • ’EP’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on Entropy Pooling model.

rm : str, optional

The risk measure used to optimize the portfolio. The default is ‘MV’. Possible values are:

  • ’MV’: Standard Deviation.

  • ’KT’: Square Root of Kurtosis.

  • ’EM’: p_em Root of Even Moment of order 2 * p_em.

  • ’MAD’: Mean Absolute Deviation.

  • ’GMD’: Gini Mean Difference.

  • ’MSV’: Semi Standard Deviation.

  • ’SKT’: Square Root of Semi Kurtosis.

  • ’ESM’: p_esm Root of Even Semi Moment of order 2 * p_esm.

  • ’FLPM’: First Lower Partial Moment (Omega Ratio).

  • ’SLPM’: Second Lower Partial Moment (Sortino Ratio).

  • ’CVaR’: Conditional Value at Risk.

  • ’TG’: Tail Gini.

  • ’EVaR’: Entropic Value at Risk.

  • ’RLVaR’: Relativistic Value at Risk.

  • ’WR’: Worst Realization (Minimax).

  • ’RG’: Range of returns.

  • ’CVRG’: CVaR range of returns.

  • ’TGRG’: Tail Gini range of returns.

  • ’EVRG’: EVaR range of returns.

  • ’RVRG’: RLVaR range of returns. I recommend only use this function with MOSEK solver.

  • ’MDD’: Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).

  • ’ADD’: Average Drawdown of uncompounded cumulative returns.

  • ’CDaR’: Conditional Drawdown at Risk of uncompounded cumulative returns.

  • ’EDaR’: Entropic Drawdown at Risk of uncompounded cumulative returns.

  • ’RLDaR’: Relativistic Drawdown at Risk of uncompounded cumulative returns. I recommend only use this function with MOSEK solver.

  • ’UCI’: Ulcer Index of uncompounded cumulative returns.

kelly : str, optional

Method used to calculate mean return. Possible values are: None for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is None.

rf : scalar, optional

Risk free rate. The default is 0.

hist : bool, optional

Indicate what kind of returns are used to calculate risk measures that depends on scenarios (All except ‘MV’ risk measure). If model = ‘BL’, True means historical covariance and returns and False Black Litterman covariance and historical returns. If model = ‘FM’, True means historical covariance and returns and False Risk Factor model for covariance and returns. If model = ‘BL_FM’, True means historical covariance and returns, False Black Litterman with Risk Factor model for covariance and Risk Factor model for returns, and ‘2’ Risk Factor model for covariance and returns. The default is True.

Returns:

limits – A dataframe that containts the weights of the portfolios.

Return type:

DataFrame

Notes

This method is preferable (faster) to use instead of efficient_frontier method to know the range of expected return and expected risk.

efficient_frontier(model='Classic', rm='MV', kelly=None, points=20, rf=0, solver='CLARABEL', hist=True)[source]

Method that calculates several portfolios in the efficient frontier of the selected risk measure, available with current assets and constraints.

Parameters:
model : str can be {'Classic', 'BL', 'FM', 'BLFM', 'EP'}

The model used for optimize the portfolio. The default is ‘Classic’. Possible values are:

  • ’Classic’: use estimates of expected return vector and covariance matrix that depends on historical data.

  • ’BL’: use estimates of expected return vector and covariance matrix based on the Black Litterman model.

  • ’FM’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on a Risk Factor model specified by the user.

  • ’BLFM’: use estimates of expected return vector and covariance matrix based on Black Litterman applied to a Risk Factor model specified by the user.

  • ’EP’: use estimates of expected return vector, covariance matrix and cokurtosis square matrix based on Entropy Pooling model.

rm : str, optional

The risk measure used to optimize the portfolio. The default is ‘MV’. Possible values are:

  • ’MV’: Standard Deviation.

  • ’KT’: Square Root of Kurtosis.

  • ’EM’: p_em Root of Even Moment of order 2 * p_em.

  • ’MAD’: Mean Absolute Deviation.

  • ’GMD’: Gini Mean Difference.

  • ’MSV’: Semi Standard Deviation.

  • ’SKT’: Square Root of Semi Kurtosis.

  • ’ESM’: p_esm Root of Even Semi Moment of order 2 * p_esm.

  • ’FLPM’: First Lower Partial Moment (Omega Ratio).

  • ’SLPM’: Second Lower Partial Moment (Sortino Ratio).

  • ’CVaR’: Conditional Value at Risk.

  • ’TG’: Tail Gini.

  • ’EVaR’: Entropic Value at Risk.

  • ’RLVaR’: Relativistic Value at Risk.

  • ’WR’: Worst Realization (Minimax).

  • ’RG’: Range of returns.

  • ’CVRG’: CVaR range of returns.

  • ’TGRG’: Tail Gini range of returns.

  • ’EVRG’: EVaR range of returns.

  • ’RVRG’: RLVaR range of returns. I recommend only use this function with MOSEK solver.

  • ’MDD’: Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).

  • ’ADD’: Average Drawdown of uncompounded cumulative returns.

  • ’CDaR’: Conditional Drawdown at Risk of uncompounded cumulative returns.

  • ’EDaR’: Entropic Drawdown at Risk of uncompounded cumulative returns.

  • ’RLDaR’: Relativistic Drawdown at Risk of uncompounded cumulative returns. I recommend only use this function with MOSEK solver.

  • ’UCI’: Ulcer Index of uncompounded cumulative returns.

kelly : str, optional

Method used to calculate mean return. Possible values are: None for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is None.

points : scalar, optional

Number of point calculated from the efficient frontier. The default is 50.

rf : scalar, optional

Risk free rate. The default is 0.

solver : str, optional

Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is ‘CLARABEL’.

hist : bool, optional

Indicate what kind of returns are used to calculate risk measures that depends on scenarios (All except ‘MV’ risk measure). If model = ‘BL’, True means historical covariance and returns and False Black Litterman covariance and historical returns. If model = ‘FM’, True means historical covariance and returns and False Risk Factor model for covariance and returns. If model = ‘BL_FM’, True means historical covariance and returns, False Black Litterman with Risk Factor model for covariance and Risk Factor model for returns, and ‘2’ Risk Factor model for covariance and returns. The default is True.

Returns:

frontier – A dataframe that containts the weights of the portfolios.

Return type:

DataFrame

Notes

It’s recommendable that don’t use this method when there are too many assets (more than 100) and you are using a scenario based risk measure (all except standard deviation). It’s preferable to use frontier_limits method (faster) to know the range of expected return and expected risk.

reset_risk_constraints()[source]

Reset all risk constraints.

reset_linear_constraints()[source]

Reset all linear constraints.

reset_inputs()[source]

Reset all inputs parameters of optimization models.

reset_all()[source]

Reset portfolio object to defatult values.

Bibliography

[A1] (1,2)

Edward Thorp. The kelly criterion in blackjack, sports betting, and the stock market. Handbook of Asset and Liability Management, 1:, 12 2008. doi:10.1016/B978-044453248-0.50015-0.

[A2] (1,2)

Dany Cajas. Kelly portfolio optimization: a disciplined convex programming framework. SSRN Electronic Journal, 2021. URL: https://doi.org/10.2139/ssrn.3833617, doi:10.2139/ssrn.3833617.

[A3] (1,2,3)

Dany Cajas. A semidefinite programming approach to risk parity portfolio optimization. SSRN Electronic Journal, 2025. URL: http://dx.doi.org/10.2139/ssrn.5097869, doi:10.2139/ssrn.5097869.

[A4] (1,2)

Harry Markowitz. Portfolio selection. The Journal of Finance, 7(1):77–91, 1952. URL: http://www.jstor.org/stable/2975974.

[A5] (1,2,3,4,5,6)

Dany Cajas. Convex optimization of portfolio kurtosis. SSRN Electronic Journal, 2022. URL: https://doi.org/10.2139/ssrn.4202967, doi:10.2139/ssrn.4202967.

[A6] (1,2,3,4)

Dany Cajas. Approximation of portfolio kurtosis through sum of squared quadratic forms. SSRN Electronic Journal, 6 2023. doi:10.2139/ssrn.4472793.

[A7] (1,2)

Dany Cajas. Portfolio optimization of even moments using power cone programming. SSRN Electronic Journal, 2026. URL: http://dx.doi.org/10.2139/ssrn.6518258, doi:10.2139/ssrn.6518258.

[A8] (1,2)

Hiroshi Konno and Hiroaki Yamazaki. Mean-absolute deviation portfolio optimization model and its applications to tokyo stock market. Management Science, 37(5):519–531, 1991. URL: https://EconPapers.repec.org/RePEc:inm:ormnsc:v:37:y:1991:i:5:p:519-531.

[A9] (1,2)

Shlomo Yitzhaki. Stochastic dominance, mean variance, and gini's mean difference. American Economic Review, 72:178–85, 01 1982.

[A10] (1,2,3,4,5,6,7,8,9,10)

Dany Cajas. Owa portfolio optimization: a disciplined convex programming framework. SSRN Electronic Journal, 2021. URL: https://doi.org/10.2139/ssrn.3988927, doi:10.2139/ssrn.3988927.

[A11] (1,2,3,4)

Dany Cajas. Efficient gini mean difference and tail gini portfolio optimization based on p-norms. SSRN Electronic Journal, 2024. URL: http://dx.doi.org/10.2139/ssrn.4711326, doi:10.2139/ssrn.4711326.

[A12] (1,2,3,4,5,6,7)

Dany Cajas. Advanced portfolio optimization. Springer International Publishing, Cham, Switzerland, April 2025.

[A13] (1,2)

Renata Mansini, W. Ogryczak, and M.Grazia Speranza. Twenty years of linear programming based portfolio optimization. European Journal of Operational Research, 234:518–535, 04 2014. doi:10.1016/j.ejor.2013.08.035.

[A14] (1,2,3,4)

Renata Mansini, W. Ogryczak, and M.Grazia Speranza. Linear Models for Portfolio Optimization, pages 19–45. Springer, 01 2015. doi:10.1007/978-3-319-18482-1_2.

[A15] (1,2)

R. Tyrrell Rockafellar and Stanislav Uryasev. Optimization of conditional value-at-risk. Journal of Risk, 2:21–41, 2000.

[A16] (1,2)

W. Ogryczak and Andrzej Ruszczynskia. Dual stochastic dominance and quantile risk measures. International Transactions in Operational Research, 9:661–680, 09 2002. doi:10.1111/1475-3995.00380.

[A17] (1,2)

Amir Ahmadi Javid. Entropic value-at-risk: a new coherent risk measure. Journal of Optimization Theory and Applications, 12 2012. doi:10.1007/s10957-011-9968-2.

[A18] (1,2)

Amir Ahmadi Javid and Malihe Fallah. Portfolio optimization with entropic value-at-risk. European Journal of Operational Research, 08 2017. doi:10.1016/j.ejor.2019.02.007.

[A19] (1,2,3,4)

Dany Cajas. Entropic portfolio optimization: a disciplined convex programming framework. SSRN Electronic Journal, 2021. URL: https://doi.org/10.2139/ssrn.3792520, doi:10.2139/ssrn.3792520.

[A20] (1,2,3,4)

Dany Cajas. Portfolio optimization of relativistic value at risk. SSRN Electronic Journal, 2023. URL: https://doi.org/10.2139/ssrn.4378498, doi:10.2139/ssrn.4378498.

[A21]

Renata Mansini, W. Ogryczak, and M.Grazia Speranza. On lp solvable models for portfolio selection. Informatica, 14:37–62, 01 2003.

[A22] (1,2,3,4)

A. Chekhlov, S. Uryasev, and M. Zabarankin. Portfolio optimization with drawdown constraints. In Panos M Pardalos, Athanasios Migdalas, and George Baourakis, editors, Supply Chain And Finance, volume of World Scientific Book Chapters, chapter 13, pages 209–228. World Scientific Publishing Co. Pte. Ltd., edition, November 2004. URL: https://ideas.repec.org/h/wsi/wschap/9789812562586_0013.html.

[A23] (1,2)

Peter Martin. The investor's guide to fidelity funds. Wiley, New York, 1989. ISBN 978-0471622581.

[A24] (1,2)

Benjamin Bruder and Thierry Roncalli. Managing risk exposures using the risk budgeting approach. SSRN Electronic Journal, pages, 01 2012. doi:10.2139/ssrn.2009778.

[A25] (1,2,3)

Jean-Charles Richard and Thierry Roncalli. Constrained Risk Budgeting Portfolios: Theory, Algorithms, Applications & Puzzles. Papers 1902.05710, arXiv.org, February 2019. URL: https://ideas.repec.org/p/arx/papers/1902.05710.html.

[A26] (1,2)

Vaughn Gambeta and Roy Kwon. Risk return trade-off in relaxed risk parity portfolio optimization. Journal of Risk and Financial Management, 2020. URL: https://www.mdpi.com/1911-8074/13/10/237, doi:10.3390/jrfm13100237.

[A27] (1,2,3)

Miguel Sousa Lobo and Stephen Boyd. The worst-case risk of a portfolio. 10 2000.

[A28] (1,2)

Frank Fabozzi. Robust portfolio optimization and management. John Wiley, Hoboken, N.J, 2007. ISBN 978-0-471-92122-6.

[A29]

R.H. Tütüncü and M. Koenig. Robust asset allocation. Annals of Operations Research, 132:157–187, 01 2004. doi:10.1023/B:ANOR.0000045281.41041.ed.

[A30]

Daniel Palomar. Robust optimization with applications. URL: https://palomar.home.ece.ust.hk/ELEC5470_lectures/slides_robust_optim.pdf.

[A31]

Dany Cajas. Higher order moment portfolio optimization with l-moments. SSRN Electronic Journal, 2023. URL: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4393155, doi:10.2139/ssrn.4393155.

[A32]

Dany Cajas. Semidefinite relaxation of higher portfolio moments. SSRN Electronic Journal, 2025. URL: http://dx.doi.org/10.2139/ssrn.5284483, doi:10.2139/ssrn.5284483.

[A33] (1,2)

Jan R. Magnus and H. Neudecker. The elimination matrix: some lemmas and applications. SIAM Journal on Algebraic Discrete Methods, 1(4):422–449, 1980. URL: https://doi.org/10.1137/0601049, arXiv:https://doi.org/10.1137/0601049, doi:10.1137/0601049.

[A34]

Dajun Yue and Fengqi You. Reformulation-linearization method for global optimization of mixed integer linear fractional programming problems with application on sustainable batch scheduling. In Jiří Jaromír Klemeš, Petar Sabev Varbanov, and Peng Yen Liew, editors, 24th European Symposium on Computer Aided Process Engineering, volume 33 of Computer Aided Chemical Engineering, pages 949–954. Elsevier, 2014. URL: https://www.sciencedirect.com/science/article/pii/B9780444634566501599, doi:https://doi.org/10.1016/B978-0-444-63456-6.50159-9.

[A35] (1,2,3,4,5,6,7)

Dany Cajas. A graph theory approach to portfolio optimization. SSRN Electronic Journal, 10 2023. doi:10.2139/ssrn.4602019.

[A36] (1,2,3,4,5)

Dany Cajas. A graph theory approach to portfolio optimization part ii. SSRN Electronic Journal, 12 2023. doi:10.2139/ssrn.4540021.

[A37] (1,2,3,4)

Attilio Meucci. Risk and Asset Allocation. Springer Berlin Heidelberg, 2005. URL: https://doi.org/10.1007/978-3-540-27904-4, doi:10.1007/978-3-540-27904-4.

[A38] (1,2,3,4)

Yiyong Feng and Daniel P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends® in Signal Processing, 9(1-2):1–231, 2016. URL: https://doi.org/10.1561/2000000072, doi:10.1561/2000000072.

[A39] (1,2,3,4)

Philippe Jorion. Bayes-stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis, 21(3):279, September 1986. URL: https://doi.org/10.2307/2331042, doi:10.2307/2331042.

[A40] (1,2,3,4)

Taras Bodnar, Ostap Okhrin, and Nestor Parolya. Optimal shrinkage estimator for high-dimensional mean vector. Journal of Multivariate Analysis, 170:63–79, 03 2019. URL: https://doi.org/10.1016\%2Fj.jmva.2018.07.004, doi:10.1016/j.jmva.2018.07.004.

[A41] (1,2,3,4)

Wolfram Barfuss, Guido Previde Massara, T. Di Matteo, and Tomaso Aste. Parsimonious modeling with information filtering networks. Physical Review E, 12 2016. URL: http://dx.doi.org/10.1103/PhysRevE.94.062306, doi:10.1103/physreve.94.062306.

[A42] (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)

Marcos M. López de Prado. Machine Learning for Asset Managers. Elements in Quantitative Finance. Cambridge University Press, 2020. doi:10.1017/9781108883658.

[A43] (1,2,3,4,5,6,7,8)

Sander Gerber, Harry Markowitz, Philip Ernst, Yinsen Miao, Babak Javid, and Paul Sargen. The gerber statistic: a robust co-movement measure for portfolio optimization. SSRN Electronic Journal, 2021. URL: https://doi.org/10.2139/ssrn.3880054, doi:10.2139/ssrn.3880054.

[A44] (1,2)

Mingyu Yang. Uncertainty set sizes, sensitivity analysis, in robust portfolio optimization. Master's thesis, University of Waterloo, 2019. URL: https://www.math.uwaterloo.ca/~hwolkowi/henry/reports/MingyuYangCM-eresearchpaper-printcopy.pdf.

[A45] (1,2)

Reha H. Tütüncü and Matthias Koenig. Robust asset allocation. Annals of Operations Research, 132:157–187, 2004. URL: https://api.semanticscholar.org/CorpusID:2669348.

[A46] (1,2)

Frank J Fabozzi, Petter N Kolm, Dessislava A Pachamanova, and Sergio M Focardi. Robust Portfolio Optimization and Management. John Wiley & Sons, Nashville, TN, 05 2007.

[A47] (1,2)

Laurent El Ghaoui, Maksim Oks, and Francois Oustry. Worst-case value-at-risk and robust portfolio optimization: a conic programming approach. Oper. Res., 51(4):543–556, 2003.

[A48]

Thierry Roncalli and Guillaume Weisang. Risk parity portfolios with risk factors. SSRN Electronic Journal, 09 2012. doi:10.2139/ssrn.2155159.