skfolio 0.0.10__tar.gz → 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. {skfolio-0.0.10/src/skfolio.egg-info → skfolio-0.1.0}/PKG-INFO +18 -7
  2. {skfolio-0.0.10 → skfolio-0.1.0}/README.rst +16 -5
  3. {skfolio-0.0.10 → skfolio-0.1.0}/pyproject.toml +2 -2
  4. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/cluster/_hierarchical.py +5 -4
  5. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/datasets/_base.py +5 -0
  6. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/distance/_base.py +1 -0
  7. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/distance/_distance.py +1 -0
  8. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/exceptions.py +1 -0
  9. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/measures/_enums.py +1 -0
  10. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/measures/_measures.py +28 -0
  11. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/metrics/_scorer.py +5 -0
  12. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/model_selection/_combinatorial.py +5 -0
  13. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/model_selection/_validation.py +5 -0
  14. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/model_selection/_walk_forward.py +6 -1
  15. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/moments/covariance/_base.py +7 -0
  16. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/moments/covariance/_covariance.py +7 -0
  17. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/moments/expected_returns/_base.py +4 -0
  18. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/moments/expected_returns/_expected_returns.py +5 -0
  19. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/_base.py +8 -0
  20. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/cluster/_nco.py +5 -0
  21. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/cluster/hierarchical/_base.py +4 -0
  22. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/cluster/hierarchical/_herc.py +3 -1
  23. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/cluster/hierarchical/_hrp.py +4 -0
  24. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/convex/_base.py +4 -1
  25. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/convex/_distributionally_robust.py +1 -0
  26. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/convex/_maximum_diversification.py +2 -1
  27. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/convex/_mean_risk.py +5 -2
  28. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/convex/_risk_budgeting.py +3 -0
  29. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/ensemble/_base.py +4 -0
  30. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/ensemble/_stacking.py +4 -0
  31. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/population/_population.py +1 -0
  32. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/portfolio/_base.py +9 -9
  33. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/portfolio/_multi_period_portfolio.py +9 -5
  34. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/portfolio/_portfolio.py +3 -2
  35. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/pre_selection/_pre_selection.py +1 -0
  36. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/preprocessing/_returns.py +2 -1
  37. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/prior/_base.py +1 -0
  38. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/prior/_black_litterman.py +4 -0
  39. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/prior/_empirical.py +2 -0
  40. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/prior/_factor_model.py +5 -0
  41. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/typing.py +1 -0
  42. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/uncertainty_set/_base.py +1 -0
  43. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/uncertainty_set/_bootstrap.py +5 -0
  44. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/uncertainty_set/_empirical.py +5 -0
  45. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/utils/bootstrap.py +3 -0
  46. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/utils/equations.py +1 -0
  47. skfolio-0.1.0/src/skfolio/utils/fixes/__init__.py +3 -0
  48. skfolio-0.1.0/src/skfolio/utils/fixes/_dendrogram.py +389 -0
  49. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/utils/sorting.py +1 -0
  50. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/utils/stats.py +4 -1
  51. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/utils/tools.py +4 -0
  52. {skfolio-0.0.10 → skfolio-0.1.0/src/skfolio.egg-info}/PKG-INFO +18 -7
  53. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio.egg-info/SOURCES.txt +3 -1
  54. {skfolio-0.0.10 → skfolio-0.1.0}/LICENSE +0 -0
  55. {skfolio-0.0.10 → skfolio-0.1.0}/MANIFEST.in +0 -0
  56. {skfolio-0.0.10 → skfolio-0.1.0}/setup.cfg +0 -0
  57. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/__init__.py +0 -0
  58. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/cluster/__init__.py +0 -0
  59. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/datasets/__init__.py +0 -0
  60. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/datasets/data/__init__.py +0 -0
  61. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/datasets/data/factors_dataset.csv.gz +0 -0
  62. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/datasets/data/sp500_dataset.csv.gz +0 -0
  63. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/datasets/data/sp500_index.csv.gz +0 -0
  64. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/distance/__init__.py +0 -0
  65. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/measures/__init__.py +0 -0
  66. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/metrics/__init__.py +0 -0
  67. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/model_selection/__init__.py +0 -0
  68. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/moments/__init__.py +0 -0
  69. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/moments/covariance/__init__.py +0 -0
  70. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/moments/expected_returns/__init__.py +0 -0
  71. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/__init__.py +0 -0
  72. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/cluster/__init__.py +0 -0
  73. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/cluster/hierarchical/__init__.py +0 -0
  74. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/convex/__init__.py +0 -0
  75. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/ensemble/__init__.py +0 -0
  76. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/naive/__init__.py +0 -0
  77. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/optimization/naive/_naive.py +0 -0
  78. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/population/__init__.py +0 -0
  79. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/portfolio/__init__.py +0 -0
  80. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/pre_selection/__init__.py +0 -0
  81. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/preprocessing/__init__.py +0 -0
  82. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/prior/__init__.py +0 -0
  83. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/uncertainty_set/__init__.py +0 -0
  84. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio/utils/__init__.py +0 -0
  85. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio.egg-info/dependency_links.txt +0 -0
  86. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio.egg-info/requires.txt +0 -0
  87. {skfolio-0.0.10 → skfolio-0.1.0}/src/skfolio.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: skfolio
