RiskContributionAnalysis
- class qf_lib.common.timeseries_analysis.risk_contribution_analysis.RiskContributionAnalysis[source]
Bases:
object
Calculates risk contribution metrics.
Methods:
By minimising this function it is possible to calculate Equal Risk Contribution Portfolio.
get_risk_contribution
(factors_rets, ...)Calculates risk contribution of different factors to the portfolio.
get_risk_contribution_optimised
(assets_rets, ...)Calculates risk contribution of each asset of the portfolio.
Tells whether each asset has an equal risk contribution to the portfolio.
- classmethod get_distance_to_equal_risk_contrib(assets_returns_covariance: QFDataFrame, weights_of_assets: QFSeries) float [source]
By minimising this function it is possible to calculate Equal Risk Contribution Portfolio. It has better numerical properties than simple approach ( riskContribution - mean(riskContribution) ) Details: http://www.thierry-roncalli.com/download/erc-slides.pdf
- Parameters:
assets_returns_covariance – covariance matrix for assets returns data frame
weights_of_assets – weight of each asset in the portfolio. It’s indexed with names of assets.
- Return type:
L2 (euclidean) distance from equal risk distribution
- classmethod get_risk_contribution(factors_rets: SimpleReturnsDataFrame, weigths_of_assets: QFSeries, portfolio_rets: SimpleReturnsSeries) QFSeries [source]
Calculates risk contribution of different factors to the portfolio. Risk is defined as volatility. Uses x-sigma-rho formula (MSCI Bara paper).
- Parameters:
factors_rets – dataframe consisted of returns for different assets
weigths_of_assets – series of weights of each asset. It’s indexed with names of assets.
portfolio_rets – return of the whole portfolio
- Returns:
Series of risk contributions (one for each asset) to the portfolio. It’s indexed with names of assets.
- Return type:
pandas.Series
- classmethod get_risk_contribution_optimised(assets_rets: SimpleReturnsDataFrame, weights_of_assets: QFSeries) QFSeries [source]
Calculates risk contribution of each asset of the portfolio.
- Parameters:
assets_rets – returns of assets building the portfolio (each assets in a separate column)
weights_of_assets – Series of weights (one for each asset). It’s indexed with names of assets.
- Return type:
Series of risk contributions (one for each asset). It’s indexed with names of assets
- classmethod is_equal_risk_contribution(returns_covariance: QFDataFrame, weights_of_assets: QFSeries) bool [source]
Tells whether each asset has an equal risk contribution to the portfolio.
- Parameters:
returns_covariance – DataFrame which is a covariance matrix. Columns and rows are both indexed with names of assets.
weights_of_assets – Series of weights (one weight for each asset). It’s indexed with names of assets.
- Return type:
True if each asset has and equal risk contribution. False – otherwise.