Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diversification_ratio not tested #1388

Open
ricardoV94 opened this issue Jan 16, 2025 · 0 comments
Open

diversification_ratio not tested #1388

ricardoV94 opened this issue Jan 16, 2025 · 0 comments
Labels
MMM optimizer question Further information is requested tests

Comments

@ricardoV94
Copy link
Contributor

ricardoV94 commented Jan 16, 2025

The helper is not tested directly (_covariance_matrix is). It's unclear how a user was supposed to use as part of an optimization cost because it requires 2D samples, whereas the optimizer was always giving 1D samples before #1357

def diversification_ratio(
samples: pt.TensorVariable, budgets: pt.TensorVariable
) -> pt.TensorVariable:
R"""
Calculate the Diversification Ratio of a portfolio to evaluate risk distribution.
The Diversification Ratio measures the effectiveness of diversification by comparing
the weighted average volatility of individual assets to the overall portfolio volatility.
A higher ratio indicates better diversification, as it reflects lower correlations among
assets, leading to reduced portfolio risk.
The Diversification Ratio is calculated as:
.. math::
DR = \frac{\\sum_{i=1}^{n} w_i \\cdot \\sigma_i}{\\sigma_p}
where:
- :math:`w_i` is the weight of asset \\( i \\)
- :math:`\\sigma_i` is the volatility (standard deviation) of asset \\( i \\)
- :math:`\\sigma_p` is the volatility of the portfolio
Parameters
----------
samples : pt.TensorVariable
2D PyTensor tensor variable where each column represents the returns of an asset.
budgets : pt.TensorVariable
1D PyTensor tensor variable representing the investment amounts in each asset.
Returns
-------
pt.TensorVariable
Diversification Ratio.
This ratio provides insight into how individual asset volatilities and their correlations
contribute to the overall portfolio risk.
References
----------
- Choueifaty, Y., & Coignard, Y. (2008). Toward Maximum Diversification. *Journal of Portfolio Management*.
- Meucci, A. (2009). Managing Diversification. *Risk*, 22(5), 74-79.
"""
weights = budgets / pt.sum(budgets)
individual_volatilities = pt.std(samples, axis=0, ddof=1)
cov_matrix = _covariance_matrix(samples)
portfolio_volatility = pt.sqrt(pt.dot(weights, pt.dot(cov_matrix, weights.T)))
weighted_avg_volatility = pt.sum(weights * individual_volatilities)
diversification_ratio = weighted_avg_volatility / portfolio_volatility
return diversification_ratio

CC @cetagostini

@ricardoV94 ricardoV94 added question Further information is requested MMM tests optimizer labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MMM optimizer question Further information is requested tests
Projects
None yet
Development

No branches or pull requests

1 participant