3
- Version: 0.0.10
3
+ Version: 0.1.0
4
4
  Summary: Portfolio optimization built on top of scikit-learn
5
5
  Author-email: Hugo Delatte <delatte.hugo@gmail.com>
6
6
  Maintainer-email: Hugo Delatte <delatte.hugo@gmail.com>
@@ -37,7 +37,7 @@ Project-URL: API Reference, https://www.skfolio.org/api_reference.html
37
37
  Project-URL: Documentation, https://www.skfolio.org
38
38
  Project-URL: Tutorials, https://www.skfolio.org
39
39
  Project-URL: Repository, https://github.com/skfolio/skfolio
40
- Keywords: portfolio,optimization,optimisation,finance,asset,allocation,quantitative,quant,investment,startegy,machine-learning,scikit-learn,data-mining,data-science
40
+ Keywords: portfolio,optimization,optimisation,finance,asset,allocation,quantitative,quant,investment,strategy,machine-learning,scikit-learn,data-mining,data-science
41
41
  Classifier: Intended Audience :: Developers
42
42
  Classifier: Intended Audience :: Science/Research
43
43
  Classifier: Intended Audience :: Financial and Insurance Industry
@@ -86,12 +86,12 @@ Requires-Dist: sphinx-favicon; extra == "docs"
86
86
 
87
87
  .. -*- mode: rst -*-
88
88
 
89
- |Licence|_ |Codecov|_ |Black|_ |PythonVersion|_ |PyPi|_ |CI/CD|_
89
+ |Licence|_ |Codecov|_ |Black|_ |PythonVersion|_ |PyPi|_ |CI/CD|_ |Downloads|_ |Ruff|_ |Contribution|_ |Website|_
90
90
 
91
91
  .. |Licence| image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
92
92
  .. _Licence: https://github.com/skfolio/skfolio/blob/main/LICENSE
93
93
 
94
- .. |Codecov| image:: https://codecov.io/gh/skfolio/skfolio/branch/main/graph/badge.svg
94
+ .. |Codecov| image:: https://codecov.io/gh/skfolio/skfolio/graph/badge.svg?token=KJ0SE4LHPV
95
95
  .. _Codecov: https://codecov.io/gh/skfolio/skfolio
96
96
 
97
97
  .. |PythonVersion| image:: https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue
@@ -106,6 +106,17 @@ Requires-Dist: sphinx-favicon; extra == "docs"
106
106
  .. |CI/CD| image:: https://img.shields.io/github/actions/workflow/status/skfolio/skfolio/release.yml?logo=github
