Skip to main content

quantlab-factor-agent logo

quantlab-factor-agent

CI Docs PyPI Python 3.13+ Platform: Linux and macOS License: MIT and Apache-2.0 Changelog Status: alpha Built on quantlab Factors: KunQuant

English | 简体中文

quantlab-factor-agent mines daily stock factors with language models, mechanism first. A model states an economic mechanism and writes the factor it implies as KunQuant code. Fixed checks and statistics from quantlab then decide whether the factor is new and adds to the factors you already have. The model only proposes and reviews, and it sees nothing but the training segment.

Documentation · Example configs · Changelog

Status: alpha (0.x). The API, the config format and the run directory's layout may change between minor versions.

How it works

Each round: the planner picks directions, the proposer writes candidates, the Gate checks them in a sandbox, the reviewer checks that hypothesis and code agree, the Evaluator scores them on the training segment and admission decides; trials go to the ledger for the next round. After the campaign, acceptance validates, opens the hold-out once and exports.

A campaign runs in rounds. The planner picks one research direction per slot, and the proposer writes a hypothesis, a description and KunQuant code for each. The Gate builds the code in a sandbox and refuses rewrites of existing factors; the reviewer checks that hypothesis and code describe the same factor. The Evaluator then scores what is left on the training segment, and admission accepts or rejects it. After the campaign, Acceptance trains a quantlab return model with and without the accepted factors, opens the hold-out once and exports the chosen factors.

  • Mechanism first. The Gate compares KunQuant graphs and refuses rewrites, parameter-only variants and large shared subtrees of every reference, known and accepted factor.
  • No look-ahead. Prompts carry training-segment statistics only: no return, no date, no validation or hold-out metric. The hold-out opens once, behind a lock.
  • Only code accepts. The Evaluator scores candidates on quantlab's whole-market panels, masked to each day's members, and the partial-IC t threshold tightens with every evaluated trial.
  • Nothing hard-coded about the market. Fields, operators, prompts, mechanism types and scoring come from the config's files, so a new input family is a new field file.
  • Any provider, replayable. Each role picks its backend: OpenAI-compatible endpoints (DeepSeek, OpenAI, vLLM, ...), Anthropic or Claude Code. Every call is logged, and the replay backend reproduces a run byte for byte without a provider.
  • Resumable. run() picks up from the run directory after a crash or an exhausted balance.

The diagram below shows how the parts fit together: what the models search, what each judge refuses, how every trial feeds the next round, and where the data the models see ends. How the agent mines factors explains it in full.

The four parts of the mechanism: language models search over mechanism types and directions; the Gate, the reviewer, the Evaluator and admission each refuse what is not valid, consistent, new or significant; accepted factors join the zoo and pool and every trial feeds back to the planner; the models see only training-segment statistics, and the hold-out opens once behind a lock.

With themes turned on, the planner also reads a map of the directions tried so far; see the direction map.

Install

You need Python 3.13+ and a C++ compiler on the PATH (KunQuant compiles factor graphs to native code):

pip install "quantlab-factor-agent[web]"   # [web] adds the factor-agent-web frontend

To work on the code, or to run the example configs and the offline test suite, install from a checkout with uv, with quantlab's checkout beside it:

git clone https://github.com/ZhaorongDai/quantlab.git
git clone https://github.com/ZhaorongDai/quantlab-factor-agent.git
cd quantlab-factor-agent
uv sync --extra web
uv run pytest -n auto    # offline: no LLM call, a synthetic market

On macOS, xgboost also needs brew install libomp. Keys come from environment variables only (ANTHROPIC_API_KEY, or the variable a role's api_key_env names), and a config that holds a key is refused. See installation.

Run a campaign

from factor_agent.acceptance import Acceptance
from factor_agent.campaign import Campaign
from factor_agent.config import CampaignConfig

config = CampaignConfig.from_file("configs/us3000_ret5.yaml")
result = Campaign(config).run()          # resumes when run_dir already holds a state
print(result.stop, len(result.accepted), "accepted of", len(result.records))

report = Acceptance(config).validate()   # baseline vs baseline + accepted, on validation
print(report.markdown())

Point the config's data paths at your own quantlab stores first. A campaign runs for hours, mostly waiting on the model, and needs no GPU; Acceptance uses CUDA when it is available. Before a long run, factor-agent check <config> reports everything run() would refuse (a store that does not exist, an unset API key variable, a resume that changed the config) in seconds, without writing anything; --ping also sends each backend one short request.

Watch a run in the browser

factor-agent-web runs/    # then open http://127.0.0.1:8000

The web panel lists your runs and opens each one: whether its accepted factors improve your model, a card per factor, every trial on a Lineage graph and the admission map, the LLM calls of the round in progress, the memory and the config. It only reads the run directory, listens on localhost only, and on a server you reach it through an SSH tunnel. See the web frontend.

The trials page: a round's plan with its Picked parents outlined in blue, the Lineage graph of every trial by round with arrows from parent to child, and the admission map of partial-IC t against the largest correlation with an existing factor

Building on earlier trials

Every trial after the first round either starts a new direction or builds on an earlier one, its parent, as a refinement or a mutation. A trial's Lineage sums up the trials built on it: how many, how many stopped early, which were accepted and how far the best got. With context.lineage the planner and the proposer read it. With round.picked_parents: k the code, not the planner, chooses the parents of k slots each round, the Picked parents: it ranks the evaluated trials by quality, fertility and novelty, each shared over the Trial graph of trials related by generation, code structure and correlation, so a trial whose relatives did well rises with them. The trial_graph section sets how much is shared and how the graph is built. Both are off by default. The web panel's "why these parents" shows, for each round, how propagation moved each trial's utilities and rank:

The propagation view: per utility a trial's own value, its neighbours' average with the heaviest neighbours listed, and its value after propagation; beside it the rank ladder, where the trial rises from rank 15 to rank 10

See building on earlier trials and the campaign config.

Documentation

Contributing

Bug reports, questions and pull requests are welcome; see CONTRIBUTING.md. Report security problems privately, as SECURITY.md describes.

License

MIT. factor_agent/_max_drawdown.py adapts code from KunQuant under the Apache License 2.0.

Metadata

Release files for quantlab-factor-agent 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantlab-factor-agent 0.2.0
File Size Uploaded Provenance Actions
quantlab_factor_agent-0.2.0.tar.gz 446.7 kB With provenance Details for quantlab_factor_agent-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quantlab-factor-agent 0.2.0
File Interpreter ABI Platform Actions
quantlab_factor_agent-0.2.0-py3-none-any.whl Python 3 none any Details for quantlab_factor_agent-0.2.0-py3-none-any.whl

Total release size: 780.5 kB

Release files / quantlab_factor_agent-0.2.0.tar.gz

Download URL quantlab_factor_agent-0.2.0.tar.gz
Size 446.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d2da4a6906aa057ff5414d0a299c6bd7533bb274ac6e55f94e74659c240f867b
BLAKE2b-256 checksum
How to use checksums
dda86159c85bd06f013bf4b151c2c39173ed18857b61f5e60f365b2851b04d59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / quantlab_factor_agent-0.2.0-py3-none-any.whl

Download URL quantlab_factor_agent-0.2.0-py3-none-any.whl
Size 333.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0afe69babae04df496520a30fbaae0dd1cc2a5f5e6e44e54dfa04266e0e7d923
BLAKE2b-256 checksum
How to use checksums
ca0436713a92b6863140008c957250aa20ce889ac33bd24a2a898a31bcad9ef5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Security for quantlab-factor-agent 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for quantlab_factor_agent-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page