skfolio : Portfolio Optimization in Python
Carlo Nicolini \corrauthor \equalcontribution Ipazia SpA Milan, Italy [email protected], Matteo Manzi \equalcontribution Orion Finance Paris, France [email protected], Hugo Delatte \equalcontribution SKFolio Labs London, UK [email protected] · 2025
Read skfolio : Portfolio Optimization in Python by Carlo Nicolini \corrauthor \equalcontribution Ipazia SpA Milan, Italy [email protected], Matteo Manzi \equalcontribution Orion Finance Paris, France [email protected], Hugo Delatte \equalcontribution SKFolio Labs London, UK [email protected] (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2507-04176.txt.
Introduction
Carlo Nicolini and co-authors present skfolio, an open-source Python library for portfolio optimization, in a 2025 paper. Building investment portfolios demands tools that marry sound statistics with code practitioners will actually use.
The library plugs into the scikit-learn ecosystem and follows its fit, predict, and transform pattern throughout. Strategies range from classic mean-variance methods to modern clustering-based allocation. Financial estimators ship with native interfaces, and cross-validation tools respect the order of financial time series. Machine learning workflows thus carry straight into portfolio construction. The authors pitch reproducibility and transparency as the payoff: researchers and traders share one tested base instead of private, unverifiable scripts.
Catalog record
| CREATOR | Carlo Nicolini \corrauthor \equalcontribution Ipazia SpA Milan, Italy [email protected], Matteo Manzi \equalcontribution Orion Finance Paris, France [email protected], Hugo Delatte \equalcontribution SKFolio Labs London, UK [email protected] |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 20 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2507-04176
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
skfolio : Portfolio Optimization in Python Carlo Nicolini \corrauthor \equalcontribution Ipazia SpA Milan, Italy [email protected], Matteo Manzi \equalcontribution Orion Finance Paris, France [email protected], Hugo Delatte \equalcontribution SKFolio Labs London, UK [email protected] Abstract Portfolio optimization is a fundamental challenge in quantitative finance, requiring robust computational tools that integrate statistical rigor with practical implementation. We present skfolio , an open-source Python library for portfolio construction and risk management that seamlessly integrates with the scikit-learn ecosystem. skfolio provides a unified framework for diverse allocation strategies, from classical mean-variance optimization to modern clustering-based methods, state-of-the-art financial estimators with native interfaces, and advanced cross-validation techniques tailored for financial time series. By adhering to scikit-learn’s fit-predict-transform paradigm, the library enables researchers and practitioners to leverage machine learning workflows for portfolio optimization, promoting reproducibility and transparency in quantitative finance. 1 Introduction Portfolio optimization, first introduced by Markowitz’s Modern Portfolio Theory (MPT) ( Markowitz 1952 ) , is a key concept in quantitative finance. However, putting MPT into practice comes with several challenges. These include high sensitivity to expected return and risk estimates, lack of diversification, frequent changes in asset weights (i.e. high turnover), and poor performance when tested on new data (i.e. overfitting). There are many different optimization methods, pre-selection techniques, distribution and moment estimators available, and they are often combined in practice, making the process even more complex. This highlights the need for a single, unified framework that leverages machine learning for model selection, validation, and parameter tuning, while also mitigating the risks of overfitting and data leakage ( Arnott et al. 2019 ; Bailey et al. 2016 ) . Such a framework is essential for the quantitative finance community, which faces persistent challenges in bridging the gap between sophisticated financial theory and practical implementation. These challenges include: (i) a fragmented ecosystem, where existing libraries lack consistent interfaces and comprehensive feature sets; (ii) limited reproducibility, as proprietary solutions hinder research validation and collaboration; (iii) poor machine learning integration, with traditional portfolio tools not fitting seamlessly into modern data science workflows; and (iv) inadequate cross-validation, since standard ML methods often fail to account for temporal dependencies inherent in financial data. In this work, we present skfolio , an open-source library designed to address these challenges. Built on top of the standardized scikit-learn API ( Pedregosa et al. 2011 ) , skfolio offers a comprehensive framework for portfolio optimization and risk management. This approach ensures seamless integration with existing machine learning workflows, while preserving the mathematical rigor essential for robust portfolio construction. 2 Design and Implementation 2.1 Overview and Basic Usage skfolio follows a modular architecture that integrates seamlessly with the scikit-learn ecosystem. Figure 1 A illustrates the library’s core components and their interactions. The library is built around three fundamental principles: (i) scikit-learn compatibility: all estimators inherit from BaseEstimator , implementing the standard fit-predict-transform paradigm, (ii) mathematical rigor: state-of-the-art portfolio optimization methods with numerical stability implemented in cvxpy ( Diamond and Boyd 2016 ) , (iii) transparency and reproducibility: open-source design promoting research reproducibility. As an example, we demonstrate how to find the minimum variance portfolio with a maximum weight constraint and L_{2} regularization on the portfolio weights, and how to generate the corresponding efficient frontier. This is formulated as a convex minimization problem. \displaystyle\min_{\mathbf{w}} \displaystyle\mathbf{w}^{T}\boldsymbol{\hat{\Sigma}}\mathbf{w}+\lambda\mathbf{w}^{T}\mathbf{w} (1) \displaystyle\text{s.t.} \displaystyle\mathbf{w}^{T}\mathbf{1}=1 \displaystyle\mathbf{w}_{\rm{AAPL}}\leq 0.2 where \boldsymbol{\hat{\Sigma}} is the sample covariance matrix, \lambda is the L_{2} regularization parameter. In Figure 1 B, we implement the convex optimization problem from Equation 1 . We load the S&P 500 dataset, convert prices to returns, and solve for 100 points on the mean-risk frontier, imposing a maximum weight of 20% for AAPL and L_{2} regularization with \lambda=0.01 . Figure 1 C, shows the frontier for the problem, divided over train and test set. A. C. B. ⬇ from skfolio . datasets import load_sp500_dataset from skfolio . optimization import ( MeanRisk , ObjectiveFunction ) from skfolio . measures import RiskMeasure from skfolio . preprocessing import prices_to_returns from sklearn . model_selection import train_test_split # Load the prices and convert to returns prices = load_sp500_dataset () X = prices_to_returns ( prices ) X_train , X_test = train_test_split ( X , test_size =0.2, shuffle = False ) # Define a convex optimization problem model = MeanRisk ( risk_measure = RiskMeasure . VARIANCE , objective_function = ObjectiveFunction . MINIMIZE_RISK , efficient_frontier_size =100, max_weights ={" AAPL ": 0.2}, l2_coef =0.01 ) # Fit on training data and predict on test data model . fit ( X_train ) ptf_train = model . predict ( X_train ) ptf_test = model . predict ( X_test ) ptf_train . summary (), ptf_test . summary () Figure 1: (A) skfolio architecture showing the integration between data preprocessing, optimization methods, and evaluation components within the scikit-learn framework. (B) Basic usage example of finding the minimum variance portfolio. (C) Efficient frontier for the minimum variance portfolio on the S&P 500 dataset, over both train and test data. The training frontier dominates the test frontier, showing the overfitting of the model. 2.1.1 Convex Optimization Methods The MeanRisk class covers all the convex optimization problems that can be formulated as risk minimization, expected returns maximization, utility maximization, and ratio maximization (Table 1 ). Multiple risk functions are supported (e.g. variance, CVaR, CDaR, and many more). All problems have an additional regularization cost described by the \mathcal{L}(\mathbf{w}) term including L_{1} and L_{2} norms of the portfolio weights, transaction costs, management fees and parameters uncertainty loss for robust parameters estimation ( Mohajerin Esfahani and Kuhn 2018 ; Ceria and Stubbs 2006 ) . Granular control over the number of assets in a portfolio can be achieved by applying cardinality constraints (i.e., specifying a maximum number of assets), which are supported through specialized MIP solvers. Prior estimators may also be incorporated to assist in estimating expected returns, the covariance matrix, or to impose additional structure on the optimization problem. Minimize Risk Maximize Expected Returns \displaystyle\begin{array}[]{l}\left\{\begin{array}[]{lcll}\argmin_{\mathbf{w}}&\rm{risk}_{i}(\mathbf{R}^{T}\mathbf{w})+\mathcal{L}(\mathbf{w})&&\\ \text{s.t.}&\mathbf{w}^{T}{\boldsymbol{\mu}}\geq\mu_{\min}&&\\ &\mathbf{A}\mathbf{w}\geq\mathbf{b}&&\\ &\rm{risk}_{j}(\mathbf{R}^{T}\mathbf{w})\leq\rm{risk}_{j}^{\max},\forall\;i\neq j&&\end{array}\right.\end{array} \displaystyle\begin{array}[]{l}\left\{\begin{array}[]{lcll}\argmax_{\mathbf{w}}&\mathbf{w}^{T}{\boldsymbol{\mu}}-\mathcal{L}(\mathbf{w})&&\\ \text{s.t.}&\mathbf{A}\mathbf{w}\geq\mathbf{b}&&\\ &\rm{risk}_{j}(\mathbf{R}^{T}\mathbf{w})\leq\rm{risk}_{j}^{\max},\forall\;j&&\end{array}\right.\end{array} Maximize Utility Maximize Ratio \displaystyle\begin{array}[]{l}\left\{\begin{array}[]{lcll}\argmax_{\mathbf{w}}&\mathbf{w}^{T}\mu-\lambda\times\rm{risk}_{i}(\mathbf{R}^{T}\mathbf{w})-\mathcal{L}(\mathbf{w})&&\\ \text{s.t.}&\mathbf{w}^{T}\mu\geq\mu_{\min}&&\\ &\mathbf{A}\mathbf{w}\geq\mathbf{b}&&\\ &\rm{risk}_{j}(\mathbf{R}^{T}\mathbf{w})\leq\rm{risk}_{j}^{\max},\forall\;j&&\end{array}\right.\end{array} \displaystyle\begin{array}[]{l}\left\{\begin{array}[]{lcll}\argmax_{\mathbf{w}}&\dfrac{\mathbf{w}^{T}{\boldsymbol{\mu}}}{\rm{risk}_{i}(\mathbf{R}^{T}\mathbf{w})}-\mathcal{L}(\mathbf{w})&&\\ \text{s.t.}&\mathbf{w}^{T}\mu\geq\mu_{\min}&&\\ &\mathbf{A}\mathbf{w}\geq\mathbf{b}&&\\ &\rm{risk}_{j}(\mathbf{R}^{T}\mathbf{w})\leq\rm{risk}_{j}^{\max},\forall\;j&&\end{array}\right.\end{array} Table 1: The four formulations of convex portfolio optimization problems implemented in skfolio . The risk function \rm{risk}_{i} is chosen from one of the many risk functions available. The optimization variables are the portfolio weights \mathbf{w} , the constraints are encoded in the \mathbf{A} and \mathbf{b} matrices. The main input variable are the asset excess returns \mathbf{R} . The parameter \mu_{\min} is the minimum acceptable excess return, \rm{risk}_{i}^{\max} is the maximum acceptable risk for the i -th risk measure, while the \mathcal{L}(\mathbf{w}) encodes additional regularization terms. 2.2 Prior Estimation Methods Prior estimators are all the necessary methods to provide additional information to the optimization process. skfolio supports sophisticated prior estimation methods that enhance portfolio optimization by incorporating domain knowledge or analyst views, and addressing estimation errors. Frequentist or Bayesian approaches like parameters shrinkage (Bayes-Stein for returns ( Jorion 1986 ) , shrinkage for covariance matrix ( Ledoit and Wolf 2004 ) ) and Black-Litterman ( He and Litterman 2002 ) are available as prior specifiers, together with classical factor models ( Jurczenko 2015 ) . Advanced information-theoretic approaches, such as opinion pooling ( Good 1952 ) and entropy pooling ( Meucci et al. 2011 ; Meucci 2012 ) are also supported, offering robust alternatives for asset allocation in