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

Some Theory

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} &\underset{w}{\max} & & R (w)\\ &\text{s.t.} & & Aw \geq B\\ & & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\ & & & R (w) \geq \overline{\mu} \end{aligned}\end{split}\]
  • Minimum Risk Portfolio:

\[\begin{split}\begin{aligned} &\underset{w}{\min} & & \phi_{k}(w)\\ &\text{s.t.} & & Aw \geq B\\ & & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\ & & & R (w) \geq \overline{\mu} \end{aligned}\end{split}\]
  • Maximum Risk Adjusted Return Ratio Portfolio:

\[\begin{split}\begin{aligned} &\underset{w}{\max} & & \frac{R (w) - r_{f}}{\phi_{k}(w)}\\ &\text{s.t.} & & Aw \geq B\\ & & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\ & & & R (w) \geq \overline{\mu} \end{aligned}\end{split}\]
  • Maximum Utility Portfolio:

\[\begin{split}\begin{aligned} &\underset{w}{\max} & & R (w) - \lambda \phi_{k}(w)\\ &\text{s.t.} & & Aw \geq B\\ & & &\phi_{i}(w) \leq c_{i} \; \forall \; i \; \in \; [1,13] \\ & & & R (w) \geq \overline{\mu} \end{aligned}\end{split}\]

Where:

\(R (w)\) is the return function, posible 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.

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

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

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

\(Aw \geq B\): is a set of linear constraints.

\(\phi_{i}(w)\): are 20 available risk measures. The available risk measures are:

  • Standard Deviation [A3].

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

  • Mean Absolute Deviation [A6].

  • Gini Mean Difference [A7], [A8].

  • Conditional Value at Risk Range [A8].

  • Tail Gini Range [A8].

  • Semi Standard Deviation [A9].

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

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

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

  • Conditional Value at Risk [A11].

  • Tail Gini [A12], [A8].

  • Entropic Value at Risk [A13], [A14], [A15].

  • Relativistic Value at Risk [A16].

  • Worst Realization (Minimax) [A17].

  • Average Drawdown of uncompounded cumulative returns [A18].

  • Ulcer Index of uncompounded cumulative returns [A19].

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

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

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

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