107
107
  .. _CI/CD: https://github.com/skfolio/skfolio/raw/main/LICENSE
108
108
 
109
+ .. |Downloads| image:: https://static.pepy.tech/badge/skfolio
110
+ .. _Downloads: https://pepy.tech/project/skfolio
111
+
112
+ .. |Ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
113
+ .. _Ruff: https://github.com/astral-sh/ruff
114
+
115
+ .. |Contribution| image:: https://img.shields.io/badge/Contributions-Welcome-blue
116
+ .. _Contribution: https://github.com/skfolio/skfolio/blob/main/CONTRIBUTING.md
117
+
118
+ .. |Website| image:: https://img.shields.io/website-up-down-53cc0d-red/http/skfolio.org
119
+ .. _Website: https://skfolio.org
109
120
 
110
121
  .. |PythonMinVersion| replace:: 3.10
111
122
  .. |NumpyMinVersion| replace:: 1.23.4
@@ -120,7 +131,7 @@ Requires-Dist: sphinx-favicon; extra == "docs"
120
131
  ===============
121
132
  |icon| skfolio
122
133
  ===============
123
- .. |icon| image:: https://raw.githubusercontent.com/skfolio/skfolio/master/docs/_static/favicon.png
134
+ .. |icon| image:: https://raw.githubusercontent.com/skfolio/skfolio/master/docs/_static/logo_animate.svg
124
135
  :width: 100
125
136
  :alt: skfolio documentation
126
137
  :target: https://skfolio.org/
@@ -466,7 +477,7 @@ Randomized Search of the L2 Norm
466
477
 
