skfolio 0.8.0__py3-none-any.whl → 0.9.0__py3-none-any.whl

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.
@@ -813,8 +813,7 @@ class Population(list):
813
813
  )
814
814
  + "<extra></extra>",
815
815
  colorbar=dict(
816
- title=str(z),
817
- titleside="top",
816
+ title=dict(text=str(z), side="top"),
818
817
  tickformat=",.2%" if not z.is_ratio else None,
819
818
  ),
820
819
  )
@@ -1,6 +1,7 @@
1
1
  """Pre Selection module."""
2
2
 
3
3
  from skfolio.pre_selection._drop_correlated import DropCorrelated
4
+ from skfolio.pre_selection._drop_zero_variance import DropZeroVariance
4
5
  from skfolio.pre_selection._select_complete import SelectComplete
5
6
  from skfolio.pre_selection._select_k_extremes import SelectKExtremes
6
7
  from skfolio.pre_selection._select_non_dominated import SelectNonDominated
@@ -8,6 +9,7 @@ from skfolio.pre_selection._select_non_expiring import SelectNonExpiring
8
9
 
9
10
  __all__ = [
10
11
  "DropCorrelated",
12
+ "DropZeroVariance",
11
13
  "SelectComplete",
12
14
  "SelectKExtremes",
13
15
  "SelectNonDominated",
@@ -0,0 +1,75 @@
1
+ """Pre-selection DropZeroVariance module."""
2
+
3
+ # Copyright (c) 2025
4
+ # Author: Vincent Maladiere <maladiere.vincent@gmail.com>
5
+ # SPDX-License-Identifier: BSD-3-Clause
6
+
7
+ import numpy as np
8
+ import numpy.typing as npt
9
+ import sklearn.base as skb
10
+ import sklearn.feature_selection as skf
11
+ import sklearn.utils.validation as skv
12
+
13
+
14
+ class DropZeroVariance(skf.SelectorMixin, skb.BaseEstimator):
15
+ """Transformer for dropping assets with near-zero variance.
16
+
17
+ On short windows, some assets can experience a near-zero variance, making
18
+ the covariance matrix improper for optimization. This simple transformer drops
19
+ assets whose variance is below some threshold.
20
+
21
+ Parameters
22
+ ----------
23
+ threshold : float, default=1e-8
24
+ Minimum variance threshold. The default value is 1e-8. For daily asset returns,
25
+ this value filters out assets whose daily standard deviation is below 1e-4
26
+ (0.01%), which corresponds to an annual standard deviation of approximately
27
+ 0.16%, assuming 252 trading days.
28
+
29
+ Attributes
30
+ ----------
31
+ to_keep_ : ndarray of shape (n_assets, )
32
+ Boolean array indicating which assets are remaining.
33
+
34
+ n_features_in_ : int
35
+ Number of assets seen during `fit`.
36
+
37
+ feature_names_in_ : ndarray of shape (`n_features_in_`,)
38
+ Names of assets seen during `fit`. Defined only when `X`
39
+ has assets names that are all strings.
40
+ """
41
+
42
+ to_keep_: np.ndarray
43
+
44
+ def __init__(self, threshold: float = 1e-8):
45
+ self.threshold = threshold
46
+
47
+ def fit(self, X: npt.ArrayLike, y=None):
48
+ """Fit the transformer on some assets.
49
+
50
+ Parameters
51
+ ----------
52
+ X : array-like of shape (n_observations, n_assets)
53
+ Price returns of the assets.
54
+
55
+ y : Ignored
56
+ Not used, present for API consistency by convention.
57
+
58
+ Returns
59
+ -------
60
+ self : DropZeroVariance
61
+ Fitted estimator.
62
+ """
63
+ X = skv.validate_data(self, X)
64
+ if self.threshold < 0:
65
+ raise ValueError(
66
+ f"`threshold` must be higher than 0, got {self.threshold}."
67
+ )
68
+
69
+ self.to_keep_ = X.var(axis=0) > self.threshold
70
+
71
+ return self
72
+
73
+ def _get_support_mask(self):
74
+ skv.check_is_fitted(self)
75
+ return self.to_keep_
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: skfolio
3
- Version: 0.8.0
3
+ Version: 0.9.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>, Matteo Manzi <matteomanzi09@gmail.com>
@@ -83,13 +83,14 @@ skfolio/optimization/ensemble/_stacking.py,sha256=DaswFVBTghP10vHGESn6aLT7C9wgp-
83
83
  skfolio/optimization/naive/__init__.py,sha256=1QKgOuA6DoqKVOsJxWKogaGPyOir6ln-aQ28PTAbtJs,181
84
84
  skfolio/optimization/naive/_naive.py,sha256=w5lDVpn5YeO6NN5dRzSRvj-V6GpfLogOW7FVxevwZl8,6453
85
85
  skfolio/population/__init__.py,sha256=ehKwWhDJCifjhEL-QezVR0xYjzRTeyHbrEMbfWjF9cU,106
86
- skfolio/population/_population.py,sha256=jmfy759zm5Z0ReRBaHMHCaPHEOf8AFxqXVzYrNhaVIw,31354
86
+ skfolio/population/_population.py,sha256=5HNSubjalwKWeukaPPGH8LKgQ9ICpcVFp4h_MtiUhak,31332
87
87
  skfolio/portfolio/__init__.py,sha256=YeDSH0ZdyE-lcbDqpNw9IOltURtoM-ewAzzcec44Q5Q,586
88
88
  skfolio/portfolio/_base.py,sha256=V81HUQ2CWmohGOeNip1dPESGnmRKQk8eDAthjkvVFhQ,40541
89
89
  skfolio/portfolio/_multi_period_portfolio.py,sha256=9z71aZL2GrV6rQ_EkIyPkK-mJ9N2ZLZCIinSScfRgfw,24412
90
90
  skfolio/portfolio/_portfolio.py,sha256=o1e1KNZAuxlC8y3zTIcaW7c2jk_LlEBCzEF8FRJht20,32791
91
- skfolio/pre_selection/__init__.py,sha256=3hqxwd8nAa1dBna5MrE1P5JPrM-OkSvXGyhbMq7ZKIk,511
91
+ skfolio/pre_selection/__init__.py,sha256=6J_D0QIMi24owwJJP6vxYnIgIyWZuMzCMnpMCEpAvCo,606
92
92
  skfolio/pre_selection/_drop_correlated.py,sha256=4-PSd8R20Rcdyc8Zzcy9B2eRPEtaEkM3YXi74YKF-Pk,3839
93
+ skfolio/pre_selection/_drop_zero_variance.py,sha256=66Mi0Fta1kdmLw0CCqa7p9AqpoBpS9B3fGPLqhb8VIU,2312
93
94
  skfolio/pre_selection/_select_complete.py,sha256=2nEvcjROMJzhAHMCHADeAiCws_tc-BMtndIkjRexL84,3902
94
95
  skfolio/pre_selection/_select_k_extremes.py,sha256=nMugK88igmscribCw_I1UnjE_O7cuIjrJF8AGuVTfiA,3082
95
96
  skfolio/pre_selection/_select_non_dominated.py,sha256=Auv7G8E1QNO96heb35oBWmFLd68LlVDRgSpcg7wpv5A,6004
@@ -113,8 +114,8 @@ skfolio/utils/equations.py,sha256=yj6-TReoPq3YaUQyAx-t4wZNbODON2T4TyA82z2SnkU,15
113
114
  skfolio/utils/sorting.py,sha256=F7gfIBfnulfDUiqvzrlR-pba4PPLJT6NH7-5s4sdRhw,3521
114
115
  skfolio/utils/stats.py,sha256=glVHo7rjwy06dl5kkULLOADMrEkVJcfXXAz-1qmYQL4,17005
115
116
  skfolio/utils/tools.py,sha256=sGJFiqc60TqXyaWoH7JdsbaFYj_bvwq3hHIk6FxDC3U,22994
116
- skfolio-0.8.0.dist-info/licenses/LICENSE,sha256=F6Gi-ZJX5BlVzYK8R9NcvAkAsKa7KO29xB1OScbrH6Q,1526
117
- skfolio-0.8.0.dist-info/METADATA,sha256=2I3oPRJjRLU5M_KQRaAx9xmrcARPZbaMuE8qu2RdSAE,22383
118
- skfolio-0.8.0.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
119
- skfolio-0.8.0.dist-info/top_level.txt,sha256=NXEaoS9Ms7t32gxkb867nV0OKlU0KmssL7IJBVo0fJs,8
120
- skfolio-0.8.0.dist-info/RECORD,,
117
+ skfolio-0.9.0.dist-info/licenses/LICENSE,sha256=F6Gi-ZJX5BlVzYK8R9NcvAkAsKa7KO29xB1OScbrH6Q,1526
118
+ skfolio-0.9.0.dist-info/METADATA,sha256=_qGGSm5oQZaU1lYBcKTfslMYdmLJ1oe3pQK0MCTUhOQ,22383
119
+ skfolio-0.9.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
120
+ skfolio-0.9.0.dist-info/top_level.txt,sha256=NXEaoS9Ms7t32gxkb867nV0OKlU0KmssL7IJBVo0fJs,8
121
+ skfolio-0.9.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5