Why this RFC
QuantGPT's expression parser currently accepts pandas-style operators (ts_mean, cs_rank, ...) inline as Python expressions. This works but creates friction:
- AI agents need to learn syntax + valid operator names — scattered across docs/code, no formal grammar
- Users can't easily share factor definitions — expressions are tied to a Python execution context
- Reproducibility is fragile — operator semantics live in code, not in a spec
Platforms like WorldQuant BRAIN, Alphalens, and Qlib have moved to a dedicated factor DSL with explicit grammar, type checking, and a documented operator catalog.
Proposal sketch
factor "smart_momentum" {
inputs: close, volume, amount
formula: ts_corr(ts_returns(close, 5), volume / amount, 20)
universe: hs300
rebalance: daily
neutralize: industry
}
Compiled internally to the current Python expression representation. But:
.factor files are standalone, version-controllable, shareable
- Schema validation catches errors before backtest
- LLM agent's contract becomes deterministic ("emit one
.factor file")
Trade-offs
Pros
- Cleaner LLM agent contract (structured output > free-form Python)
- Factor definitions become first-class artifacts
- Foundation for a public factor library / leaderboard
- Validation before execution = faster iteration
Cons
- Yet-another-language to learn
- Implementation cost: parser, compiler, error messages
- Risk of feature gap vs. raw Python expressions
- Lock-in to specific operator semantics
Alternatives considered
- JSON / YAML factor specs — less expressive, no parser needed
- Python decorators — keep Python, enforce structure via
@factor(...)
- Status quo — stick with Python, invest in better docs
Questions for the community
- Have you needed to share factor definitions across projects or teams? How did you handle it?
- If you use WorldQuant BRAIN / Qlib, would a similar DSL feel natural here?
- Do LLM agents in your workflow benefit from structured output formats (function schemas, JSON tool calls)?
- Any DSL — good or bad — we should learn from?
This is exploratory. No commitment to implement. Comment with use cases, alternatives, or pushback.
Difficulty: N/A (discussion)
Why this RFC
QuantGPT's expression parser currently accepts pandas-style operators (
ts_mean,cs_rank, ...) inline as Python expressions. This works but creates friction:Platforms like WorldQuant BRAIN, Alphalens, and Qlib have moved to a dedicated factor DSL with explicit grammar, type checking, and a documented operator catalog.
Proposal sketch
Compiled internally to the current Python expression representation. But:
.factorfiles are standalone, version-controllable, shareable.factorfile")Trade-offs
Pros
Cons
Alternatives considered
@factor(...)Questions for the community
This is exploratory. No commitment to implement. Comment with use cases, alternatives, or pushback.
Difficulty: N/A (discussion)