跳至正文
返回文库全部文档

审计交易策略之间的 LEAN 一致性

笔记本 《交易机器学习》

总结

本笔记分析一项真实策略审计的留存结果,比较 LEAN 引擎与匹配的 ML4T 回测配置。它列出冻结输入所支持的资产类别工作负载,并报告成交、估值、估值时间戳、权益差异和期末价值方面的一致性证据。由于现有连续合约根价格缺少原生 LEAN 订阅所需的带日期合约链和展期映射,因此不纳入 CME 期货工作负载。

笔记还比较了仅引擎运行时间:计时围绕引擎调用进行,不包括输入加载、推断、目标构建、准备和报告。这些数据仅适用于固定的版本、输入和计时边界。笔记还列出一条合成压力测试记录,用于诊断规模和配置,与真实策略比较分开呈现。本笔记提供的是审计结果,并未对框架速度或等效性作出普遍结论;一致性发现仅限于受支持的工作负载和冻结的数据包。

核心观点

  • 审计比较 LEAN 与 ML4T 回测在成交、估值、时间戳和期末结果方面的表现。
  • 冻结输入支持 ETF、加密货币永续合约、以 USD 报价的 FX 以及 US 股票工作负载。
  • CME 期货案例不受支持,因为缺少所需的带日期合约链和展期映射。
  • 仅引擎计时不包括数据准备、推断、适配器处理和报告。
  • 合成压力测试结果用于诊断,应与真实策略证据区分开来。

标签

全文
# LEAN Parity on Current Case-Study Strategies


# LEAN Parity on Current Case-Study Strategies

This notebook isolates the LEAN rows from the current real-strategy audit. It uses retained results
generated by the native LEAN engine and the matching ML4T Backtest profiles. The shared inputs are
frozen before engine execution.

**Learning objectives**

- Identify which selected asset classes are valid LEAN comparisons
- Read LEAN parity across fills, valuations, and terminal value
- Interpret LEAN engine-only timing on the measured strategies
- Keep synthetic stress evidence separate from real-strategy equivalence

**Book reference**: Chapter 16, Section 16.3

## Setup

```python
"""Current LEAN parity evidence."""

import json

import polars as pl
from IPython.display import Markdown, display

from utils.paths import get_chapter_dir
```

```python
# Production defaults - Papermill injects overrides after this cell
ROUND_SECONDS = 3
```

```python
AUDIT_PATH = get_chapter_dir(16) / "resources" / "framework_parity_audit.json"
audit = json.loads(AUDIT_PATH.read_text(encoding="utf-8"))
lean = audit["frameworks"]["lean"]
LEAN_NAME = f"{lean['display_name']} {lean['version']}"
CASE_NAMES = {
    "etfs": "ETF allocation",
    "cme_futures": "CME futures",
    "crypto_perps_funding": "Crypto perpetual funding",
    "fx_pairs": "FX allocation (USD-quoted pairs)",
    "us_equities_panel": "US equity panel",
}
```

```python
display(Markdown(f"**Pinned engine:** {LEAN_NAME} with ML4T profile `{lean['profile']}`"))
```

## 1. Supported real strategies

LEAN is required for the ETF, crypto-perpetual, USD-quoted foreign-exchange, and US equity-panel
workloads. The CME row is unsupported for this particular frozen bundle: it contains continuous
root prices but lacks the dated contract chain and roll map needed to construct a native LEAN
futures subscription.

```python
lean_results = (
    pl.DataFrame(audit["real_strategy_records"])
    .filter(pl.col("framework") == "lean")
    .with_columns(pl.col("case_study").replace_strict(CASE_NAMES).alias("strategy"))
    .select(
        "strategy",
        "status",
        "fills",
        "valuations",
        "valuation_timestamps_match",
        "equity_gap",
        "equity_raw_gap",
        "terminal_gap",
        "terminal_raw_gap",
        "negative_control_detected",
    )
)

assert lean_results.height == 4
assert lean_results["status"].to_list() == ["pass"] * 4
assert lean_results["valuation_timestamps_match"].all()
assert lean_results["negative_control_detected"].all()

display(lean_results)
```

```python
lean_unsupported = (
    pl.DataFrame(audit["unsupported_records"])
    .filter(pl.col("framework") == "lean")
    .with_columns(pl.col("case_study").replace_strict(CASE_NAMES).alias("strategy"))
    .select("strategy", "reason")
)
display(lean_unsupported)
```

The table reports the complete fill and valuation counts for each supported workload. LEAN uses
native equity, crypto-future, and foreign-exchange securities. The audit does not convert the
continuous CME roots into a different instrument merely to add a LEAN row.

## 2. Engine-only timing

The timer starts immediately before the engine call and stops when it returns. One warmup and ten
process-isolated samples are used. Input loading, model inference, target construction, adapter
preparation, result extraction, and reporting are outside the timed region.

```python
lean_timing = (
    pl.DataFrame(audit["performance_records"])
    .filter(pl.col("framework") == "lean")
    .with_columns(
        pl.col("case_study").replace_strict(CASE_NAMES).alias("strategy"),
        pl.col("framework_median_seconds").round(ROUND_SECONDS).alias("lean_seconds"),
        pl.col("ml4t_median_seconds").round(ROUND_SECONDS).alias("ml4t_seconds"),
        pl.col("framework_to_ml4t_ratio").round(2).alias("lean_div_ml4t"),
    )
    .select("strategy", "lean_seconds", "ml4t_seconds", "lean_div_ml4t")
)
display(lean_timing)
```

The timing result applies to these pinned versions, bundles, and engine boundaries. It is not a
general LEAN performance claim.

## 3. Synthetic stress remains diagnostic

```python
lean_stress = (
    pl.DataFrame(audit["synthetic_stress"]["records"])
    .filter(pl.col("framework") == "lean")
    .select("intents", "fills", "trades", "terminal_value", "status")
)
display(lean_stress)
```

The retained stress row tests scale and the calibrated LEAN profile on generated inputs. The
supported rows above provide the real-data evidence.

在遵守原作品许可的前提下,附作者信息全文展示。 许可协议: MIT

此摘要由 Stratmill 研究智能体根据原文撰写,并非原文副本。