467
478
  randomized_search = RandomizedSearchCV(
468
479
  estimator=MeanRisk(),
469
- cv=WalkForward(train_size=255, test_size=60),
480
+ cv=WalkForward(train_size=252, test_size=60),
470
481
  param_distributions={
471
482
  "l2_coef": loguniform(1e-3, 1e-1),
472
483
  },
@@ -635,7 +646,7 @@ If you use `skfolio` in a scientific publication, we would appreciate citations:
635
646
  Bibtex entry::
636
647
 
637
648
  @misc{skfolio,
638
- author = {Hugo Delatte},
649
+ author = {Hugo Delatte, Carlo Nicolini},
639
650
  title = {skfolio},
640
651
  year = {2023},
641
652
  url = {https://github.com/skfolio/skfolio}
@@ -1,11 +1,11 @@
1
1
  .. -*- mode: rst -*-
2
2
 
3
- |Licence|_ |Codecov|_ |Black|_ |PythonVersion|_ |PyPi|_ |CI/CD|_
3
+ |Licence|_ |Codecov|_ |Black|_ |PythonVersion|_ |PyPi|_ |CI/CD|_ |Downloads|_ |Ruff|_ |Contribution|_ |Website|_
4
4
 
5
5
  .. |Licence| image:: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
6
6
  .. _Licence: https://github.com/skfolio/skfolio/blob/main/LICENSE
7
7
 
8
- .. |Codecov| image:: https://codecov.io/gh/skfolio/skfolio/branch/main/graph/badge.svg
8
+ .. |Codecov| image:: https://codecov.io/gh/skfolio/skfolio/graph/badge.svg?token=KJ0SE4LHPV
9
9
  .. _Codecov: https://codecov.io/gh/skfolio/skfolio
10
10
 
11
11
  .. |PythonVersion| image:: https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue
@@ -20,6 +20,17 @@
20
20
  .. |CI/CD| image:: https://img.shields.io/github/actions/workflow/status/skfolio/skfolio/release.yml?logo=github
21
21
  .. _CI/CD: https://github.com/skfolio/skfolio/raw/main/LICENSE
22
22
 
23
+ .. |Downloads| image:: https://static.pepy.tech/badge/skfolio
24
+ .. _Downloads: https://pepy.tech/project/skfolio
25
+
26
+ .. |Ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
27
+ .. _Ruff: https://github.com/astral-sh/ruff
28
+
29
+ .. |Contribution| image:: https://img.shields.io/badge/Contributions-Welcome-blue
30
+ .. _Contribution: https://github.com/skfolio/skfolio/blob/main/CONTRIBUTING.md
31
+
32
+ .. |Website| image:: https://img.shields.io/website-up-down-53cc0d-red/http/skfolio.org
33
+ .. _Website: https://skfolio.org
23
34
 
24
35
  .. |PythonMinVersion| replace:: 3.10
25
36
  .. |NumpyMinVersion| replace:: 1.23.4
@@ -34,7 +45,7 @@
34
45
  ===============
35
46
  |icon| skfolio
36
47
  ===============
37
- .. |icon| image:: https://raw.githubusercontent.com/skfolio/skfolio/master/docs/_static/favicon.png
48
+ .. |icon| image:: https://raw.githubusercontent.com/skfolio/skfolio/master/docs/_static/logo_animate.svg
38
49
  :width: 100
39
50
  :alt: skfolio documentation
40
51
  :target: https://skfolio.org/
@@ -380,7 +391,7 @@ Randomized Search of the L2 Norm
380
391
 
381
392
  randomized_search = RandomizedSearchCV(
382
393
  estimator=MeanRisk(),
383
- cv=WalkForward(train_size=255, test_size=60),
394
+ cv=WalkForward(train_size=252, test_size=60),
384
395
  param_distributions={
385
396
  "l2_coef": loguniform(1e-3, 1e-1),
386
397
  },
@@ -549,7 +560,7 @@ If you use `skfolio` in a scientific publication, we would appreciate citations:
549
560
  Bibtex entry::
550
561
 
551
562
  @misc{skfolio,
552
- author = {Hugo Delatte},
563
+ author = {Hugo Delatte, Carlo Nicolini},
553
564
  title = {skfolio},
554
565
  year = {2023},
555
566
  url = {https://github.com/skfolio/skfolio}
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "skfolio"
7
- version = "0.0.10"
7
+ version = "0.1.0"
8
8
  maintainers = [
9
9
  { name = "Hugo Delatte", email = "delatte.hugo@gmail.com" },
10
10
  ]
@@ -33,7 +33,7 @@ keywords = [
33
33
  "quantitative",
34
34
  "quant",
35
35
  "investment",
36
- "startegy",
36
+ "strategy",
37
37
  "machine-learning",
38
38
  "scikit-learn",
39
39
  "data-mining",
@@ -1,5 +1,6 @@
1
1
  """Hierarchical Clustering estimators."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
5
6
 
@@ -7,13 +8,13 @@ from enum import auto
7
8
 
8
9
  import numpy as np
9
10
  import numpy.typing as npt
10
- import plotly.figure_factory as ff
11
11
  import plotly.graph_objects as go
12
12
  import scipy.cluster.hierarchy as sch
13
13
  import scipy.spatial.distance as scd
14
14
  import sklearn.base as skb
15
15
  import sklearn.utils.validation as skv
16
16
 
17
+ from skfolio.utils.fixes import create_dendrogram
17
18
  from skfolio.utils.stats import assert_is_distance, compute_optimal_n_clusters
18
19
  from skfolio.utils.tools import AutoEnum, default_asset_names
19
20
 
@@ -244,7 +245,7 @@ class HierarchicalClustering(skb.ClusterMixin, skb.BaseEstimator):
244
245
  asset_names = default_asset_names(n_assets=n_assets)
245
246
 
246
247
  if not heatmap:
247
- fig = ff.create_dendrogram(
248
+ fig = create_dendrogram(
248
249
  np.ones(1),
249
250
  distfun=lambda x: None,
250
251
  linkagefun=lambda x: linkage_matrix,
@@ -263,7 +264,7 @@ class HierarchicalClustering(skb.ClusterMixin, skb.BaseEstimator):
263
264
  return fig
264
265
 
265
266
  # Initialize figure by creating upper dendrogram
266
- fig = ff.create_dendrogram(
267
+ fig = create_dendrogram(
267
268
  np.ones(1),
268
269
  orientation="bottom",
269
270
  distfun=lambda x: None,
@@ -276,7 +277,7 @@ class HierarchicalClustering(skb.ClusterMixin, skb.BaseEstimator):
276
277
  fig["data"][i]["yaxis"] = "y2"
277
278
 
278
279
  # Create Side Dendrogram
279
- side_dendrogram = ff.create_dendrogram(
280
+ side_dendrogram = create_dendrogram(
280
281
  np.ones(1),
281
282
  orientation="right",
282
283
  distfun=lambda x: None,
@@ -1,7 +1,12 @@
1
1
  """Datasets module."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-portfolio, Copyright (c) 2022, Carlo Nicolini, Licensed under MIT Licence.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
9
+ # Grisel Licensed under BSD 3 clause.
5
10
 
6
11
  import gzip
7
12
  import os
@@ -1,5 +1,6 @@
1
1
  """Base Distance Estimators"""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
5
6
 
@@ -1,5 +1,6 @@
1
1
  """Distance Estimators"""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
5
6
 
@@ -3,6 +3,7 @@ The :mod:`skfolio.exceptions` module includes all custom warnings and error
3
3
  classes used across skfolio.
4
4
  """
5
5
 
6
+ # Copyright (c) 2023
6
7
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
7
8
  # License: BSD 3 clause
8
9
 
@@ -1,5 +1,6 @@
1
1
  """Module that includes all Measures enums used across `skfolio`."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
5
6
 
@@ -1,7 +1,10 @@
1
1
  """Module that includes all Measures functions used across `skfolio`."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Gini mean difference and OWA GMD weights features are derived
7
+ # from Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
5
8
 
6
9
 
7
10
  import numpy as np
@@ -605,3 +608,28 @@ def gini_mean_difference(returns: np.ndarray) -> float:
605
608
  """
606
609
  w = owa_gmd_weights(len(returns))
607
610
  return float(w @ np.sort(returns, axis=0))
611
+
612
+
613
+ def effective_number_assets(weights: np.ndarray) -> float:
614
+ r"""
615
+ Computes the effective number of assets, defined as the inverse of the Herfindahl index [1]_:
616
+ .. math:: N_{eff} = \frac{1}{\Vert w \Vert_{2}^{2}}
617
+
618
+ It quantifies portfolio concentration, with a higher value indicating a more diversified portfolio.
619
+
620
+ Parameters
621
+ ----------
622
+ weights : ndarray of shape (n_assets,)
623
+ Weights of the assets.
624
+
625
+ Returns
626
+ -------
627
+ value : float
628
+ Effective number of assets.
629
+
630
+ References
631
+ ----------
632
+ .. [1] "Banking and Financial Institutions Law in a Nutshell".
633
+ Lovett, William Anthony (1988)
634
+ """
635
+ return 1.0 / (np.power(weights, 2).sum())
@@ -1,7 +1,12 @@
1
1
  """Scorer module"""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-portfolio, Copyright (c) 2022, Carlo Nicolini, Licensed under MIT Licence.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
9
+ # Grisel Licensed under BSD 3 clause.
5
10
 
6
11
  from collections.abc import Callable
7
12
 
@@ -1,7 +1,12 @@
1
1
  """Combinatorial module"""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-portfolio, Copyright (c) 2022, Carlo Nicolini, Licensed under MIT Licence.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
9
+ # Grisel Licensed under BSD 3 clause.
5
10
 
6
11
  import itertools
7
12
  import math
@@ -1,7 +1,12 @@
1
1
  """Model validation module."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-portfolio, Copyright (c) 2022, Carlo Nicolini, Licensed under MIT Licence.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
9
+ # Grisel Licensed under BSD 3 clause.
5
10
 
6
11
  import numpy as np
7
12
  import numpy.typing as npt
@@ -1,7 +1,12 @@
1
1
  """Walk Forward cross-validator"""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-portfolio, Copyright (c) 2022, Carlo Nicolini, Licensed under MIT Licence.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
9
+ # Grisel Licensed under BSD 3 clause.
5
10
 
6
11
  from collections.abc import Iterator
7
12
 
@@ -39,7 +44,7 @@ class WalkForward(skm.BaseCrossValidator):
39
44
 
40
45
  reduce_test : bool, default=False
41
46
  If this is set to True, the last train/test split will be returned even if the
42
- test set is partial (if it constains less observations than `test_size`),
47
+ test set is partial (if it contains less observations than `test_size`),
43
48
  otherwise it will be ignored.
44
49
  The default is `False`
45
50
 
@@ -1,5 +1,12 @@
1
1
  """Base Covariance Estimators."""
2
2
 
3
+ # Copyright (c) 2023
4
+ # Author: Hugo Delatte <delatte.hugo@gmail.com>
5
+ # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
8
+ # Grisel Licensed under BSD 3 clause.
9
+
3
10
  from abc import ABC, abstractmethod
4
11
 
5
12
  import numpy as np
@@ -1,5 +1,12 @@
1
1
  """Covariance Estimators."""
2
2
 
3
+ # Copyright (c) 2023
4
+ # Author: Hugo Delatte <delatte.hugo@gmail.com>
5
+ # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
8
+ # Grisel Licensed under BSD 3 clause.
9
+
3
10
  import numpy as np
4
11
  import numpy.typing as npt
5
12
  import pandas as pd
@@ -1,7 +1,11 @@
1
1
  """Base Expected returns estimators."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
8
+ # Grisel Licensed under BSD 3 clause.
5
9
 
6
10
  from abc import ABC, abstractmethod
7
11
 
@@ -1,7 +1,12 @@
1
1
  """Expected returns estimators."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
9
+ # Grisel Licensed under BSD 3 clause.
5
10
 
6
11
  from enum import auto
7
12
 
@@ -14,6 +14,14 @@ from skfolio.measures import RatioMeasure
14
14
  from skfolio.population import Population
15
15
  from skfolio.portfolio import Portfolio
16
16
 
17
+ # Copyright (c) 2023
18
+ # Author: Hugo Delatte <delatte.hugo@gmail.com>
19
+ # License: BSD 3 clause
20
+ # Implementation derived from:
21
+ # scikit-portfolio, Copyright (c) 2022, Carlo Nicolini, Licensed under MIT Licence.
22
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
23
+ # Grisel Licensed under BSD 3 clause.
24
+
17
25
 
18
26
  class BaseOptimization(skb.BaseEstimator, ABC):
19
27
  """Base class for all portfolio optimizations in skfolio.
@@ -1,7 +1,12 @@
1
1
  """Nested Clusters Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
9
+ # Grisel Licensed under BSD 3 clause.
5
10
 
6
11
  from copy import deepcopy
7
12
 
@@ -1,7 +1,11 @@
1
1
  """Base Hierarchical Clustering Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
8
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
5
9
 
6
10
  from abc import ABC, abstractmethod
7
11
 
@@ -1,8 +1,10 @@
1
1
  """Hierarchical Equal Risk Contribution estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
5
-
6
+ # The risk measure generalization and constraint features are derived
7
+ # from Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
6
8
 
7
9
  import numpy as np
8
10
  import numpy.typing as npt
@@ -1,7 +1,11 @@
1
1
  """Hierarchical Risk Parity Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # The risk measure generalization and constraint features are derived
7
+ # from Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
8
+
5
9
 
6
10
  import numpy as np
7
11
  import numpy.typing as npt
@@ -1,7 +1,10 @@
1
1
  """Base Convex Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # The optimization features are derived
7
+ # from Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
5
8
 
6
9
  import warnings
7
10
  from abc import ABC, abstractmethod
@@ -43,7 +46,7 @@ class ObjectiveFunction(AutoEnum):
43
46
  MAXIMIZE_UTILITY : str
44
47
  Maximize the utility :math:`w^T\mu - \lambda \times risk(w)`.
45
48
 
46
- MAXIMIZE_UTILITY : str
49
+ MAXIMIZE_RATIO : str
47
50
  Maximize the ratio :math:`\frac{w^T\mu - R_{f}}{risk(w)}`.
48
51
  """
49
52
 
@@ -1,5 +1,6 @@
1
1
  """Distributionally Robust CVaR Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
5
6
 
@@ -1,5 +1,6 @@
1
1
  """Maximum Diversification Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
5
6
 
@@ -21,7 +22,7 @@ class MaximumDiversification(MeanRisk):
21
22
 
22
23
  It is a special case of the :class:`~skfolio.optimization.MeanRisk` estimator where
23
24
  the expected return from the objective function is replaced by the weighted
24
- volatilies.
25
+ volatilities.
25
26
 
26
27
  Parameters
27
28
  ----------
@@ -1,7 +1,10 @@
1
1
  """Mean Risk Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # The optimization features are derived
7
+ # from Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
5
8
 
6
9
  import cvxpy as cp
7
10
  import numpy as np
@@ -931,7 +934,7 @@ class MeanRisk(ConvexOptimization):
931
934
  case ObjectiveFunction.MAXIMIZE_RATIO:
932
935
  if expected_return.is_affine():
933
936
  # Charnes-Cooper's variable transformation for Fractional
934
- # Programing problem :Max(f1/f2) with f2 linear
937
+ # Programming problem :Max(f1/f2) with f2 linear
935
938
  constraints += [
936
939
  expected_return * self._scale_constraints
937
940
  - cp.Constant(self.risk_free_rate)
@@ -941,7 +944,7 @@ class MeanRisk(ConvexOptimization):
941
944
  ]
942
945
  else:
943
946
  # Schaible's generalization of Charnes-Cooper's variable
944
- # transformation for Fractional Programing problem :Max(f1/f2)
947
+ # transformation for Fractional Programming problem :Max(f1/f2)
945
948
  # with f1 concave instead of linear: Schaible,"Parameter-free
946
949
  # Convex Equivalent and Dual Programs of Fractional Programming
947
950
  # Problems".
@@ -1,7 +1,10 @@
1
1
  """Risk Budgeting Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # The optimization features are derived
7
+ # from Riskfolio-Lib, Copyright (c) 2020-2023, Dany Cajas, Licensed under BSD 3 clause.
5
8
 
6
9
  import cvxpy as cp
7
10
  import numpy as np
@@ -2,8 +2,12 @@
2
2
  Follow same implementation as Base composition from sklearn
3
3
  """
4
4
 
5
+ # Copyright (c) 2023
5
6
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
6
7
  # License: BSD 3 clause
8
+ # Implementation derived from:
9
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
10
+ # Grisel Licensed under BSD 3 clause.
7
11
 
8
12
  from abc import ABC, abstractmethod
9
13
  from contextlib import suppress
@@ -1,7 +1,11 @@
1
1
  """Stacking Optimization estimator."""
2
2
 
3
+ # Copyright (c) 2023
3
4
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
4
5
  # License: BSD 3 clause
6
+ # Implementation derived from:
7
+ # scikit-learn, Copyright (c) 2007-2010 David Cournapeau, Fabian Pedregosa, Olivier
8
+ # Grisel Licensed under BSD 3 clause.
5
9
 
6
10
  from copy import deepcopy
7
11
 
@@ -2,6 +2,7 @@
2
2
  A population is a collection of portfolios.
3
3
  """
4
4
 
5
+ # Copyright (c) 2023
5
6
  # Author: Hugo Delatte <delatte.hugo@gmail.com>
6
7
  # License: BSD 3 clause
7
8