风险函数

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

该模块具有计算几个风险指标的功能,这些指标被资产管理行业和学术界广泛使用。

模块函数

RiskFunctions.MAD(X)[源代码]

Calculate the Mean Absolute Deviation (MAD) of a returns series.

MAD(X)=1Tt=1T|XtE(Xt)|
参数:

X (1d-array) – Returns series, must have Tx1 size.

返回:

value – MAD of a returns series.

返回类型:

float

RiskFunctions.SemiDeviation(X)[源代码]

Calculate the Semi Deviation of a returns series.

SemiDev(X)=[1T1t=1Tmin(XtE(Xt),0)2]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.

返回类型:

float

RiskFunctions.Kurtosis(X)[源代码]

Calculate the Square Root Kurtosis of a returns series.

Kurt(X)=[1Tt=1T(XtE(Xt))4]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.

返回类型:

float

RiskFunctions.SemiKurtosis(X)[源代码]

Calculate the Semi Square Root Kurtosis of a returns series.

SemiKurt(X)=[1Tt=1Tmin(XtE(Xt),0)4]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.

返回类型:

float

RiskFunctions.VaR_Hist(X, alpha=0.05)[源代码]

Calculate the Value at Risk (VaR) of a returns series.

VaRα(X)=inft(0,T){XtR:FX(Xt)>α}
参数:
  • 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.

返回类型:

float

RiskFunctions.CVaR_Hist(X, alpha=0.05)[源代码]

Calculate the Conditional Value at Risk (CVaR) of a returns series.