\(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 [A20] [A21]:

\[\begin{split}\begin{aligned} &\underset{w}{\min} & & \phi(w) \\ &\text{s.t.} & & b \log(w) \geq c \\ & & & \mu w \geq \overline{\mu} \\ & & & Aw \geq B \\ & & & 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.

\(b\): is a vector of risk contribution constraints.

\(Aw \geq B\): is a set of linear constraints.

\(\phi(w)\): are 16 available risk measures. The available risk measures are:

  • Standard Deviation [A3].

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

  • Mean Absolute Deviation [A6].

  • Gini Mean Difference [A7], [A8].

  • Conditional Value at Risk Range [A8].

  • Tail Gini Range [A8].

  • Semi Standard Deviation [A9].

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

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

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

  • Conditional Value at Risk [A11].

  • Tail Gini [A12], [A8].

  • Entropic Value at Risk [A13], [A14], [A15].

  • Relativistic Value at Risk [A16].

  • Ulcer Index of uncompounded cumulative returns [A19].

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

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

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

\(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 [A22]:

\[\begin{split}\begin{aligned} &\underset{w}{\min} & & \psi - \gamma & \\ &\text{s.t.} & & \zeta = \Sigma w \\ & & & w^{T} \Sigma w \leq \left ( \psi^{2} - \rho^{2} \right ) & \\ & & & w_{i} \zeta_{i} \geq \gamma^{2} b_{i} & \forall i=1 , \ldots , N \\ & & & \lambda x^{T} \Theta x \leq \rho^{2} & \\ & & & \mu w \geq \overline{\mu} & \\ & & & Aw \geq B & \\ & & & \sum^{N}_{i=1} w_{i} = 1 & \\ & & & \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.

\(b\): is the risk contribution vector constraint.

\(\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 \geq B\): is a set of linear constraints.

Worst Case Mean Variance Portfolio Optimization

Riskfolio-Lib allows to calculate worst case mean variance optimum portfolios [A23] [A24] [A25] [A26] that results from optimize one of the following 4 objective functions:

  • Worst Case Maximum Return Portfolio:

\[\begin{split}\begin{aligned} &\underset{w}{\max} & & \underset{\mu \, \in \, U_{\mu}}{\min} \mu w\\ &\text{s.t.} & & Aw \geq B\\ \end{aligned}\end{split}\]
  • Worst Case Minimum Risk Portfolio:

\[\begin{split}\begin{aligned} &\underset{w}{\min} & & \underset{\Sigma \, \in \, U_{\Sigma}}{\max} w^{T} \Sigma w\\ &\text{s.t.} & & Aw \geq B\\ \end{aligned}\end{split}\]
  • Worst Case Maximum Risk Adjusted Return Ratio Portfolio:

\[\begin{split}\begin{aligned} &\underset{w}{\max} & & \cfrac{\underset{\mu \, \in \, U_{\mu}}{\min} \mu w - r_{f}} {\underset{\Sigma \, \in \, U_{\Sigma}}{\max} \sqrt{w^{T} \Sigma w}}\\ &\text{s.t.} & & Aw \geq B\\ \end{aligned}\end{split}\]
  • Worst Case Maximum Utility Portfolio:

\[\begin{split}\begin{aligned} &\underset{w}{\max} & & \underset{\mu \, \in \, U_{\mu}}{\min} \mu w - \underset{\Sigma \, \in \, U_{\Sigma}}{\max} \lambda w^{T} \Sigma w\\ &\text{s.t.} & & Aw \geq 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 )^{T} \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 )^{T} \leq k^{2}_{\Sigma} \, , \, \Sigma \succeq 0 \right \} \\ \end{aligned}\end{split}\]

\(Aw \geq B\): is a set of linear constraints.

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

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

Ordered Weighted Averaging (OWA) Portfolio

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

  • Minimum Risk Portfolio:

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

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

\[\begin{split}\begin{aligned} &\underset{w}{\max} & & R (w) - \lambda \left ( \sum^{T}_{i=0} v_{[i]}y_{[i]} \right) \\ &\text{s.t.} & & Aw \geq B\\ & & & y = rw \\ & & & 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.

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

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

Module Methods

class Portfolio.Portfolio(returns=None, sht=False, uppersht=0.2, upperlng=1, budget=1, nea=None, card=None, factors=None, B=None, alpha=0.05, a_sim=100, beta=None, b_sim=None, kappa=0.3, n_max_kurt=50, kindbench=True, allowTO=False, turnover=0.05, allowTE=False, TE=0.05, benchindex=None, benchweights=None, ainequality=None, binequality=None, b=None, network_sdp=None, network_penalty=0.05, network_ip=None, acentrality=None, bcentrality=None, lowerret=None, upperdev=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, upperrg=None, uppermdd=None, upperadd=None, upperCDaR=None, upperEDaR=None, upperRLDaR=None, upperuci=None, p_1=2, p_2=3, p_3=4, p_4=10, p_5=50)[source]

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

Parameters:
  • returns (DataFrame, optional) – A dataframe that containts the returns of the 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 value of the sum of absolute values of short positions (negative weights). The default is 0.2.

  • upperlng (float, optional) – Indicate the maximum value of the sum of long positions (positive weights). When sht=True, the difference between upperlng and uppersht must be equal to the budget (upperlng - uppersht = budget) 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.

  • 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 [A28]. The default is None.

  • factors (DataFrame, optional) – A dataframe that containts the returns of the factors. The default is None.

  • B (DataFrame, optional) – A dataframe that containts the loadings matrix. 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.

  • 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 \geq B\). The default is None.

  • binequality (1d-array, optional) – The matrix \(B\) of the linear constraint \(A \geq B\). 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 [A29] and [A30]. The default is None.

  • network_penalty (float, optional) – The weight of SDP network constraint when the risk measure is not ‘MV’. This constraint is based on [A29] and [A30]. The default is 0.05.

  • 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 [A29] and [A30]. The default is None.

  • acentrality (nd-array, optional) – The matrix \(A_c\) of the centrality constraint \(A_c = B_c\). This constraint is based on [A29]. 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 [A29]. 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.

  • 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.

  • 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.

assets_stats(method_mu='hist', method_cov='hist', method_kurt=None, d=0.94, **kwargs)[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 [A31] and [A32].

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

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

  • 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: [A35].

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

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

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

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

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

  • 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 [A4].

    • ’semi’: use semi cokurtosis square matrix. For more information see [A4].

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

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

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

  • **kwargs (dict) – All additional parameters of mean_vector and covar_matrix functions.

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', **kwargs)[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 [A31] and [A32].

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

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

  • 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: [A35].

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

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

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

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

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

  • **kwargs (dict) – Other variables related to the covariance estimation.

See also

riskfolio.src.ParamsEstimation.black_litterman

factors_stats(method_mu='hist', method_cov='hist', d=0.94, B=None, feature_selection='stepwise', dict_cov={}, dict_risk={})[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 [A31] and [A32].

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

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

  • 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: [A35].

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

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

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

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

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

  • B (DataFrame of shape (n_assets, n_features), optional) – Loadings matrix. If is not specified, is estimated using stepwise regression. The default is None.

  • feature_selection (str, 'stepwise' or 'PCR', optional) –

    Indicate the method used to estimate the loadings matrix. The default is ‘stepwise’. Possible values are:

    • ’stepwise’: use stepwise regression to select the best factors and estimate coefficients.

    • ’PCR’: use principal components regression to estimate coefficients.

  • dict_cov (dict) – Other variables related to the covariance estimation method.

  • dict_risk (dict) – Other variables related of risk_factors function.

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=False, diag=False, method_mu='hist', method_cov='hist', kwargs_1=None, kwargs_2=None)[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.

  • diag (bool, optional) – Indicate if we use the diagonal matrix to calculate covariance matrix of factor model, only useful when we work with a factor model based on a regresion model (only equity portfolio). 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 [A31] and [A32].

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

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

  • 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: [A35].

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

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

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

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

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

  • kwargs_1 (dict) – Other variables related to the loadings matrix estimation.

  • kwargs_2 (dict) – Other variables related to the factors Black Litterman model selected.

See also

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

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 – 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 [A24]. 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. [A38] and [A39] .

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

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

  • 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. [A38] and [A39] .

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

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

  • 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=False, 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}} & & F(w)\\ &\text{s. t.} & & Aw \geq B\\ & & & \phi_{i}(w) \leq c_{i}\\ \end{align}\end{split}\]

