风险函数
该模块具有计算几个风险指标的功能,这些指标被资产管理行业和学术界广泛使用。
模块函数
- RiskFunctions.MAD(X)[源代码]
Calculate the Mean Absolute Deviation (MAD) of a returns series.
\[\text{MAD}(X) = \frac{1}{T}\sum_{t=1}^{T} | X_{t} - \mathbb{E}(X_{t}) |\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 返回:
value – MAD of a returns series.
- 返回类型:
- RiskFunctions.SemiDeviation(X)[源代码]
Calculate the Semi Deviation of a returns series.
\[\text{SemiDev}(X) = \left [ \frac{1}{T-1}\sum_{t=1}^{T} \min (X_{t} - \mathbb{E}(X_{t}), 0)^2 \right ]^{1/2}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Semi Deviation of a returns series.
- 返回类型:
- RiskFunctions.Kurtosis(X)[源代码]
Calculate the Square Root Kurtosis of a returns series.
\[\text{Kurt}(X) = \left [ \frac{1}{T}\sum_{t=1}^{T} (X_{t} - \mathbb{E}(X_{t}))^{4} \right ]^{1/2}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Square Root Kurtosis of a returns series.
- 返回类型:
- RiskFunctions.SemiKurtosis(X)[源代码]
Calculate the Semi Square Root Kurtosis of a returns series.
\[\text{SemiKurt}(X) = \left [ \frac{1}{T}\sum_{t=1}^{T} \min (X_{t} - \mathbb{E}(X_{t}), 0)^{4} \right ]^{1/2}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Semi Square Root Kurtosis of a returns series.
- 返回类型:
- RiskFunctions.VaR_Hist(X, alpha=0.05)[源代码]
Calculate the Value at Risk (VaR) of a returns series.
\[\text{VaR}_{\alpha}(X) = -\inf_{t \in (0,T)} \left \{ X_{t} \in \mathbb{R}: F_{X}(X_{t})>\alpha \right \}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
alpha (float, optional) – Significance level of VaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – VaR of a returns series.
- 返回类型:
- RiskFunctions.CVaR_Hist(X, alpha=0.05)[源代码]
Calculate the Conditional Value at Risk (CVaR) of a returns series.
\[\text{CVaR}_{\alpha}(X) = \text{VaR}_{\alpha}(X) + \frac{1}{\alpha T} \sum_{t=1}^{T} \max(-X_{t} - \text{VaR}_{\alpha}(X), 0)\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
alpha (float, optional) – Significance level of CVaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – CVaR of a returns series.
- 返回类型:
- RiskFunctions.WR(X)[源代码]
Calculate the Worst Realization (WR) or Worst Scenario of a returns series.
\[\text{WR}(X) = \max(-X)\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – WR of a returns series.
- 返回类型:
- RiskFunctions.LPM(X, MAR=0, p=1)[源代码]
Calculate the First or Second Lower Partial Moment of a returns series.
\[\begin{split}\text{LPM}(X, \text{MAR}, 1) &= \frac{1}{T}\sum_{t=1}^{T} \max(\text{MAR} - X_{t}, 0) \\ \text{LPM}(X, \text{MAR}, 2) &= \left [ \frac{1}{T-1}\sum_{t=1}^{T} \max(\text{MAR} - X_{t}, 0)^{2} \right ]^{\frac{1}{2}} \\\end{split}\]Where:
\(\text{MAR}\) is the minimum acceptable return. \(p\) is the order of the \(\text{LPM}\).
- 参数:
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – p-th Lower Partial Moment of a returns series.
- 返回类型:
- RiskFunctions.Entropic_RM(X, z=1, alpha=0.05)[源代码]
Calculate the Entropic Risk Measure (ERM) of a returns series.
\[\text{ERM}_{\alpha}(X) = z\ln \left (\frac{M_X(z^{-1})}{\alpha} \right )\]Where:
\(M_X(z)\) is the moment generating function of X.
- 参数:
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – ERM of a returns series.
- 返回类型:
- RiskFunctions.EVaR_Hist(X, alpha=0.05)[源代码]
Calculate the Entropic Value at Risk (EVaR) of a returns series.
\[\text{EVaR}_{\alpha}(X) = \inf_{z>0} \left \{ z \ln \left (\frac{M_X(z^{-1})}{\alpha} \right ) \right \}\]Where:
\(M_X(t)\) is the moment generating function of X.
- 参数:
X (1d-array) – Returns series, must have Tx1 size.
alpha (float, optional) – Significance level of EVaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
(value, z) – EVaR of a returns series and value of z that minimize EVaR.
- 返回类型:
- RiskFunctions.RLVaR_Hist(X, alpha=0.05, kappa=0.01, solver=None)[源代码]
Calculate the Relativistic Value at Risk (RLVaR) of a returns series. I recommend only use this function with MOSEK solver.
\[\begin{split}\text{RLVaR}^{\kappa}_{\alpha}(X) & = \left \{ \begin{array}{ll} \underset{z, t, \psi, \theta, \varepsilon, \omega}{\text{inf}} & t + z \ln_{\kappa} \left ( \frac{1}{\alpha T} \right ) + \sum^T_{i=1} \left ( \psi_{i} + \theta_{i} \right ) \\ \text{s.t.} & -X - t + \varepsilon + \omega \leq 0\\ & z \geq 0 \\ & \left ( z \left ( \frac{1+\kappa}{2\kappa} \right ), \psi_{i} \left ( \frac{1+\kappa}{\kappa} \right ), \varepsilon_{i} \right) \in \mathcal{P}_3^{1/(1+\kappa),\, \kappa/(1+\kappa)} \\ & \left ( \omega_{i}\left ( \frac{1}{1-\kappa} \right ), \theta_{i}\left ( \frac{1}{\kappa} \right), -z \left ( \frac{1}{2\kappa} \right ) \right ) \in \mathcal{P}_3^{1-\kappa,\, \kappa} \\\end{split}\]Where:
\(\mathcal{P}_3^{\alpha,\, 1-\alpha}\) is the power cone 3D.
\(\kappa\) is the deformation parameter.
- 参数:
X (1d-array) – Returns series, must have Tx1 size.
alpha (float, optional) – Significance level of EVaR. The default is 0.05.
kappa (float, optional) – Deformation parameter of RLVaR, must be between 0 and 1. The default is 0.01.
solver (str, optional) – Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is None.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – RLVaR of a returns series.
- 返回类型:
- RiskFunctions.MDD_Abs(X)[源代码]
Calculate the Maximum Drawdown (MDD) of a returns series using uncompounded cumulative returns.
\[\text{MDD}(X) = \max_{j \in (0,T)} \left [\max_{t \in (0,j)} \left ( \sum_{i=0}^{t}X_{i} \right ) - \sum_{i=0}^{j}X_{i} \right ]\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – MDD of an uncompounded cumulative returns.
- 返回类型:
- RiskFunctions.ADD_Abs(X)[源代码]
Calculate the Average Drawdown (ADD) of a returns series using uncompounded cumulative returns.
\[\text{ADD}(X) = \frac{1}{T}\sum_{j=0}^{T}\left [ \max_{t \in (0,j)} \left ( \sum_{i=0}^{t}X_{i} \right ) - \sum_{i=0}^{j}X_{i} \right ]\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – ADD of an uncompounded cumulative returns.
- 返回类型:
- RiskFunctions.DaR_Abs(X, alpha=0.05)[源代码]
Calculate the Drawdown at Risk (DaR) of a returns series using uncompounded cumulative returns.
\[\begin{split}\text{DaR}_{\alpha}(X) & = \max_{j \in (0,T)} \left \{ \text{DD}(X,j) \in \mathbb{R}: F_{\text{DD}} \left ( \text{DD}(X,j) \right )< 1-\alpha \right \} \\ \text{DD}(X,j) & = \max_{t \in (0,j)} \left ( \sum_{i=0}^{t}X_{i} \right )- \sum_{i=0}^{j}X_{i}\end{split}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size..
alpha (float, optional) – Significance level of DaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – DaR of an uncompounded cumulative returns series.
- 返回类型:
- RiskFunctions.CDaR_Abs(X, alpha=0.05)[源代码]
Calculate the Conditional Drawdown at Risk (CDaR) of a returns series using uncompounded cumulative returns.
\[\text{CDaR}_{\alpha}(X) = \text{DaR}_{\alpha}(X) + \frac{1}{\alpha T} \sum_{j=0}^{T} \max \left [ \max_{t \in (0,j)} \left ( \sum_{i=0}^{t}X_{i} \right ) - \sum_{i=0}^{j}X_{i} - \text{DaR}_{\alpha}(X), 0 \right ]\]Where:
\(\text{DaR}_{\alpha}\) is the Drawdown at Risk of an uncompounded cumulated return series \(X\).
- 参数:
X (1d-array) – Returns series, must have Tx1 size..
alpha (float, optional) – Significance level of CDaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – CDaR of an uncompounded cumulative returns series.
- 返回类型:
- RiskFunctions.EDaR_Abs(X, alpha=0.05)[源代码]
Calculate the Entropic Drawdown at Risk (EDaR) of a returns series using uncompounded cumulative returns.
\[\begin{split}\text{EDaR}_{\alpha}(X) & = \inf_{z>0} \left \{ z \ln \left (\frac{M_{\text{DD}(X)}(z^{-1})}{\alpha} \right ) \right \} \\ \text{DD}(X,j) & = \max_{t \in (0,j)} \left ( \sum_{i=0}^{t}X_{i} \right )- \sum_{i=0}^{j}X_{i} \\\end{split}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size..
alpha (float, optional) – Significance level of EDaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
(value, z) – EDaR of an uncompounded cumulative returns series and value of z that minimize EDaR.
- 返回类型:
- RiskFunctions.RLDaR_Abs(X, alpha=0.05, kappa=0.01, solver=None)[源代码]
Calculate the Relativistic Drawdown at Risk (RLDaR) of a returns series using uncompounded cumulative returns. I recommend only use this function with MOSEK solver.
\[\begin{split}\text{RLDaR}^{\kappa}_{\alpha}(X) & = \text{RLVaR}^{\kappa}_{\alpha}(DD(X)) \\ \text{DD}(X,j) & = \max_{t \in (0,j)} \left ( \sum_{i=0}^{t}X_{i} \right )- \sum_{i=0}^{j}X_{i} \\\end{split}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
alpha (float, optional) – Significance level of EVaR. The default is 0.05.
kappa (float, optional) – Deformation parameter of RLDaR, must be between 0 and 1. The default is 0.01.
solver (str, optional) – Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is None.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – RLDaR of an uncompounded cumulative returns series.
- 返回类型:
- RiskFunctions.UCI_Abs(X)[源代码]
Calculate the Ulcer Index (UCI) of a returns series using uncompounded cumulative returns.
\[\text{UCI}(X) =\sqrt{\frac{1}{T}\sum_{j=0}^{T} \left [ \max_{t \in (0,j)} \left ( \sum_{i=0}^{t}X_{i} \right ) - \sum_{i=0}^{j}X_{i} \right ] ^2}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Ulcer Index of an uncompounded cumulative returns.
- 返回类型:
- RiskFunctions.MDD_Rel(X)[源代码]
Calculate the Maximum Drawdown (MDD) of a returns series using cumpounded cumulative returns.
\[\text{MDD}(X) = \max_{j \in (0,T)}\left[\max_{t \in (0,j)} \left ( \prod_{i=0}^{t}(1+X_{i}) \right ) - \prod_{i=0}^{j}(1+X_{i}) \right]\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – MDD of a cumpounded cumulative returns.
- 返回类型:
- RiskFunctions.ADD_Rel(X)[源代码]
Calculate the Average Drawdown (ADD) of a returns series using cumpounded cumulative returns.
\[\text{ADD}(X) = \frac{1}{T}\sum_{j=0}^{T} \left [ \max_{t \in (0,j)} \left ( \prod_{i=0}^{t}(1+X_{i}) \right )- \prod_{i=0}^{j}(1+X_{i}) \right ]\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – ADD of a cumpounded cumulative returns.
- 返回类型:
- RiskFunctions.DaR_Rel(X, alpha=0.05)[源代码]
Calculate the Drawdown at Risk (DaR) of a returns series using cumpounded cumulative returns.
\[\begin{split}\text{DaR}_{\alpha}(X) & = \max_{j \in (0,T)} \left \{ \text{DD}(X,j) \in \mathbb{R}: F_{\text{DD}} \left ( \text{DD}(X,j) \right )< 1 - \alpha \right \} \\ \text{DD}(X,j) & = \max_{t \in (0,j)} \left ( \prod_{i=0}^{t}(1+X_{i}) \right )- \prod_{i=0}^{j}(1+X_{i})\end{split}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size..
alpha (float, optional) – Significance level of DaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – DaR of a cumpounded cumulative returns series.
- 返回类型:
- RiskFunctions.CDaR_Rel(X, alpha=0.05)[源代码]
Calculate the Conditional Drawdown at Risk (CDaR) of a returns series using cumpounded cumulative returns.
\[\text{CDaR}_{\alpha}(X) = \text{DaR}_{\alpha}(X) + \frac{1}{\alpha T} \sum_{i=0}^{T} \max \left [ \max_{t \in (0,T)} \left ( \prod_{i=0}^{t}(1+X_{i}) \right )- \prod_{i=0}^{j}(1+X_{i}) - \text{DaR}_{\alpha}(X), 0 \right ]\]Where:
\(\text{DaR}_{\alpha}\) is the Drawdown at Risk of a cumpound cumulated return series \(X\).
- 参数:
X (1d-array) – Returns series, must have Tx1 size..
alpha (float, optional) – Significance level of CDaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – CDaR of a cumpounded cumulative returns series.
- 返回类型:
- RiskFunctions.EDaR_Rel(X, alpha=0.05)[源代码]
Calculate the Entropic Drawdown at Risk (EDaR) of a returns series using cumpounded cumulative returns.
\[\begin{split}\text{EDaR}_{\alpha}(X) & = \inf_{z>0} \left \{ z \ln \left (\frac{M_{\text{DD}(X)}(z^{-1})}{\alpha} \right ) \right \} \\ \text{DD}(X,j) & = \max_{t \in (0,j)} \left ( \prod_{i=0}^{t}(1+X_{i}) \right )- \prod_{i=0}^{j}(1+X_{i})\end{split}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size..
alpha (float, optional) – Significance level of EDaR. The default is 0.05.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
(value, z) – EDaR of a cumpounded cumulative returns series and value of z that minimize EDaR.
- 返回类型:
- RiskFunctions.RLDaR_Rel(X, alpha=0.05, kappa=0.01, solver=None)[源代码]
Calculate the Relativistic Drawdown at Risk (RLDaR) of a returns series using compounded cumulative returns. I recommend only use this function with MOSEK solver.
\[\begin{split}\text{RLDaR}^{\kappa}_{\alpha}(X) & = \text{RLVaR}^{\kappa}_{\alpha}(DD(X)) \\ \text{DD}(X,j) & = \max_{t \in (0,j)} \left ( \prod_{i=0}^{t}(1+X_{i}) \right )- \prod_{i=0}^{j}(1+X_{i}) \\\end{split}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
alpha (float, optional) – Significance level of RLDaR. The default is 0.05.
kappa (float, optional) – Deformation parameter of RLDaR, must be between 0 and 1. The default is 0.01.
solver (str, optional) – Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is None.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – RLDaR of a compounded cumulative returns series.
- 返回类型:
- RiskFunctions.UCI_Rel(X)[源代码]
Calculate the Ulcer Index (UCI) of a returns series using cumpounded cumulative returns.
\[\text{UCI}(X) =\sqrt{\frac{1}{T}\sum_{j=0}^{T} \left [ \max_{t \in (0,j)} \left ( \prod_{i=0}^{t}(1+X_{i}) \right )- \prod_{i=0}^{j} (1+X_{i}) \right ] ^2}\]- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Ulcer Index of a cumpounded cumulative returns.
- 返回类型:
- RiskFunctions.GMD(X)[源代码]
Calculate the Gini Mean Difference (GMD) of a returns series.
- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Gini Mean Difference of a returns series.
- 返回类型:
- RiskFunctions.TG(X, alpha=0.05, a_sim=100)[源代码]
Calculate the Tail Gini of a returns series.
- 参数:
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Ulcer Index of a cumpounded cumulative returns.
- 返回类型:
- RiskFunctions.RG(X)[源代码]
Calculate the range of a returns series.
- 参数:
X (1d-array) – Returns series, must have Tx1 size.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Ulcer Index of a cumpounded cumulative returns.
- 返回类型:
- RiskFunctions.CVRG(X, alpha=0.05, beta=None)[源代码]
Calculate the CVaR range of a returns series.
- 参数:
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Ulcer Index of a cumpounded cumulative returns.
- 返回类型:
- RiskFunctions.TGRG(X, alpha=0.05, a_sim=100, beta=None, b_sim=None)[源代码]
Calculate the Tail Gini range of a returns series.
- 参数:
X (1d-array) – Returns series, must have Tx1 size.
alpha (float, optional) – Significance level of 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 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.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Ulcer Index of a cumpounded cumulative returns.
- 返回类型:
- RiskFunctions.L_Moment(X, k=2)[源代码]
Calculate the kth l-moment of a returns series.
Where $y_{[i]}$ is the ith-ordered statistic.
- 参数:
X (1d-array) – Returns series, must have Tx1 size.
k (int) – Order of the l-moment. Must be an integer higher or equal than 1.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Kth l-moment of a returns series.
- 返回类型:
- RiskFunctions.L_Moment_CRM(X, k=4, method='MSD', g=0.5, max_phi=0.5, solver=None)[源代码]
Calculate a custom convex risk measure that is a weighted average of first k-th l-moments.
- 参数:
X (1d-array) – Returns series, must have Tx1 size.
k (int) – Order of the l-moment. Must be an integer higher or equal than 2.
method (str, optional) –
Method to calculate the weights used to combine the l-moments with order higher than 2. The default value is ‘MSD’. Possible values are:
’CRRA’: Normalized Constant Relative Risk Aversion coefficients.
’ME’: Maximum Entropy.
’MSS’: Minimum Sum Squares.
’MSD’: Minimum Square Distance.
g (float, optional) – Risk aversion coefficient of CRRA utility function. The default is 0.5.
max_phi (float, optional) – Maximum weight constraint of L-moments. The default is 0.5.
solver (str, optional) – Solver available for CVXPY. Used to calculate ‘ME’, ‘MSS’ and ‘MSD’ weights. The default value is None.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Custom convex risk measure that is a weighted average of first k-th l-moments of a returns series.
- 返回类型:
- RiskFunctions.Sharpe_Risk(w, cov=None, returns=None, rm='MV', rf=0, alpha=0.05, a_sim=100, beta=None, b_sim=None, kappa=0.01, solver=None)[源代码]
Calculate the risk measure available on the Sharpe function.
- 参数:
w (DataFrame or 1d-array of shape (n_assets, 1)) – Weights matrix, where n_assets is the number of assets.
cov (DataFrame or nd-array of shape (n_features, n_features)) – Covariance matrix, where n_features is the number of features.
returns (DataFrame or nd-array of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.
rm (str, optional) –
Risk measure used in the denominator of the ratio. The default is ‘MV’. Possible values are:
’MV’: Standard Deviation.
’KT’: Square Root Kurtosis.
’MAD’: Mean Absolute Deviation.
’GMD’: Gini Mean Difference.
’MSV’: Semi Standard Deviation.
’SKT’: Square Root Semi Kurtosis.
’FLPM’: First Lower Partial Moment (Omega Ratio).
’SLPM’: Second Lower Partial Moment (Sortino Ratio).
’VaR’: Value at Risk.
’CVaR’: Conditional Value at Risk.
’TG’: Tail Gini.
’EVaR’: Entropic Value at Risk.
’RLVaR’: Relativistic Value at Risk. I recommend only use this function with MOSEK solver.
’WR’: Worst Realization (Minimax).
’RG’: Range of returns.
’CVRG’: CVaR range of returns.
’TGRG’: Tail Gini range of returns.
’MDD’: Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).
’ADD’: Average Drawdown of uncompounded cumulative returns.
’DaR’: Drawdown at Risk of uncompounded cumulative returns.
’CDaR’: Conditional Drawdown at Risk of uncompounded cumulative returns.
’EDaR’: Entropic Drawdown at Risk of uncompounded cumulative returns.
’RLDaR’: Relativistic Drawdown at Risk of uncompounded cumulative returns. I recommend only use this risk measure with MOSEK solver.
’UCI’: Ulcer Index of uncompounded cumulative returns.
’MDD_Rel’: Maximum Drawdown of compounded cumulative returns (Calmar Ratio).
’ADD_Rel’: Average Drawdown of compounded cumulative returns.
’CDaR_Rel’: Conditional Drawdown at Risk of compounded cumulative returns.
’EDaR_Rel’: Entropic Drawdown at Risk of compounded cumulative returns.
’RLDaR_Rel’: Relativistic Drawdown at Risk of compounded cumulative returns. I recommend only use this risk measure with MOSEK solver.
’UCI_Rel’: Ulcer Index of compounded cumulative returns.
rf (float, optional) – Risk free rate. The default is 0.
alpha (float, optional) – Significance level of VaR, CVaR, EVaR, RLVaR, DaR, CDaR, EDaR, RLDaR 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, must be between 0 and 1. The default is 0.01.
solver (str, optional) – Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is None.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Risk measure of the portfolio.
- 返回类型:
- RiskFunctions.Sharpe(w, mu, cov=None, returns=None, rm='MV', rf=0, alpha=0.05, a_sim=100, beta=None, b_sim=None, kappa=0.01, solver=None)[源代码]
Calculate the Risk Adjusted Return Ratio from a portfolio returns series.
\[\text{Sharpe}(X) = \frac{\mathbb{E}(X) - r_{f}}{\phi(X)}\]Where:
\(X\) is the vector of portfolio returns.
\(r_{f}\) is the risk free rate, when the risk measure is
\(\text{LPM}\) uses instead of \(r_{f}\) the \(\text{MAR}\).
\(\phi(X)\) is a convex risk measure. The risk measures availabe are:
- 参数:
w (DataFrame or 1d-array of shape (n_assets, 1)) – Weights matrix, where n_assets is the number of assets.
mu (DataFrame or nd-array of shape (1, n_assets)) – Vector of expected returns, where n_assets is the number of assets.
cov (DataFrame or nd-array of shape (n_features, n_features)) – Covariance matrix, where n_features is the number of features.
returns (DataFrame or nd-array of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.
rm (str, optional) –
Risk measure used in the denominator of the ratio. The default is ‘MV’. Possible values are:
’MV’: Standard Deviation.
’KT’: Square Root Kurtosis.
’MAD’: Mean Absolute Deviation.
’GMD’: Gini Mean Difference.
’MSV’: Semi Standard Deviation.
’SKT’: Square Root Semi Kurtosis.
’FLPM’: First Lower Partial Moment (Omega Ratio).
’SLPM’: Second Lower Partial Moment (Sortino Ratio).
’VaR’: Value at Risk.
’CVaR’: Conditional Value at Risk.
’TG’: Tail Gini.
’EVaR’: Entropic Value at Risk.
’RLVaR’: Relativistic Value at Risk. I recommend only use this function with MOSEK solver.
’WR’: Worst Realization (Minimax).
’RG’: Range of returns.
’CVRG’: CVaR range of returns.
’TGRG’: Tail Gini range of returns.
’MDD’: Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).
’ADD’: Average Drawdown of uncompounded cumulative returns.
’DaR’: Drawdown at Risk of uncompounded cumulative returns.
’CDaR’: Conditional Drawdown at Risk of uncompounded cumulative returns.
’EDaR’: Entropic Drawdown at Risk of uncompounded cumulative returns.
’RLDaR’: Relativistic Drawdown at Risk of uncompounded cumulative returns. I recommend only use this function with MOSEK solver.
’UCI’: Ulcer Index of uncompounded cumulative returns.
’MDD_Rel’: Maximum Drawdown of compounded cumulative returns (Calmar Ratio).
’ADD_Rel’: Average Drawdown of compounded cumulative returns.
’CDaR_Rel’: Conditional Drawdown at Risk of compounded cumulative returns.
’EDaR_Rel’: Entropic Drawdown at Risk of compounded cumulative returns.
’RLDaR_Rel’: Relativistic Drawdown at Risk of compounded cumulative returns. I recommend only use this function with MOSEK solver.
’UCI_Rel’: Ulcer Index of compounded cumulative returns.
rf (float, optional) – Risk free rate. The default is 0.
alpha (float, optional) – Significance level of VaR, CVaR, EVaR, RLVaR, DaR, CDaR, EDaR, RLDaR 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, must be between 0 and 1. The default is 0.01.
solver (str, optional) – Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is None.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Risk adjusted return ratio of \(X\).
- 返回类型:
- RiskFunctions.Risk_Contribution(w, cov=None, returns=None, rm='MV', rf=0, alpha=0.05, a_sim=100, beta=None, b_sim=None, kappa=0.01, solver=None)[源代码]
Calculate the risk contribution for each asset based on the risk measure selected.
- 参数:
w (DataFrame or 1d-array of shape (n_assets, 1)) – Weights matrix, where n_assets is the number of assets.
cov (DataFrame or nd-array of shape (n_features, n_features)) – Covariance matrix, where n_features is the number of features.
returns (DataFrame or nd-array of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.
rm (str, optional) –
Risk measure used in the denominator of the ratio. The default is ‘MV’. Possible values are:
’MV’: Standard Deviation.
’KT’: Square Root Kurtosis.
’MAD’: Mean Absolute Deviation.
’GMD’: Gini Mean Difference.
’MSV’: Semi Standard Deviation.
’SKT’: Square Root Semi Kurtosis.
’FLPM’: First Lower Partial Moment (Omega Ratio).
’SLPM’: Second Lower Partial Moment (Sortino Ratio).
’VaR’: Value at Risk.
’CVaR’: Conditional Value at Risk.
’TG’: Tail Gini.
’EVaR’: Entropic Value at Risk.
’RLVaR’: Relativistic Value at Risk. I recommend only use this function with MOSEK solver.
’WR’: Worst Realization (Minimax).
’RG’: Range of returns.
’CVRG’: CVaR range of returns.
’TGRG’: Tail Gini range of returns.
’MDD’: Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).
’ADD’: Average Drawdown of uncompounded cumulative returns.
’DaR’: Drawdown at Risk of uncompounded cumulative returns.
’CDaR’: Conditional Drawdown at Risk of uncompounded cumulative returns.
’EDaR’: Entropic Drawdown at Risk of uncompounded cumulative returns.
’RLDaR’: Relativistic Drawdown at Risk of uncompounded cumulative returns. I recommend only use this function with MOSEK solver.
’UCI’: Ulcer Index of uncompounded cumulative returns.
’MDD_Rel’: Maximum Drawdown of compounded cumulative returns (Calmar Ratio).
’ADD_Rel’: Average Drawdown of compounded cumulative returns.
’CDaR_Rel’: Conditional Drawdown at Risk of compounded cumulative returns.
’EDaR_Rel’: Entropic Drawdown at Risk of compounded cumulative returns.
’RLDaR_Rel’: Relativistic Drawdown at Risk of compounded cumulative returns. I recommend only use this function with MOSEK solver.
’UCI_Rel’: Ulcer Index of compounded cumulative returns.
rf (float, optional) – Risk free rate. The default is 0.
alpha (float, optional) – Significance level of VaR, CVaR, EVaR, RLVaR, DaR, CDaR, EDaR, RLDaR 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, must be between 0 and 1. The default is 0.01.
solver (str, optional) – Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is None.
- 抛出:
ValueError – When the value cannot be calculated.
- 返回:
value – Risk measure of the portfolio.
- 返回类型: