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 Classe#

measures.BaseMeasure

Base Enum of measures

Classes#

measures.PerfMeasure

Enumeration of performance measures

measures.RiskMeasure

Enumeration of risk measures

measures.ExtraRiskMeasure

Enumeration of other risk measures not used in convex optimization

measures.RatioMeasure

Enumeration of ratio measures

Functions#

measures.mean(returns)

Compute the mean.

measures.get_cumulative_returns(returns[, ...])

Compute the cumulative returns from the returns.

measures.get_drawdowns(returns[, compounded])

Compute the drawdowns' series from the returns.

measures.variance(returns)

Compute the variance (second moment).

measures.semi_variance(returns[, ...])

Compute the semi-variance (second lower partial moment).

measures.standard_deviation(returns)

Compute the standard-deviation (square root of the second moment).

measures.semi_deviation(returns[, ...])

Compute the semi standard-deviation (semi-deviation) (square root of the second lower partial moment).

measures.third_central_moment(returns)

Compute the third central moment.

measures.fourth_central_moment(returns)

Compute the Fourth central moment.

measures.fourth_lower_partial_moment(returns)

Compute the fourth lower partial moment.

measures.cvar(returns[, beta])

Compute the historical CVaR (conditional value at risk).

measures.mean_absolute_deviation(returns[, ...])

Compute the mean absolute deviation (MAD).

measures.value_at_risk(returns[, beta])

Compute the historical value at risk (VaR).

measures.worst_realization(returns)

Compute the worst realization (worst return).

measures.first_lower_partial_moment(returns)

Compute the first lower partial moment.

measures.entropic_risk_measure(returns[, ...])

Compute the entropic risk measure.

measures.evar(returns[, beta])

Compute the EVaR (entropic value at risk) and its associated risk aversion.

measures.drawdown_at_risk(drawdowns[, beta])

Compute the Drawdown at risk.

measures.cdar(drawdowns[, beta])

Compute the historical CDaR (conditional drawdown at risk).

measures.max_drawdown(drawdowns)

Compute the maximum drawdown.

measures.average_drawdown(drawdowns)

Compute the average drawdown.

measures.edar(drawdowns[, beta])

Compute the EDaR (entropic drawdown at risk).

measures.ulcer_index(drawdowns)

Compute the Ulcer index.

measures.gini_mean_difference(returns)

Compute the Gini mean difference (GMD).

measures.owa_gmd_weights(n_observations)

Compute the OWA weights used for the Gini mean difference (GMD) computation.

measures.effective_number_assets(weights)

Computes the effective number of assets, defined as the inverse of the Herfindahl index [R3692bcdb1be2-1]:

skfolio.portfolio: Portfolio#

Portfolio module. Portfolio and MultiPeriodPortfolio objects are returned by the predict method of Optimization estimators. They need to be homogenous to 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 Classe#

portfolio.BasePortfolio

Base Portfolio class for all portfolios in skfolio.

Classes#

portfolio.Portfolio

Portfolio class.

portfolio.MultiPeriodPortfolio

Multi-Period Portfolio class.

skfolio.population: Population#

Classes#

population.Population

Population Class.

skfolio.optimization.naive: Naive Optimization Estimators#

Classes#

optimization.EqualWeighted

Equally Weighted estimator.

optimization.InverseVolatility

Inverse Volatility estimator.

optimization.Random

Random weight estimator.

skfolio.optimization.convex: Convex Optimization Estimators#

Enum#

optimization.ObjectiveFunction

Enumeration of objective functions.

Classes#

optimization.ConvexOptimization

Base class for all convex optimization estimators in skfolio.

optimization.MeanRisk

Mean-Risk Optimization estimator.

optimization.RiskBudgeting

Risk Budgeting Optimization estimator.

optimization.MaximumDiversification

Maximum Diversification Optimization estimator.

optimization.DistributionallyRobustCVaR

Distributionally Robust CVaR.

skfolio.optimization.cluster: Clustering Optimization Estimators#

Classes#

optimization.BaseHierarchicalOptimization

Base Hierarchical Clustering Optimization estimator.

optimization.HierarchicalRiskParity

Hierarchical Risk Parity estimator.

optimization.HierarchicalEqualRiskContribution

Hierarchical Equal Risk Contribution estimator.

optimization.NestedClustersOptimization

Nested Clusters Optimization estimator.

skfolio.optimization.ensemble: Ensemble Optimization Estimators#

Classes#

optimization.BaseComposition

Handles parameter management for ensemble estimators.

optimization.StackingOptimization

Stack of optimizations with a final optimization.

skfolio.prior: Prior Estimators#

skfolio package

Model Dataclass#

prior.PriorModel

Prior model dataclass.

Base Class#

prior.BasePrior

Base class for all prior estimators in skfolio.

Classes#

prior.EmpiricalPrior

Empirical Prior estimator.

prior.BlackLitterman

Black & Litterman Prior Model estimator.

prior.FactorModel

Factor Model estimator.

Loading Matrix Classes for Factor Models#

prior.BaseLoadingMatrix

Base class for all Loading Matrix estimators.

prior.LoadingMatrixRegression

Loading Matrix Regression estimator.

skfolio.moments.mu: Mu Estimators#

skfolio package

Base Class#

moments.BaseMu

Base class for all expected returns estimators in skfolio.

Classes#

moments.EmpiricalMu

Empirical Expected Returns (Mu) estimator.

moments.EWMu

Exponentially Weighted Expected Returns (Mu) estimator.

moments.ShrunkMu

Shrinkage Expected Returns (Mu) estimator.

moments.EquilibriumMu

Equilibrium Expected Returns (Mu) estimator.

moments.ShrunkMuMethods

Shrinkage methods for the ShrunkMu estimator