Where:

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

\(Aw \geq B\) is a set of linear constraints.

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

Parameters:
  • model (str can be {'Classic', 'BL', 'FM' or 'BLFM'}) –

    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 and covariance 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.

  • 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.

    • ’MAD’: Mean Absolute Deviation.

    • ’GMD’: Gini Mean Difference.

    • ’MSV’: Semi Standard Deviation.

    • ’SKT’: Square Root of Semi Kurtosis.

    • ’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.

    • ’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.

    • ’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 False for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is False.

  • 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:

w – 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 [A20] [A21] and the risk parity with risk factors approach [] 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.} & & b \log(w) \geq c\\ & & & \mu w \geq \overline{\mu} \\ & & & Aw \geq B \\ & & & w \geq 0 \\ \end{aligned}\end{split}\]

Where:

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

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

\(b\) is a vector of risk constraints.

\(Aw \geq B\): is a set of linear constraints.

\(\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.

    • ’MAD’: Mean Absolute Deviation.

    • ’GMD’: Gini Mean Difference.

    • ’MSV’: Semi Standard Deviation.

    • ’SKT’: Square Root of Semi Kurtosis.

    • ’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.

    • ’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:

w – 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 [A22]. The general problem that solves is:

\[\begin{split}\begin{aligned} &\underset{w}{\min} & & \psi - \gamma & \\ &\text{s.t.} & & \zeta = \Sigma w \\ & & & w^{T} \Sigma w \leq \left ( \psi^{2} - \rho^{2} \right ) & \\ & & & w_{i} \zeta_{i} \geq \gamma^{2} b_{i} & \forall i=1 , \ldots , N \\ & & & \lambda x^{T} \Theta x \leq \rho^{2} & \\ & & & \mu w \geq \overline{\mu} & \\ & & & Aw \geq B & \\ & & & \sum^{N}_{i=1} w_{i} = 1 & \\ & & & \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.

\(b\): is the risk constribution constraint vector.

\(\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 \geq B\): is a set of linear constraints.

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 [A21]. 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:

w – 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:

w – The weights of optimal portfolio.

Return type:

DataFrame

owa_optimization(obj='Sharpe', owa_w=None, kelly=False, 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 \geq B\\ \end{align}\end{split}\]

Where:

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

\(Aw \geq B\) is a set of linear constraints.

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.

  • 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 False for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is False.

  • 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:

w – The weights of optimal portfolio.

Return type:

DataFrame

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

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

Parameters:
  • model (str, optional) – Methodology used to estimate input parameters. The default is ‘Classic’.

  • 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.

    • ’MAD’: Mean Absolute Deviation.

    • ’GMD’: Gini Mean Difference.

    • ’MSV’: Semi Standard Deviation.

    • ’SKT’: Square Root of Semi Kurtosis.

    • ’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.

    • ’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.

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

  • kelly (str, optional) – Method used to calculate mean return. Possible values are False for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is False.

  • 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=False, 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, optional) – Methodology used to estimate input parameters. The default is ‘Classic’.

  • 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.

    • ’MAD’: Mean Absolute Deviation.

    • ’GMD’: Gini Mean Difference.

    • ’MSV’: Semi Standard Deviation.

    • ’SKT’: Square Root of Semi Kurtosis.

    • ’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.

    • ’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.

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

  • kelly (str, optional) – Method used to calculate mean return. Possible values are False for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is False.

  • 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]

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]

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)

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

[A4] (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.

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

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

[A6] (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.

[A7] (1,2)

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

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

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.

[A9] (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.

[A10] (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.

[A11] (1,2)

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

[A12] (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.

[A13] (1,2)

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

[A14] (1,2)

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

[A15] (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.

[A16] (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.

[A17]

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

[A18] (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.

[A19] (1,2)

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

[A20] (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.

[A21] (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, doi:.

[A22] (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.

[A23] (1,2,3)

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

[A24] (1,2)

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

[A25]

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.

[A26]

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

[A27]

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.

[A28]

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.

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

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

[A30] (1,2,3)

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

[A31] (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.

[A32] (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.

[A33] (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.

[A34] (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, mar 2019. URL: https://doi.org/10.1016\%2Fj.jmva.2018.07.004, doi:10.1016/j.jmva.2018.07.004.

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

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

[A36] (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.

[A37] (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.

[A38] (1,2)

missing journal in Yang2019

[A39] (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.

[A40] (1,2)

missing publisher in Fabozzi

[A41] (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.