The sklearn-compatible portfolio estimator library whose CombinatorialPurgedCV breaks sklearn's own split() contract - it yields (train, [test_0, ...]), and normal two-variable unpacking mis-partitions your data without raising. TRIGGER - skfolio, skfolio.optimization, MeanRisk, RiskBudgeting, HierarchicalRiskParity, HierarchicalEqualRiskContribution, NestedClustersOptimization, skfolio.moments, DenoiseCovariance, GerberCovariance, ImpliedCovariance, EmpiricalPrior, EntropyPooling, VineCopula, CombinatorialPurgedCV, WalkForward, purged_size, embargo_size, RiskMeasure. Memory is stale and will break code - 1.0.0 landed 2026-08-23, so every recalled snippet predates the API stability commitment. SKIP for the widest risk-measure menu (lib-riskfolio) and for a strictly sklearn-compliant purged splitter (lib-purgedcv). SKIP for choosing between libraries, or when no library is named - the domain skill's job.
Ships in fin-libraries. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The only portfolio library that is a real scikit-learn estimator collection — so portfolio construction itself can be cross-validated, not just the return forecast feeding it.
| pip / import | skfolio / skfolio |
| Version | 1.0.3 (2026-08-31) — 1.0.0 landed 2026-08-23 · Python >=3.10 |
| Licence | BSD-3-Clause |
| Status | ✅ fastest-moving library in the category — 2,345★ / 41 issues, pushed 2026-09-03; 0.20.2 → 1.0.3 in 18 days |
⚠️ Positioning, precisely: skfolio is scikit-learn-compatible, part of the sklearn
ecosystem — not an official sub-project, not scikit-learn-contrib-governed.
⚠️ Pre-1.0 knowledge will break. 1.0.0 shipped 2026-08-23, so essentially every tutorial, blog post and
model-recalled snippet predates the stability commitment. Check any 0.x example first.
🚨 CombinatorialPurgedCV.split() yields (train_index, [test_0, test_1, …]) — a list of test folds per split,
not sklearn's 2-tuple contract. Any loop written the normal way — for train, test in cv.split(X) — binds test
to a list of arrays and then indexes with it. It does not raise. It produces a wrong partition and a wrong score,
which is exactly the failure mode purged CV exists to prevent. The correct shape is in the snippet below.
purged_size and embargo_size are OBSERVATIONS, not time🚨 Under time bars that is merely opaque. Under dollar or volume bars a fixed count is a wildly varying time span —
the same purged_size=10 purges an hour in one regime and three days in another. Convert from your longest label
horizon in bars, and redo it whenever the sampling scheme changes. ⚠️ CPCV is also combinatorially expensive:
C(n_folds, n_test_folds) fits, so C(10,3) is 120 model fits per grid point, multiplied by the grid.
single🚨 HierarchicalRiskParity results therefore differ from the AFML book and from PyPortfolioOpt's HRPOpt by design,
not by bug. Reproducing a paper? Set linkage explicitly. 🚨 fit(X) takes RETURNS. Prices run without
complaint and produce a nonsense covariance. Guarantee the input contains negative values before you hand it over. ⚠️
predict returns a Portfolio/Population, not a weights dict. Arrivals from PyPortfolioOpt look for
clean_weights(); the equivalents are .weights, .summary(), .plot_cumulative_returns(). ⚠️ Cardinality
constraints require a MIP-capable solver (HiGHS, SCIP, Gurobi, MOSEK); failures surface as opaque solver errors.
fit/predict and get_params(deep=True), so
Pipeline, GridSearchCV, RandomizedSearchCV and cross_val_predict all work. "Tune the
shrinkage coefficient and the risk measure jointly under purged CV" is three lines here.WalkForward, CombinatorialPurgedCV, Multiple Randomized CV.from skfolio import RiskMeasure
from skfolio.optimization import MeanRisk, ObjectiveFunction
from skfolio.moments import DenoiseCovariance
from skfolio.prior import EmpiricalPrior
from skfolio.model_selection import WalkForward, CombinatorialPurgedCV
from sklearn.model_selection import GridSearchCV
model = MeanRisk(
risk_measure=RiskMeasure.CVAR,
objective_function=ObjectiveFunction.MAXIMIZE_RATIO,
prior_estimator=EmpiricalPrior(covariance_estimator=DenoiseCovariance()),
min_weights=0.0, max_weights=0.10, # set bounds explicitly, never rely on defaults
)
model.fit(X_train) # X_train: DataFrame of RETURNS, not prices
ptf = model.predict(X_test) # a Portfolio object; weights are ptf.weights
print(ptf.summary())
grid = GridSearchCV(model, {"risk_measure": [RiskMeasure.VARIANCE, RiskMeasure.CVAR]},
cv=WalkForward(train_size=252, test_size=63)) # sizes in OBSERVATIONS
grid.fit(X)
cv = CombinatorialPurgedCV(n_folds=10, n_test_folds=2,
purged_size=5, embargo_size=5) # OBSERVATIONS, not time
for train_idx, test_idx_list in cv.split(X): # 🚨 non-sklearn contract
for test_idx in test_idx_list:
...
../../../fin-core/skills/portfolio-and-risk/SKILL.md — optimizer choice, and the metric traps downstream../../../fin-core/skills/portfolio-and-risk/references/skfolio.md — the source card../../../fin-core/skills/portfolio-and-risk/references/optimizers.md — head-to-head table../../../fin-core/skills/backtest-validation/references/purgedcv.md — CPCV alternatives comparedThis file is the deep dive on one library and assumes the choice is already made.
For which library to pick, how it compares with the alternatives, and the traps that span
several of them, the entry point is the domain skill portfolio-and-risk (../../../fin-core/skills/portfolio-and-risk/SKILL.md).
What SKILL.md sets; muted values are Claude Code's defaults
/fin-libraries:lib-skfoliofrom fin-libraries
npx claudepluginhub howard-lynn-ye/fin-rsi --plugin fin-libraries24 skills in this plugin
/lib-akshareakshare is the widest free Chinese-market scraper (1,103 public interfaces) and it purges its own PyPI history, so you cannot pin it. TRIGGER - akshare, "import akshare as ak", pip install akshare, stock_zh_a_hist, stock_zh_a_daily, index_stock_cons_csindex, stock_zt_pool_em, stock_zh_a_stop_em, adjust="qfq"/"hfq", 复权, 前复权, 后复权, 涨跌停, 东方财富, 新浪财经, A股数据, 沪深300成分股, "No matching distribution found for akshare==", akshare 报错, akshare 封 IP. akshare ships roughly 2.3 releases a week and deletes the old ones, so any signature, column name or version pin you remember is probably already gone. SKIP for lib-tushare, which is the skill for point-in-time fundamentals and dated index membership. SKIP when the question is WHICH library to choose, or names no library at all - both belong to the domain skill./lib-alpaca-pyAlpaca's current Python SDK, which defaults to the paper host but lets url_override silently send live orders from a client that believes it is in the sandbox. TRIGGER - import alpaca, pip install alpaca-py, TradingClient, StockHistoricalDataClient, CryptoHistoricalDataClient, submit_order, LimitOrderRequest, MarketOrderRequest, OrderSide, TimeInForce, client_order_id, url_override, paper=True, BaseURL.TRADING_PAPER, paper-api.alpaca.markets, bracket OCO OTO orders, trail_percent, IEX vs SIP feed, Algo Trader Plus, alpaca-trade-api, APCA_API_BASE_URL; an order rejected asynchronously for time-in-force or price precision. Memory is stale here: alpaca-trade-api was deprecated in 2024 and defaulted to LIVE, whereas alpaca-py 0.44.0 (2026-08-11) declares paper=True - the widely repeated warning is inverted. SKIP for Interactive Brokers and for the general order-safety patterns (broker-execution-apis). SKIP for choosing between libraries, or when no library is named - the domain skill's job.Other plugins' skills for the same job