Strategy specification

How to turn a trading idea into a quant strategy specification

“Buy strong stocks and control drawdown” describes an intention, but it does not tell a backtest what to do. A useful spec makes each decision explicit enough that two reviewers can identify the same inputs, trades and constraints. That reduces silent assumptions when AI turns a strategy description into code.

Published by FiClaw 产品团队 · Published · Updated

阅读中文版

Quick answer

A quant strategy specification is the reviewable agreement between an idea and its implementation. State the universe, data availability, signal, execution time, position sizing, exit rules, costs and test period before generating code. FiClaw can help turn a natural-language idea into a spec and Python; the researcher must resolve missing assumptions and check that the code follows the confirmed rules.

Key takeaways

  • Separate the research hypothesis from the rules that implement it.
  • Define when information becomes available and when an order may execute.
  • Confirm missing conditions before code generation, then review the implementation against the spec.

1. Define the contract between the idea and the code

Start with one research question: which observable behavior might explain the signal, and what result would challenge that idea? Then describe rules without words such as strong, cheap, timely or appropriate unless a formula or threshold defines them.

Specify the eligible instruments and their historical membership. A universe described as current index members is different from a universe reconstructed at each historical date. If the required historical membership or disclosure timing is unavailable, record that limitation before interpreting results.

  1. 01Inputs: instruments, fields, units, frequency, lookback and missing-data handling.
  2. 02Decisions: signal formula, ranking, ties, selection count and rebalance calendar.
  3. 03Execution: signal availability, order time, price convention and unfilled-order handling.
  4. 04Portfolio: capital, weights, cash, position limits, exits, fees and slippage.

2. Use a specification template before asking for Python

The following prompt is a workflow template, not a strategy recommendation. Replace placeholders with research choices. Ask for unresolved questions first so the AI does not quietly choose a universe, a price or an execution rule for you.

Research question: [the behavior to test and the reason for testing it]
Universe: [instruments; historical membership rule; inclusion/exclusion rules]
Data: [fields, frequency, adjustment convention, available-at timing]
Signal: [formula, lookback, thresholds, ranking and tie handling]
Decision schedule: [when the signal is calculated and positions reviewed]
Execution: [earliest order time, price convention, unfilled-order policy]
Portfolio: [capital, sizing, holding count, cash and position limits]
Exit rules: [rebalance, stop, time limit or other explicit conditions]
Constraints: [suspensions, price limits, trading lots and data gaps]
Costs: [fees, slippage and their calculation conventions]
Evaluation: [dates, benchmark, metrics and independent validation period]
Before coding: list ambiguous or unavailable conditions for confirmation.
After coding: map each rule to its implementation and proposed checks.

3. Replace ambiguous phrases with testable decisions

A more detailed prompt is useful only when its details settle actual choices. Check the gaps most likely to change a trade before reviewing the sophistication of the generated code.

3. Replace ambiguous phrases with testable decisions
Phrase in the ideaQuestion to resolveEvidence to review
Buy the best momentum stocksWhich return window, ranking direction, count and tie rule?Signal values and the selected list on a sample rebalance date
Trade at the closeIs the signal known before that close, and which execution assumption is feasible?Input timestamps, decision time and order time
Hold equal weightsAre weights reset at each rebalance, and how are cash and lot rounding handled?Target weights, submitted quantities and resulting holdings
Use financial dataWhich disclosure was available at the decision time?Disclosure availability, observation date and missing-value policy
Control riskWhich exposure, position or loss rule triggers which action?The explicit trigger and corresponding code path

4. Review the FiClaw implementation against the confirmed spec

FiClaw connects the strategy idea, spec, generated Python, historical backtest and diagnosis. Use that chain to compare the implementation with the confirmed rules. A run that completes successfully still needs a logic review: valid Python can implement the wrong signal timing or rebalance rule.

Inspect a small number of dates and trades by hand, including a missing-data case and a rebalance with constrained execution if those cases occur. Save the prompt, confirmed spec, code version, settings and review notes together. If a rule changes after the first run, create a new version and state the reason rather than rewriting the original experiment silently.

These checks are a suggested review process, not a claim that every item is automatically captured or audited by FiClaw. Capture any missing evidence separately and have a qualified reviewer confirm the implementation. The external initialization and warm-up references explain general concepts, not FiClaw's engine or default settings.

  1. 01Can a reviewer explain why each sampled instrument was eligible or excluded?
  2. 02Does every sampled signal use only information available at that time?
  3. 03Do target positions, orders, fills and costs follow the agreed rules?
  4. 04Are unavailable inputs and unresolved assumptions visible in the research record?

Frequently asked questions

What is the difference between a strategy prompt and a strategy spec?

A prompt asks the AI to perform a task and may contain an incomplete idea. A spec is the confirmed set of rules and assumptions that the code should implement. Keep both so a reviewer can see how the original idea became an experiment.

Should I let AI fill in missing strategy rules?

Ask AI to propose options and explain their consequences, then confirm the choices before coding. Universe membership, signal timing, execution, costs and missing-data handling can materially change a backtest and should not remain silent defaults.

Does a complete specification prove that a strategy works?

No. A complete spec makes an experiment understandable and reviewable. Data checks, implementation review, realistic execution assumptions, robustness tests and independent validation are still needed before interpreting its historical result.

Method and product references

Related reading

Turn a research question into a checkable experiment

Start with explicit strategy rules in FiClaw, then review the code, data assumptions and backtest results.