投资组合优化
理论介绍
均值风险投资组合优化
Riskfolio-Lib 可以通过优化以下 4 个目标函数之一而计算出投资组合:
最大收益:
最低风险:
最大的风险调整后收益率:
最大效用:
其中:
\(R (w)\) 是收益函数,可能的值是:
\(w\) 是最佳投资组合的权重向量.
\(\mu\) 是预期收益的向量.
\(\Sigma\) 是收益率的协方差矩阵.
\(r\) 是收益率的矩阵.
\(Aw \geq B\) 是一组线性约束.
\(\phi_{i}(w)\) 是 20 个可用的风险度量:
标准差 [A3].
平方根峰度 [A4].
平均绝对偏差 [A5].
条件在险价值范围 [A7].
尾部基尼范围 [A7].
半标准差 [A8].
一阶下偏矩(欧米伽比率) [A10].
二阶下偏矩(索提诺比率) [A10].
条件在险价值 [A11].
相对在险价值 [A16].
最坏情况实现(Minimax) [A17].
非复合累积收益的平均回撤 [A18].
非复合累积收益的溃疡指数 [A19].
非复合累计收益的条件在险回撤 [A18].
非复合累积收益的熵在险回撤 [A15].
非复合累积收益的相对在险回撤 [A16].
非复合累积收益的最大回撤(卡玛比率) [A18].
\(c_{i}\): 是每个风险度量的最大值.
\(r_{f}\): 是无风险利率。当风险度量是一阶或二阶下偏矩时, \(r_{f}\) 是最小可接受的收益率 \(\text{MAR}\).
\(\lambda\): 是投资者的风险厌恶系数.
风险平价投资组合优化
Riskfolio-Lib 可以通过优化一般香草风险平价模型(香草意为简单的、基础的) [A20] [A21] 来构建投资组合:
其中:
\(w\): 是最佳投资组合的权重向量.
\(\mu\): 是预期收益的向量.
\(b\): 是风险贡献约束的向量.
\(Aw \geq B\):是一组线性约束.
\(\phi(w)\):是 16 个可用的风险度量:
标准差 [A3].
平方根峰度 [A4].
平均绝对偏差 [A5].
条件在险价值范围 [A7].
尾部基尼系数范围 [A7].
半标准差 [A8].
一阶下偏矩(欧米伽比率) [A10].
二阶下偏矩(索提诺比率) [A10].
条件在险价值 [A11].
相对在险价值 [A16].
非复合累积收益的溃疡指数 [A19].
非复合累计收益的条件在险回撤 [A18].
非复合累积收益的熵在险回撤 [A15].
非复合累积收益的相对在险回撤 [A16].
\(c\): 是一个任意的常数.
宽松的风险平价投资组合优化
Riskfolio-Lib 可以通过优化宽松的风险平价模型 [A22] 来构建投资组合:
其中:
\(w\) 是最佳投资组合的权重向量.
\(\mu\) 是预期收益的向量.
\(\Sigma\) 是资产收益率的协方差矩阵.
\(\psi\) 是投资组合的平均风险.
\(\gamma\) 是每个资产风险贡献的下限.
\(b\) 是风险贡献向量的约束.
\(\zeta_{i}\) 是资产的边际风险 \(i\).
\(\rho\) 是一个正则化变量.
\(\lambda\) 是 \(\rho\) 的惩罚参数.
\(\Theta = \text{diag}(\Sigma)\)
\(Aw \geq B\) 是一组线性约束.
最坏情况下的平均方差投资组合优化
Riskfolio-Lib可以计算出最坏情况下的平均方差最佳投资组合 [A23] [A24] [A25] [A26]. 在以下4个目标函数中优化一个的结果:
最坏情况下的最大收益:
最坏情况最低风险:
最坏情况下的最大的风险调整收益率:
最坏情况下的最大效用:
其中:
\(w\) 是投资组合的权重.
\(\mu\) 是预期收益的向量.
\(\Sigma\) 是协方差矩阵.
\(U_{\mu}\) 是均值向量的不确定性集。不确定性集可以是:
\(U_{\Sigma}\) 是协方差矩阵的不确定性集。不确定性集可以是:
\(Aw \geq B\) 是一组线性约束.
\(r_{f}\) 是无风险利率.
\(\lambda\) 是投资者的风险厌恶系数.
有序加权平均法(OWA)投资组合
Riskfolio-Lib 可以计算OWA投资组合优化模型 [A7] 。我们可以使用 这个函数来计算 Higher L-Moment 投资组合优化模型 [A9] 。
最小风险:
最大的风险调整收益率:
最大效用:
其中:
\(w\) 是组合的权重.
\(v\) 是 owa 运算符的权重.
\(\mu\) 是期望收益的向量.
\(X_{[i]}\) 是向量 \(X\) 的第 \(i\) 阶元素.
模块函数
- 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, 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)[源代码]
Class that creates a portfolio object with all properties needed to calculate optimal portfolios.
- 参数:
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 [A27]. 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.
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.
- assets_stats(method_mu='hist', method_cov='hist', method_kurt=None, d=0.94, **kwargs)[源代码]
Calculate the inputs that will be used by the optimization method when we select the input model=’Classic’.
- 参数:
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 [A28] and [A29].
’BS’: Bayes-Stein estimator. For more information see [A30].
’BOP’: BOP estimator. For more information see [A31].
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: [A32].
’fixed’: denoise using fixed method. For more information see chapter 2 of [A33].
’spectral’: denoise using spectral method. For more information see chapter 2 of [A33].
’shrink’: denoise using shrink method. For more information see chapter 2 of [A33].
’gerber1’: use the Gerber statistic 1. For more information see: [A34].
’gerber2’: use the Gerber statistic 2. For more information see: [A34].
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 [A33].
’spectral’: denoise using spectral method. For more information see chapter 2 of [A33].
’shrink’: denoise using shrink method. For more information see chapter 2 of [A33].
**kwargs (dict) – All additional parameters of mean_vector and covar_matrix functions.
参见
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)[源代码]
Calculate the inputs that will be used by the optimization method when we select the input model=’BL’.
- 参数:
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 [A28] and [A29].
’BS’: Bayes-Stein estimator. For more information see [A30].
’BOP’: BOP estimator. For more information see [A31].
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: [A32].
’fixed’: denoise using fixed method. For more information see chapter 2 of [A33].
’spectral’: denoise using spectral method. For more information see chapter 2 of [A33].
’shrink’: denoise using shrink method. For more information see chapter 2 of [A33].
’gerber1’: use the Gerber statistic 1. For more information see: [A34].
’gerber2’: use the Gerber statistic 2. For more information see: [A34].
**kwargs (dict) – Other variables related to the covariance estimation.
参见
riskfolio.src.ParamsEstimation.black_litterman
- factors_stats(method_mu='hist', method_cov='hist', d=0.94, B=None, dict_cov={}, dict_risk={})[源代码]
Calculate the inputs that will be used by the optimization method when we select the input model=’FM’.
- 参数:
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 [A28] and [A29].
’BS’: Bayes-Stein estimator. For more information see [A30].
’BOP’: BOP estimator. For more information see [A31].
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: [A32].
’fixed’: denoise using fixed method. For more information see chapter 2 of [A33].
’spectral’: denoise using spectral method. For more information see chapter 2 of [A33].
’shrink’: denoise using shrink method. For more information see chapter 2 of [A33].
’gerber1’: use the Gerber statistic 1. For more information see: [A34].
’gerber2’: use the Gerber statistic 2. For more information see: [A34].
dict_cov (dict) – Other variables related to the covariance estimation.
dict_risk (dict) – Other variables related of risk_factors function.
参见
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)[源代码]
Calculate the inputs that will be used by the optimization method when we select the input model=’BL’.
- 参数:
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 [A28] and [A29].
’BS’: Bayes-Stein estimator. For more information see [A30].
’BOP’: BOP estimator. For more information see [A31].
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: [A32].
’fixed’: denoise using fixed method. For more information see chapter 2 of [A33].
’spectral’: denoise using spectral method. For more information see chapter 2 of [A33].
’shrink’: denoise using shrink method. For more information see chapter 2 of [A33].
’gerber1’: use the Gerber statistic 1. For more information see: [A34].
’gerber2’: use the Gerber statistic 2. For more information see: [A34].
kwargs_1 (dict) – Other variables related to the loadings matrix estimation.
kwargs_2 (dict) – Other variables related to the factors Black Litterman model selected.
参见
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, dmu=0.1, dcov=0.1, seed=0)[源代码]
Calculate the inputs that will be used by the wc_optimization method.
- 参数:
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.
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.
参见
riskfolio.src.ParamsEstimation.bootstrapping
- optimization(model='Classic', rm='MV', obj='Sharpe', kelly=False, rf=0, l=2, hist=True)[源代码]
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.
- 参数:
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.
- 返回:
w – The weights of optimal portfolio.
- 返回类型:
DataFrame
- rp_optimization(model='Classic', rm='MV', rf=0, b=None, hist=True)[源代码]
This method that calculates the risk parity portfolio using the risk budgeting approach [A20] [A21], 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.
- 参数:
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.
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).
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.
- 返回:
w – The weights of optimal portfolio.
- 返回类型:
DataFrame
- rrp_optimization(model='Classic', version='A', l=1, b=None, hist=True)[源代码]
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.
- 参数:
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.
- 返回:
w – The weights of optimal portfolio.
- 返回类型:
DataFrame
- wc_optimization(obj='Sharpe', rf=0, l=2, Umu='box', Ucov='box')[源代码]
This method that calculates the worst case mean variance portfolio according to the objective function and uncertainty sets selected 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 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.
- 返回:
w – The weights of optimal portfolio.
- 返回类型:
DataFrame
- owa_optimization(obj='Sharpe', owa_w=None, kelly=False, rf=0, l=2)[源代码]
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.
- 参数:
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.
- 返回:
w – The weights of optimal portfolio.
- 返回类型:
DataFrame
- frontier_limits(model='Classic', rm='MV', kelly=False, rf=0, hist=True)[源代码]
Method that calculates the minimum risk and maximum return portfolios available with current assets and constraints.
- 参数:
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.
- 返回:
limits – A dataframe that containts the weights of the portfolios.
- 返回类型:
DataFrame
备注
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=None, hist=True)[源代码]
Method that calculates several portfolios in the efficient frontier of the selected risk measure, available with current assets and constraints.
- 参数:
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 None.
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.
- 返回:
frontier – A dataframe that containts the weights of the portfolios.
- 返回类型:
DataFrame
备注
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.
参考文档
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.
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.
Harry Markowitz. Portfolio selection. The Journal of Finance, 7(1):77–91, 1952. URL: http://www.jstor.org/stable/2975974.
Dany Cajas. Convex optimization of portfolio kurtosis. SSRN Electronic Journal, 2022. URL: https://doi.org/10.2139/ssrn.4202967, doi:10.2139/ssrn.4202967.
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.
Shlomo Yitzhaki. Stochastic dominance, mean variance, and gini's mean difference. American Economic Review, 72:178–85, 01 1982.
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.
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.
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.
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.
R. Tyrrell Rockafellar and Stanislav Uryasev. Optimization of conditional value-at-risk. Journal of Risk, 2:21–41, 2000.
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.
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.
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.
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.
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.
Renata Mansini, W. Ogryczak, and M.Grazia Speranza. On lp solvable models for portfolio selection. Informatica, 14:37–62, 01 2003.
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.
Peter Martin. The investor's guide to fidelity funds. Wiley, New York, 1989. ISBN 978-0471622581.
Benjamin Bruder and Thierry Roncalli. Managing risk exposures using the risk budgeting approach. SSRN Electronic Journal, pages, 01 2012. doi:10.2139/ssrn.2009778.
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:.
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.
Miguel Sousa Lobo and Stephen Boyd. The worst-case risk of a portfolio. 10 2000.
Frank Fabozzi. Robust portfolio optimization and management. John Wiley, Hoboken, N.J, 2007. ISBN 978-0-471-92122-6.
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.
Daniel Palomar. Robust optimization with applications. URL: https://palomar.home.ece.ust.hk/ELEC5470_lectures/slides_robust_optim.pdf.
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.
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.
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.
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.
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.
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.
Marcos M. López de Prado. Machine Learning for Asset Managers. Elements in Quantitative Finance. Cambridge University Press, 2020. doi:10.1017/9781108883658.
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.