API Reference#
This is the class and function reference of skfolio. Please refer to
the full user guide for further details, as the class and
function raw specifications may not be enough to give full guidelines on their
uses.
skfolio.measures: Measures#
Module that includes all Measures functions used across skfolio.
Base Class#
Base Enum of measures. |
Classes#
Enumeration of performance measures. |
|
Enumeration of risk measures. |
|
Enumeration of other risk measures not used in convex optimization. |
|
Enumeration of ratio measures. |
Functions#
|
Compute the mean. |
|
Compute the cumulative returns from a series of returns. |
|
Compute the drawdowns' series from the returns. |
|
Compute the variance (second moment). |
|
Compute the semi-variance (second lower partial moment). |
|
Compute the standard-deviation (square root of the second moment). |
|
Compute the semi-deviation (square root of the second lower partial moment). |
|
Compute the third central moment. |
|
Compute the Fourth central moment. |
|
Compute the fourth lower partial moment. |
|
Compute the Skew. |
|
Compute the Kurtosis. |
|
Compute the historical CVaR (conditional value at risk). |
|
Compute the mean absolute deviation (MAD). |
|
Compute the historical value at risk (VaR). |
|
Compute the worst realization (worst return). |
|
Compute the first lower partial moment. |
|
Compute the entropic risk measure. |
|
Compute the EVaR (entropic value at risk) and its associated risk aversion. |
|
Compute the Drawdown at risk. |
|
Compute the historical CDaR (conditional drawdown at risk). |
|
Compute the maximum drawdown. |
|
Compute the average drawdown. |
|
Compute the EDaR (entropic drawdown at risk). |
|
Compute the Ulcer index. |
|
Compute the Gini mean difference (GMD). |
|
Compute the OWA weights used for the Gini mean difference (GMD) computation. |
|
Compute the effective number of assets, defined as the inverse of the Herfindahl index. |
|
Compute the correlation matrix. |
skfolio.portfolio: Portfolio#
Portfolio module.
Portfolio and MultiPeriodPortfolio objects are returned by the predict method of
Optimization estimators.
They must be consistent with the convex optimization problems, meaning that Portfolio
is the dot product of the assets weights with the assets returns and
MultiPeriodPortfolio is a list of Portfolio.
Base Class#
Base Portfolio class for all portfolios in skfolio. |
Classes#
Portfolio class. |
|
Portfolio object returned when an optimization step fails. |
|
Multi-Period Portfolio class. |
skfolio.population: Population#
Population module.
Classes#
Population Class. |
skfolio.containers: Containers#
Containers module.
Classes#
Container for aligned cross-sectional asset data. |
|
Observation-sliced view into an |
Field Base Class#
Base class for fields stored in an |
|
Numeric 2D field with axes (observations, assets). |
|
Numeric 3D field with axes (observations, assets, third_axis). |
|
Integer-coded categorical 2D field. |
Enum#
Validation policy for values outside an |
Functions#
|
Concatenate panels along the observation axis. |
skfolio.base: Base Estimators#
Base classes for all estimators and various utility functions.
Classes#
Base class for estimators that transform asset panel data. |
|
Handles parameter management for ensemble estimators. |
skfolio.optimization.base: Base Optimization Estimator#
Optimization module.
Classes#
Base class for all portfolio optimizations in skfolio. |
skfolio.optimization.naive: Naive Optimization Estimators#
Naive Optimization module.
Classes#
Equally Weighted estimator. |
|
Inverse Volatility estimator. |
|
Random weight estimator. |
skfolio.optimization.convex: Convex Optimization Estimators#
Convex Optimization module.
Enum#
Enumeration of objective functions. |
Classes#
Base class for all convex optimization estimators in skfolio. |
|
Mean-Risk Optimization estimator. |
|
Benchmark Tracker Optimization estimator. |
|
Risk Budgeting Optimization estimator. |
|
Maximum Diversification Optimization estimator. |
|
Distributionally Robust CVaR. |
skfolio.optimization.cluster: Clustering Optimization Estimators#
Cluster Optimization module.
Classes#
Base Hierarchical Clustering Optimization estimator. |
|
Hierarchical Risk Parity estimator. |
|
Hierarchical Equal Risk Contribution estimator. |
|
Schur Complementary Allocation estimator. |
|
Nested Clusters Optimization estimator. |
skfolio.optimization.ensemble: Ensemble Optimization Estimators#
Ensemble Optimization module.
Classes#
Stack of optimizations with a final optimization. |
skfolio.prior: Prior Estimators#
Prior module.
Model Dataclass#
Return distribution estimated by a prior estimator. |
|
Factor model decomposition of asset returns. |
|
Matrix square root decomposition of a covariance matrix. |
Base Class#
Base class for all prior estimators in skfolio. |
Classes#
Empirical Prior estimator. |
|
Black & Litterman estimator. |
|
Time-series factor model estimator. |
|
Characteristics-based cross-sectional factor model. |
|
Synthetic Data Estimator. |
|
Entropy Pooling estimator. |
|
Opinion Pooling estimator. |
Loading Matrix Classes for Factor Models#
Base class for all Loading Matrix estimators. |
|
Loading Matrix Regression estimator. |
Factor Model Components#
Descriptors that map AssetPanel columns to factor characteristics.
Descriptor Base Classes#
Base class for all descriptor transformers. |
Descriptors#
Cash-flow statement accruals descriptor. |
|
Analyst forecast dispersion to price descriptor. |
|
Asset turnover descriptor. |
|
Asset growth rate descriptor. |
|
Book leverage descriptor. |
|
Book-to-price ratio descriptor. |
|
Lagged change in capex-to-assets intensity. |
|
Cash flow to assets descriptor. |
|
Cash-flow-to-price ratio descriptor. |
|
Lagged change in a field-to-scale ratio. |
|
Lagged change normalized by a positive scale. |
|
Exponentially weighted days-to-cover descriptor. |
|
Debt-to-assets ratio descriptor. |
|
Dividend-to-price ratio descriptor. |
|
Exponentially weighted Amihud illiquidity descriptor. |
|
Exponentially weighted downside beta descriptor. |
|
Exponentially weighted downside return volatility descriptor. |
|
EWMA macro sensitivity after removing market exposure. |
|
Exponentially weighted market beta descriptor. |
|
Exponentially weighted momentum descriptor. |
|
Exponentially weighted downside CAPM residual volatility descriptor. |
|
Exponentially weighted CAPM residual volatility descriptor. |
|
Exponentially weighted share turnover descriptor. |
|
Exponentially weighted volatility descriptor. |
|
Lagged earnings change divided by current market capitalization. |
|
Earnings-to-price ratio descriptor. |
|
EBITDA-to-enterprise-value ratio descriptor. |
|
Forward dividend-to-price ratio descriptor. |
|
Forward earnings-to-price ratio descriptor. |
|
Gross margin descriptor. |
|
Gross profitability descriptor. |
|
Period-over-period growth rate descriptor. |
|
Issuance growth rate descriptor. |
|
Log market capitalization descriptor. |
|
Market leverage descriptor. |
|
Maximum return over a trailing window. |
|
Passthrough descriptor for an |
|
Return on assets (ROA) descriptor. |
|
Return on equity (ROE) descriptor. |
|
Fixed-window short-term reversal descriptor. |
|
Fixed-window momentum descriptor. |
|
Sales growth rate descriptor. |
|
Sales to enterprise value descriptor. |
|
Sales-to-price ratio descriptor. |
|
Shareholder yield descriptor. |
|
Short interest descriptor. |
Factor exposure transformers.
Factor Exposure Estimators#
Base class for factor exposure estimators. |
|
Factor exposure derived from another factor's computed exposure. |
|
Factor exposure as a fixed weighted combination of descriptors. |
|
Constant factor exposure equal to one for every asset. |
|
One-hot factor exposures from a categorical field. |
Alpha models for factor-model score construction.
Alpha Estimators#
Base class for all Alpha estimators in skfolio. |
|
Exponentially weighted least-squares Sharpe-optimal alpha estimator. |
|
Fixed-weighted descriptor alpha estimator. |
|
Predictor alpha estimator using a user-provided regressor. |
Alpha Evaluation#
Side-by-side comparison of alpha forecast evaluations. |
|
Out-of-sample alpha forecast evaluation. |
Functions#
|
Evaluate alpha forecast quality. |
Enum#
Unit of the intermediate alpha forecast. |
|
Cross-sectional weighting. |
|
Correlation method. |
Factor-based volatility and return attribution.
Attribution#
Factor attribution result. |
|
Per-asset attribution breakdown. |
|
Asset-by-factor contribution breakdown. |
|
Base class for attribution breakdowns. |
|
Portfolio attribution component. |
|
Per-factor attribution breakdown. |
|
Family-level attribution breakdown. |
Attribution Functions#
Compute predicted (ex-ante) factor volatility and return attribution. |
|
Compute realized (ex-post) factor volatility and return attribution. |
|
Compute rolling realized (ex-post) factor volatility and return attribution. |
skfolio.moments.expected_returns: Expected Returns Estimators#
Expected returns module.
Base Class#
Base class for all expected returns estimators in skfolio. |
Classes#
Empirical Expected Returns (Mu) estimator. |
|
Exponentially Weighted Expected Returns (Mu) estimator. |
|
Shrinkage Expected Returns (Mu) estimator. |
|
Equilibrium Expected Returns (Mu) estimator. |
|
Shrinkage methods for the ShrunkMu estimator. |
skfolio.moments.variance: Variance Estimators#
Variance module.
Base Class#
Base class for all variance estimators in |
Classes#
Empirical Variance estimator. |
|
Exponentially Weighted Variance estimator. |
|
Exponentially weighted variance estimator with regime adjustment via the Short-Term Volatility Update (STVU) [R1cff04c74aab-1]. |
skfolio.moments.covariance: Covariance Estimators#
Covariance module.
Base Class#
Base class for all covariance estimators in |
Enum#
Transformation used to map the STVU statistic to the volatility multiplier. |
|
Target dimension used to calibrate the short-term volatility update (STVU). |
Classes#
Empirical Covariance estimator. |
|
Exponentially Weighted Covariance estimator with NaN-aware pairwise updates. |
|
Gerber Covariance estimator. |
|
Covariance Denoising estimator. |
|
Covariance Detoning estimator. |
|
LedoitWolf Covariance Estimator. |
|
Oracle Approximating Shrinkage Estimator as proposed in [Re9a22b087643-1]. |
|
Covariance estimator with shrinkage. |
|
Sparse inverse covariance with cross-validated choice of the l1 penalty. |
|
Implied Covariance estimator. |
|
Exponentially weighted covariance estimator with regime adjustment via the Short-Term Volatility Update (STVU) [R9fdb90a74052-1]. |
skfolio.distance: Distance Estimators#
Distance Estimators.
Base Class#
Base class for all distance estimators in skfolio. |
Classes#
Pearson Distance estimator. |
|
Kendall Distance estimator. |
|
Spearman Distance estimator. |
|
Covariance Distance estimator. |
|
Distance Correlation estimator. |
|
Mutual Information estimator. |
skfolio.cluster: Cluster Estimators#
Hierarchical Clustering estimators.
Classes#
Hierarchical Clustering. |
|
Methods for calculating the distance between clusters in the linkage matrix. |
skfolio.uncertainty_set: Uncertainty set Estimators#
Uncertainty Set module.
Model Dataclass#
Norm-ball uncertainty set. |
|
Compact representation of a quadratic covariance uncertainty penalty. |
Base Classes#
Base class for all Mu Uncertainty Set estimators in |
|
Base class for all Covariance Uncertainty Set estimators in |
Classes#
Empirical Mu Uncertainty Set. |
|
Empirical Covariance Uncertainty set. |
|
Bootstrap Mu Uncertainty set. |
|
Bootstrap Covariance Uncertainty set. |
|
Expected return uncertainty set estimator for directions outside the factor span. |
|
Covariance uncertainty set estimator for directions outside the factor span. |
skfolio.pre_selection: Pre-selection Transformers#
Pre Selection module.
Classes#
Transformer for dropping highly correlated assets. |
|
Transformer for dropping assets with near-zero variance. |
|
Transformer for selecting the |
|
Transformer for selecting non dominated assets. |
|
Transformer to select assets with complete data across the entire observation period. |
|
Transformer to select assets that do not expire within a specified lookahead period after the end of the observation period. |
skfolio.linear_model: Cross-sectional linear models#
Linear model module.
Base Class#
Base class for all cross-sectional linear model estimators. |
Classes#
Cross-sectional weighted least squares regression. |
|
Cross-sectional regression based on a scikit-learn regressor. |
skfolio.model_selection: Model Selection#
Model selection module.
Base Classes#
Base class for all combinatorial cross-validators. |
Classes#
Walk Forward Cross-Validator. |
|
Combinatorial Purged Cross-Validation. |
|
Multiple Randomized Cross-Validation. |
|
Online exhaustive hyperparameter search over a parameter grid. |
|
Online randomized search on hyperparameters. |
|
Out-of-sample covariance forecast evaluation. |
|
Side-by-side comparison of covariance forecast evaluations. |
Functions#
|
Generate cross-validated |
|
Generate out-of-sample portfolios using online learning. |
|
Score an online estimator using walk-forward evaluation. |
Evaluate out-of-sample covariance forecast quality. |
|
Evaluate out-of-sample covariance forecast quality using walk-forward cross-validation. |
|
|
Find the optimal number of folds (total folds and test folds) for a target training size and a target number of test paths. |
skfolio.metrics: Metrics#
Metrics module.
Functions#
|
Make a scorer from a measure, a portfolio score function, or a non-predictor estimator score function. |
|
Diagonal calibration loss. |
|
Diagonal calibration ratio based on marginal variances. |
|
Exceedance rate for chi-squared calibration statistics. |
|
Mahalanobis calibration loss. |
|
Mahalanobis calibration ratio. |
Portfolio variance calibration loss. |
|
Portfolio variance calibration ratio. |
|
|
QLIKE loss for a projected portfolio variance forecast [R7dedfcdc36e0-1]. |
|
QLIKE loss for univariate variance forecasts. |
skfolio.datasets: Datasets#
Functions#
Load the prices of 20 assets from the S&P 500 Index. |
|
Load the prices of the S&P 500 Index. |
|
Load the prices of 5 factor ETFs. |
|
|
Load the prices of 64 assets from the FTSE 100 Index composition. |
|
Load the prices of 1455 assets from the NASDAQ Composite Index. |
Load the 3 months ATM implied volatility of the 20 assets from the SP500 dataset. |
|
Generate a synthetic characteristics |
skfolio.preprocessing: Preprocessing#
Preprocessing module.
Base Class#
Base class for all cross-sectional transformers in skfolio. |
Classes#
Cross-sectional rank Gaussianization. |
|
Cross-sectional percentile rank. |
|
Cross-sectional standardization. |
|
Cross-sectional tanh outlier shrinker. |
|
Cross-sectional winsorization. |
Functions#
|
Transform a DataFrame of prices to linear or logarithmic returns. |
skfolio.utils.tools: Tools#
Classes#
Base Enum class used in |
|
Cached property decorator for slots. |
Functions#
|
Return the last |
|
Returns the argument names of a function. |
Generator to bisect a list of arrays. |
|
|
Decorator that caches class method results into a class dictionary. |
|
Check the estimator type and return its cloned version if provided, otherwise return the default estimator. |
|
Rename duplicated names by appending "_{duplicate_nb}" at the end. |
|
Default asset names are |
|
Fit the estimator and predict values for a given dataset split. |
|
Fit (or partial-fit) an estimator on a subset of the data. |
|
Format a measure number into a user-friendly string. |
Get feature names from X. |
|
|
Convert half-life to exponential decay factor. |
|
Convert a collection of items (array-like or dictionary) into a numpy array and verify its shape. |
Return the optimal rounding decimal number for a user-friendly formatting. |
|
|
Return rows, items or columns of X using indices. |
|
Create subset of dataset. |
|
Convert a list of items (asset indices or asset names) into a list of validated asset indices. |
skfolio.utils.stats: Stats#
Enum#
Enumeration of the Number of Bins Methods. |
Functions#
Raises an error if the matrix is not a distance matrix. |
|
Raises an error if the matrix is not square. |
|
|
Raises an error if the matrix is not symmetric. |
|
Retrieve the k-combination at a given lexicographic position without enumerating all combinations. |
Compute the commutation matrix. |
|
|
Compute the optimal number of clusters based on Two-Order Difference to Gap Statistic [Re0e718a4c413-1]. |
|
Convert a correlation matrix to a covariance matrix given its standard-deviation vector. |
|
Compute the nearest covariance matrix that is positive definite and with a cholesky decomposition that can be computed. |
|
Convert a covariance matrix to a correlation matrix. |
|
Weighted cross-sectional Pearson correlation. |
|
Cross-sectional rank along an axis. |
|
Cross-sectional Spearman rank correlation. |
|
Multiply the inverse of matrix a by matrix b. |
|
Inverse-volatility portfolio weights from a covariance matrix. |
|
Compute a Cholesky factor \(L\) from covariance \(\Sigma\). |
Returns True if Cholesky decomposition can be computed. |
|
Apply weight constraints to an initial array of weights by minimizing the relative weight deviation of the final weights from the initial weights. |
|
Multiply matrix a by the inverse of matrix b. |
|
Compute the optimal histogram bin size using the Freedman-Diaconis rule [R8d5b646da1d1-1]. |
|
Compute the optimal histogram bin size using Knuth's rule [R8c3fe88ee915-1]. |
|
|
Produces n random weights that sum to one from a uniform distribution (non-uniform distribution over a simplex). |
Produces n random weights that sum to one from a Dirichlet distribution (uniform distribution over a simplex). |
|
|
Generate unique k-element subsets from a universe of size n using combinatorial unranking. |
|
Squared Mahalanobis distance via Cholesky decomposition. |
Squared standardized Euclidean distance. |
|
|
Compute the Symmetric step-up matrix M such that |
|
In-place symmetrization: \(M \leftarrow (M + M^T) / 2\). |
skfolio.distribution: Distribution Estimators#
Distribution module.
Base Class#
Base Distribution Estimator. |
Enum#
Enum representing the selection criteria. |
skfolio.distribution.univariate: Univariate Distribution Estimators#
Univariate Distribution module.
Base Class#
Base Univariate Distribution Estimator. |
Classes#
Gaussian Distribution Estimation. |
|
Student's t Distribution Estimation. |
|
Johnson SU Distribution Estimation. |
|
Normal Inverse Gaussian Distribution Estimation. |
Functions#
|
Select the optimal univariate distribution estimator based on an information criterion. |
skfolio.distribution.multivariate: Multivariate Distribution Estimators#
Multivariate Distribution module.
Base Class#
Base class for Multivariate Distribution Estimators. |
Classes#
Regular Vine Copula Estimator. |
Enum#
Enumeration of methods to measure bivariate dependence. |
skfolio.distribution.copula: Bivariate Copula Estimators#
Copula module.
Base Class#
Base class for Bivariate Copula Estimators. |
Classes#
Bivariate Gaussian Copula Estimation. |
|
Bivariate Student's t Copula Estimation. |
|
Bivariate Clayton Copula Estimation. |
|
Bivariate Gumbel Copula Estimation. |
|
Bivariate Joe Copula Estimation. |
|
Bivariate Independent Copula (also called the product copula). |
Functions#
Compute pseudo-observations by ranking each column of the data and scaling the ranks. |
|
Compute empirical tail concentration for the two variables in X. |
|
|
Plot the empirical tail concentration curves. |
|
Select the best bivariate copula from a list of candidates using an information criterion. |
Enum#
Enum representing the rotation (in degrees) to apply to a bivariate copula. |