quantskills/agent-quantspace/ml

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when tasks need optional PyCaret model training, ML factor generation, inference wrappers, feature importance, or sparse LASSO weight generation.

Install

npx vskill@latest install quantskills/agent-quantspace/ml

SKILL.md

ML

ML contains reusable model training, prediction, ML factor, and sparse fitting helpers. It should produce predictions, ranks, labels, or weight matrices; return accounting belongs in skills.backtest.

Install model dependencies with uv sync --extra ml.

Public API

python
from skills.ml.ml_engine import MLEngine, ModelPredictor
from skills.ml.ml_factor import MLFactorEngine, make_precomputed_factor
from skills.ml.lasso_tracker import lasso_track
from skills.ml.pca_fold import fit_fold_transform, make_regressor
from skills.ml.walk_forward import date_level_mask, expanding_purged_folds

Components

ModulePurpose
skills.ml.ml_engineLazy PyCaret classification/regression engine and inference wrapper
skills.ml.ml_factorCompress factor configs into ML-ranked cross-sectional factor pivots
skills.ml.lasso_trackerRolling LASSO sparse index-tracking weight generation
skills.ml.pca_foldTrain-only PCA fold transforms (no StandardScaler) and frozen regressors
skills.ml.walk_forwardExpanding walk-forward folds with label purge, plus date row masks for (symbol, eob) panels

Recipes

ML rank factor for `ModularBacktester`

python
from skills.compute import indicators as I
from skills.ml.ml_factor import MLFactorEngine, make_precomputed_factor
engine = MLFactorEngine(
data=panel_df,
factor_configs=[
{"func": I.trend_score_v2, "kwargs": {"period": 24}, "name": "trend"},
{"func": I.cci, "kwargs": {"period": 48}, "name": "cci"},
],
model_type="xgboost",
train_mode="rolling",
)
rank_pivot = engine.generate()
ml_factor_fn = make_precomputed_factor(rank_pivot, name="ml_rank")

Expanding purged walk-forward folds

python
from skills.ml.walk_forward import date_level_mask, expanding_purged_folds
dates = panel.index.get_level_values("eob").unique()
folds = expanding_purged_folds(
dates,
min_train=250,
retrain_step=370,
purge=20,
)
for fold in folds:
train_mask = date_level_mask(feature_panel.index, fold.train_dates)
pred_mask = date_level_mask(feature_panel.index, fold.pred_dates)

Train-only PCA fold transform

python
from skills.ml.pca_fold import fit_fold_transform, make_regressor
transform = fit_fold_transform(train_X, pred_X, n_pca=50, random_state=42)
model = make_regressor("lasso") # or "ols" / "rf" / "xgboost"
model.fit(transform.train_X, train_y)
pred = model.predict(transform.pred_X)

Cross-sectional expanding PCA model scores

python
from skills.compute.features import make_logdiff_panel_features
from strategies.cross_sectional.ml_rank import (
expanding_pca_model_scores,
expanding_pca_multi_model_scores,
)
features = make_logdiff_panel_features(panel) # reuse across horizons
# Prefer multi-model so each fold's PCA is fit once:
results = expanding_pca_multi_model_scores(
panel, models=("ols", "lasso", "rf", "xgboost"), horizon=20, features=features
)
# Or a single model:
result = expanding_pca_model_scores(panel, model="rf", horizon=20, features=features)
scores = result.scores
fold_metrics = result.fold_metrics
overall_metrics = result.overall_metrics

Lesson 07 workflow (18 ETF, equal-weight Top 3)

bash
uv run python -m strategies.cross_sectional.workflows.run_lesson07_etf18_logdiff_pca_ml

Sparse index-tracking weights

python
from skills.ml.lasso_tracker import lasso_track
weights = lasso_track(
etf_returns,
index_returns,
lookback=120,
alpha=1e-5,
rebalance_freq="M",
)

PyCaret classification

python
from skills.ml.ml_engine import MLEngine
engine = MLEngine(task="classification", model_name="xgboost")
model, metrics = engine.setup_and_train(train_df, target="label")
preds = engine.predict(test_df)

CLI command reference

<!-- BEGIN GENERATED: qs commands -->

Transport: --input-json FILE|-, --preview N, and --log-level LEVEL; flags override JSON. Use --print-template [FIELD] for fillable templates.

Shared parameter groups
PanelSource
OptionType / defaultDescription
--panelpath? / nullParquet/CSV panel, mutually exclusive with symbols or symbols-file.
--symbolslist[string] / factoryQuantSpace symbols such as SHSE.510300; repeat flag or comma-separate.
--symbols-filepath? / nullText lines or JSON list of QuantSpace symbols.
--frequencystring / 1dMarket store directory under data/market, for example 1d or 1d_adj.
--data-rootpath? / nullManaged data root; otherwise QUANTSPACE_DATA_ROOT or repository data/.
--startstring? / nullInclusive start date: YYYY-MM-DD or YYYYMMDD.
--endstring? / nullInclusive end date: YYYY-MM-DD or YYYYMMDD.
--fieldslist[string] / factoryOptional panel field subset.
OutputOptions
OptionType / defaultDescription
--outputpath? / nullExplicit output path outside managed store namespaces.
--overwriteboolean / falseAllow replacing an existing output artifact.
--data-rootpath? / nullManaged data root; otherwise QUANTSPACE_DATA_ROOT or repository data/.
uv run qs ml factor-rank

Train MLFactorEngine on factor features and write cross-sectional ranks.

Priority: P1. Side effects: writes-output.