CVaRα(X)=VaRα(X)+1αTt=1Tmax(XtVaRα(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.

返回类型:

float

RiskFunctions.WR(X)[源代码]

Calculate the Worst Realization (WR) or Worst Scenario of a returns series.

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.

返回类型:

float

RiskFunctions.LPM(X, MAR=0, p=1)[源代码]

Calculate the First or Second Lower Partial Moment of a returns series.

LPM(X,MAR,1)=1Tt=1Tmax(MARXt,0)LPM(X,MAR,2)=[1T1t=1Tmax(MARXt,0)2]12

Where:

MAR is the minimum acceptable return. p is the order of the LPM.

参数:
  • X (1d-array) – Returns series, must have Tx1 size.

  • MAR (float, optional) – Minimum acceptable return. The default is 0.

  • p (float, optional can be {1,2}) – order of the LPM. The default is 1.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – p-th Lower Partial Moment of a returns series.

返回类型:

float

RiskFunctions.Entropic_RM(X, z=1, alpha=0.05)[源代码]

Calculate the Entropic Risk Measure (ERM) of a returns series.

ERMα(X)=zln(MX(z1)α)

Where:

MX(z) is the moment generating function of X.

参数:
  • X (1d-array) – Returns series, must have Tx1 size.

  • theta (float, optional) – Risk aversion parameter, must be greater than zero. The default is 1.

  • alpha (float, optional) – Significance level of EVaR. The default is 0.05.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – ERM of a returns series.

返回类型:

float

RiskFunctions.EVaR_Hist(X, alpha=0.05)[源代码]

Calculate the Entropic Value at Risk (EVaR) of a returns series.

EVaRα(X)=infz>0{zln(MX(z1)α)}

Where:

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

返回类型:

tuple

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{array} ended with \end{split}

Where:

P3α,1α is the power cone 3D.

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

返回类型:

tuple

RiskFunctions.MDD_Abs(X)[源代码]

Calculate the Maximum Drawdown (MDD) of a returns series using uncompounded cumulative returns.

MDD(X)=maxj(0,T)[maxt(0,j)(i=0tXi)i=0jXi]
参数:

X (1d-array) – Returns series, must have Tx1 size.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – MDD of an uncompounded cumulative returns.

返回类型:

float

RiskFunctions.ADD_Abs(X)[源代码]

Calculate the Average Drawdown (ADD) of a returns series using uncompounded cumulative returns.

ADD(X)=1Tj=0T[maxt(0,j)(i=0tXi)i=0jXi]
参数:

X (1d-array) – Returns series, must have Tx1 size.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – ADD of an uncompounded cumulative returns.

返回类型:

float

RiskFunctions.DaR_Abs(X, alpha=0.05)[源代码]

Calculate the Drawdown at Risk (DaR) of a returns series using uncompounded cumulative returns.

DaRα(X)=maxj(0,T){DD(X,j)R:FDD(DD(X,j))<1α}DD(X,j)=maxt(0,j)(i=0tXi)i=0jXi
参数:
  • 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.

返回类型:

float

RiskFunctions.CDaR_Abs(X, alpha=0.05)[源代码]

Calculate the Conditional Drawdown at Risk (CDaR) of a returns series using uncompounded cumulative returns.

CDaRα(X)=DaRα(X)+1αTj=0Tmax[maxt(0,j)(i=0tXi)i=0jXiDaRα(X),0]

Where:

DaRα 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.

返回类型:

float

RiskFunctions.EDaR_Abs(X, alpha=0.05)[源代码]

Calculate the Entropic Drawdown at Risk (EDaR) of a returns series using uncompounded cumulative returns.

EDaRα(X)=infz>0{zln(MDD(X)(z1)α)}DD(X,j)=maxt(0,j)(i=0tXi)i=0jXi
参数:
  • 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.

返回类型:

tuple

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.

RLDaRακ(X)=RLVaRακ(DD(X))DD(X,j)=maxt(0,j)(i=0tXi)i=0jXi
参数:
  • 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.

返回类型:

tuple

RiskFunctions.UCI_Abs(X)[源代码]

Calculate the Ulcer Index (UCI) of a returns series using uncompounded cumulative returns.

UCI(X)=1Tj=0T[maxt(0,j)(i=0tXi)i=0jXi]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.

返回类型:

float

RiskFunctions.MDD_Rel(X)[源代码]

Calculate the Maximum Drawdown (MDD) of a returns series using cumpounded cumulative returns.

MDD(X)=maxj(0,T)[maxt(0,j)(i=0t(1+Xi))i=0j(1+Xi)]
参数:

X (1d-array) – Returns series, must have Tx1 size.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – MDD of a cumpounded cumulative returns.

返回类型:

float

RiskFunctions.ADD_Rel(X)[源代码]

Calculate the Average Drawdown (ADD) of a returns series using cumpounded cumulative returns.

ADD(X)=1Tj=0T[maxt(0,j)(i=0t(1+Xi))i=0j(1+Xi)]
参数:

X (1d-array) – Returns series, must have Tx1 size.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – ADD of a cumpounded cumulative returns.

返回类型:

float

RiskFunctions.DaR_Rel(X, alpha=0.05)[源代码]

Calculate the Drawdown at Risk (DaR) of a returns series using cumpounded cumulative returns.

DaRα(X)=maxj(0,T){DD(X,j)R:FDD(DD(X,j))<1α}DD(X,j)=maxt(0,j)(i=0t(1+Xi))i=0j(1+Xi)
参数:
  • 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.

返回类型:

float

RiskFunctions.CDaR_Rel(X, alpha=0.05)[源代码]

Calculate the Conditional Drawdown at Risk (CDaR) of a returns series using cumpounded cumulative returns.

CDaRα(X)=DaRα(X)+1αTi=0Tmax[maxt(0,T)(i=0t(1+Xi))i=0j(1+Xi)DaRα(X),0]

Where:

DaRα 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.

返回类型:

float

RiskFunctions.EDaR_Rel(X, alpha=0.05)[源代码]

Calculate the Entropic Drawdown at Risk (EDaR) of a returns series using cumpounded cumulative returns.

EDaRα(X)=infz>0{zln(MDD(X)(z1)α)}DD(X,j)=maxt(0,j)(i=0t(1+Xi))i=0j(1+Xi)
参数:
  • 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.

返回类型:

tuple

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.

RLDaRακ(X)=RLVaRακ(DD(X))DD(X,j)=maxt(0,j)(i=0t(1+Xi))i=0j(1+Xi)
参数:
  • 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.

返回类型:

tuple

RiskFunctions.UCI_Rel(X)[源代码]

Calculate the Ulcer Index (UCI) of a returns series using cumpounded cumulative returns.

UCI(X)=1Tj=0T[maxt(0,j)(i=0t(1+Xi))i=0j(1+Xi)]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.

返回类型:

float

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.

返回类型:

float

RiskFunctions.TG(X, alpha=0.05, a_sim=100)[源代码]

Calculate the Tail Gini of a returns series.

参数:
  • X (1d-array) – Returns series, must have Tx1 size.

  • alpha (float, optional) – Significance level of Tail Gini. The default is 0.05.

  • a_sim (float, optional) – Number of CVaRs used to approximate Tail Gini. The default is 100.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – Ulcer Index of a cumpounded cumulative returns.

返回类型:

float

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.

返回类型:

float

RiskFunctions.CVRG(X, alpha=0.05, beta=None)[源代码]

Calculate the CVaR range of a returns series.

参数:
  • X (1d-array) – Returns series, must have Tx1 size.

  • alpha (float, optional) – Significance level of CVaR of losses. The default is 0.05.

  • beta (float, optional) – Significance level of CVaR of gains. If None it duplicates alpha value. The default is None.

抛出:

ValueError – When the value cannot be calculated.

返回:

value – Ulcer Index of a cumpounded cumulative returns.

返回类型:

float

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.

返回类型:

float

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.

返回类型:

float

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.

返回类型:

float

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.

返回类型:

float

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.

Sharpe(X)=E(X)rfϕ(X)

Where:

X is the vector of portfolio returns.

rf is the risk free rate, when the risk measure is

LPM uses instead of rf the MAR.

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

返回类型:

float

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.

返回类型:

float