Skip to content

Commit

Permalink
feat(measure): effective number of assets [skip ci]
Browse files Browse the repository at this point in the history
* Implemented effective number of assets in the _measures as described in issue #13. Needs to review in the metrics enum.

* Update src/skfolio/measures/_measures.py

Fixed docstring with proper references

Co-authored-by: Hugo Delatte <delatte.hugo@gmail.com>

---------

Co-authored-by: carlo <c.nicolini@ipazia.com>
Co-authored-by: Hugo Delatte <delatte.hugo@gmail.com>
  • Loading branch information
3 people committed Jan 22, 2024
1 parent 7f98efb commit 62692ef
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/skfolio/measures/_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,28 @@ def gini_mean_difference(returns: np.ndarray) -> float:
"""
w = owa_gmd_weights(len(returns))
return float(w @ np.sort(returns, axis=0))


def effective_number_assets(weights: np.ndarray) -> float:
r"""
Computes the effective number of assets, defined as the inverse of the Herfindahl index [1]_:
.. math:: N_{eff} = \frac{1}{\Vert w \Vert_{2}^{2}}
It quantifies portfolio concentration, with a higher value indicating a more diversified portfolio.
Parameters
----------
weights : ndarray of shape (n_assets,)
Weights of the assets.
Returns
-------
value : float
Effective number of assets.
References
----------
.. [1] "Banking and Financial Institutions Law in a Nutshell".
Lovett, William Anthony (1988)
"""
return 1.0/(np.power(weights, 2).sum())

0 comments on commit 62692ef

Please sign in to comment.