Shared parameters: PanelSource, OutputOptions.

OptionType / defaultDescription
--outputpath / requiredDestination rank table (date by symbol, values in [0, 1]).
--factorslist[MLFactorItem] / requiredFeature factors, each called per symbol.
--modelstring / xgboostPyCaret regression model id, e.g. xgboost or rf.
--target-forwardinteger / 1Forward return horizon of the label.
--train-mode`fixed\rolling / rolling`fixed: one split; rolling: expanding retraining.
--train-rationumber / 0.7fixed mode training fraction.
--train-windowinteger / 120rolling mode initial training days.
--retrain-freqinteger / 20rolling mode retraining interval in days.
--n-foldsinteger / 5PyCaret cross-validation folds.
--pycaret-kwargsobject / factoryExtra keyword arguments for PyCaret setup().
--importance-outputpath? / nullOptional feature importance table.

Output data fields: rows, columns, oos_start_date, evaluation.

Inspect schemas: uv run qs schema ml.factor-rank (add --part input|output or --file-field FIELD).

uv run qs ml lasso-track

Rolling LASSO index-tracking weights.

Priority: P1. Side effects: writes-output.

Shared parameters: PanelSource, OutputOptions.

OptionType / defaultDescription
--outputpath / requiredDestination tracking weights (date by symbol).
--returnspath? / nullCandidate daily returns (date by symbol); otherwise close-to-close returns of the panel source.
--index-symbolstring? / nullTarget index symbol read from the same store and frequency.
--index-returnspath? / nullDated table holding the target index returns.
--index-columnstring / returnReturn column of index_returns.
--lookbackinteger / 120Training window in trading days.
--alphanumber / 1e-06LASSO strength; larger is sparser.
--min-periodsinteger / 60Minimum samples before weights.
--rebalance-freq`D\W\M / M`Refit frequency.
--max-weightnumber / 0.3Cap per candidate.

Output data fields: rows, columns, start, end, preview.

Inspect schemas: uv run qs schema ml.lasso-track (add --part input|output or --file-field FIELD).

uv run qs ml folds

Expanding walk-forward folds with label purge.

Priority: P1. Side effects: read-only.

Shared parameters: PanelSource.

OptionType / defaultDescription
--tablepath? / nullDated table whose eob dates define the calendar; otherwise the panel source.
--min-traininteger / 250Dates before the first retrain.
--retrain-stepinteger / 126Dates predicted per fold.
--purgeinteger / 20Training dates removed before each fold.

Output data fields: dates, folds.

Inspect schemas: uv run qs schema ml.folds (add --part input|output or --file-field FIELD).

uv run qs ml pca-predict

Fit train-only PCA and a frozen regressor, then predict rows.

Priority: P1. Side effects: writes-output.

Shared parameters: OutputOptions.

OptionType / defaultDescription
--outputpath / requiredDestination predictions table with a prediction column.
--trainpath / requiredTraining table with feature columns and the target.
--predictpath / requiredTable of rows to predict, holding the same features.
--target-colstring / requiredTarget column of the training table.
--feature-colslist[string] / factoryOrdered feature columns; defaults to every training column except the target.
--model`ols\lasso\rf\xgboost / required`make_regressor model with its frozen defaults.
--n-pcainteger / 50Maximum PCA components fit on train only.
--random-stateinteger / 42PCA and model random seed.
--rf-n-jobsinteger? / nullRandom forest workers; defaults to all cores.

Output data fields: rows, features, components, pca_explained_variance_sum.

Inspect schemas: uv run qs schema ml.pca-predict (add --part input|output or --file-field FIELD).

uv run qs ml train

Train a PyCaret MLEngine model and save it to the model registry.

Priority: P2. Side effects: writes-store.

OptionType / defaultDescription
--trainpath / requiredTraining table with feature columns and the target.
--targetstring / labelTarget column.
--task`classification\regression / classification`MLEngine task.
--model-namestring / xgboostPyCaret model id, e.g. xgboost or lr.
--normalizestring / zscorePyCaret normalize method.
--pca-componentsinteger? / nullPyCaret PCA components; omitted disables PCA.
--session-idinteger / 369PyCaret random seed.
--n-jobsinteger / 1PyCaret parallel jobs.
--create-kwargsobject / factoryExtra create_model arguments; omitted uses MLEngine's deterministic defaults.
--namespacestring / requiredRegistry namespace under data/models.
--data-rootpath? / nullManaged data root; otherwise QUANTSPACE_DATA_ROOT or repository data/.
--writeboolean / falseTrain and save to the registry; otherwise return a plan.

Output data fields: dry_run, namespace, registry_dir, model_id, rows, features, cv_metrics_mean.

Inspect schemas: uv run qs schema ml.train (add --part input|output or --file-field FIELD).

uv run qs ml predict

Predict with a registry model.

Priority: P2. Side effects: writes-output.

Shared parameters: OutputOptions.

OptionType / defaultDescription
--outputpath / requiredDestination predictions table.
--datapath / requiredTable of feature rows to predict.
--namespacestring / requiredRegistry namespace under data/models.
--model-idstring / requiredModel id from qs store list --kind models --namespace <namespace>.

Output data fields: rows, task, columns.

Inspect schemas: uv run qs schema ml.predict (add --part input|output or --file-field FIELD).

<!-- END GENERATED: qs commands -->

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
57
Repository forks
11
7-day trend score
20

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/quantskills/agent-quantspace/ml/badge)](https://verified-skill.com/skills/quantskills/agent-quantspace/ml)

Something wrong with this skill or its page? Tell us.