skfolio.moments.covariance: Covariance Estimators#

skfolio package

Base Class#

moments.BaseCovariance

Base class for all covariance estimators in skfolio.

Classes#

moments.EmpiricalCovariance

Empirical covariance estimator.

moments.EWCovariance

Exponentially Weighted Covariance estimator.

moments.GerberCovariance

Gerber covariance estimator.

moments.DenoiseCovariance

Covariance Denoising estimator.

moments.DetoneCovariance

Covariance Detoning estimator.

moments.LedoitWolf

LedoitWolf Estimator.

moments.OAS

Oracle Approximating Shrinkage Estimator as proposed in [Re9a22b087643-1].

moments.ShrunkCovariance

Covariance estimator with shrinkage.

moments.GraphicalLassoCV

Sparse inverse covariance with cross-validated choice of the l1 penalty.

skfolio.distance: Distance Estimators#

skfolio package

Base Class#

distance.BaseDistance

Base class for all distance estimators in skfolio.

Classes#

distance.PearsonDistance

Pearson Distance estimator.

distance.KendallDistance

Kendall Distance estimator.

distance.SpearmanDistance

Spearman Distance estimator.

distance.CovarianceDistance

Covariance Distance estimator.

distance.DistanceCorrelation

Distance Correlation estimator.

distance.MutualInformation

Mutual Information estimator.

skfolio.cluster: Cluster Estimators#

skfolio package

Classes#

cluster.HierarchicalClustering

Hierarchical Clustering.

cluster.LinkageMethod

Methods for calculating the distance between clusters in the linkage matrix.

skfolio.uncertainty_set: Uncertainty set Estimators#

skfolio package

Model Dataclass#

uncertainty_set.UncertaintySet

Ellipsoidal uncertainty set dataclass.

Base Classes#

uncertainty_set.BaseMuUncertaintySet

Base class for all Mu Uncertainty Set estimators in skfolio.

uncertainty_set.BaseCovarianceUncertaintySet

Base class for all Covariance Uncertainty Set estimators in skfolio.

Classes#

uncertainty_set.EmpiricalMuUncertaintySet

Empirical Mu Uncertainty Set.

uncertainty_set.EmpiricalCovarianceUncertaintySet

Empirical Covariance Uncertainty set.

uncertainty_set.BootstrapMuUncertaintySet

Bootstrap Mu Uncertainty set.

uncertainty_set.BootstrapCovarianceUncertaintySet

Bootstrap Covariance Uncertainty set.

skfolio.pre_selection: Pre-selection Transformers#

skfolio package

Classes#

pre_selection.DropCorrelated

Transformer for dropping highly correlated assets.

pre_selection.SelectKExtremes

Transformer for selecting the k best or worst assets.

pre_selection.SelectNonDominated

Transformer for selecting non dominated assets.

skfolio.model_selection: Model Selection#

skfolio package

Base Classes#

model_selection.BaseCombinatorialCV

Base class for all combinatorial cross-validators.

Classes#

model_selection.CombinatorialPurgedCV

Combinatorial Purged Cross-Validation.

model_selection.WalkForward

Walk Forward cross-validator.

Functions#

model_selection.cross_val_predict(estimator, X)

Generate cross-validated Portfolios estimates.

skfolio.metrics: Metrics#

skfolio package

Functions#

metrics.make_scorer(score_func[, ...])

Make a scorer from a measure or from a custom score function.

skfolio.datasets: Datasets#

Functions#

datasets.load_sp500_dataset()

Load the prices of 20 assets from the S&P 500 Index composition.

datasets.load_sp500_index()

Load the prices of the S&P 500 Index.

datasets.load_factors_dataset()

Load the prices of 5 factor ETFs.

datasets.load_ftse100_dataset([data_home, ...])

Load the prices of 64 assets from the FTSE 100 Index composition.

datasets.load_nasdaq_dataset([data_home, ...])

Load the prices of 1455 assets from the NASDAQ Composite Index.

skfolio.preprocessing: Preprocessing#

Functions#

preprocessing.prices_to_returns(X[, y, ...])

Transforms a DataFrame of prices to linear or logarithmic returns.

skfolio.utils.stats: Stats#

Functions#

stats.NBinsMethod(value)

Enumeration of the Number of Bins Methods

stats.n_bins_freedman(x)

Compute the optimal histogram bin size using the Freedman-Diaconis rule [R8d5b646da1d1-1].

stats.n_bins_knuth(x)

Compute the optimal histogram bin size using Knuth's rule [R8c3fe88ee915-1].

stats.is_cholesky_dec(x)

Returns True if Cholesky decomposition can be computed.

stats.assert_is_square(x)

Raises an error if the matrix is not square.

stats.assert_is_symmetric(x)

Raises an error if the matrix is not symmetric.

stats.assert_is_distance(x)

Raises an error if the matrix is not a distance matrix.

stats.cov_nearest(cov[, higham, ...])

Compute the nearest covariance matrix that is positive definite and with a cholesky decomposition than can be computed.

stats.cov_to_corr(cov)

Convert a covariance matrix to a correlation matrix.

stats.corr_to_cov(corr, std)

Convert a correlation matrix to a covariance matrix given its standard-deviation vector.

stats.commutation_matrix(x)

Compute the commutation matrix.

stats.compute_optimal_n_clusters(distance, ...)

Compute the optimal number of clusters based on Two-Order Difference to Gap Statistic [Re0e718a4c413-1].

stats.rand_weights(n[, zeros])

Produces n random weights that sum to one from an uniform distribution (non-uniform distribution over a simplex)

stats.rand_weights_dirichlet(n)

Produces n random weights that sum to one from a dirichlet distribution (uniform distribution over a simplex)