contrarian-setup-gate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Contrarian Setup Gate

逆向投资配置网关

Overview

概述

Synthesize the outputs of Jason Shapiro's 3-step contrarian process into one actionable state. cot-contrarian-detector (step 1) flags crowded positioning, news-reaction-failure-analyzer (step 2) tests whether the market failed to react to news favorable to the crowd, and technical-analyst's contrarian-confirmation mode (step 3) confirms weekly price-action evidence of a reversal. This gate reads those three report JSONs and applies an explicit, exhaustively-tested precedence rule set to produce one
setup_status
, with a fail-closed reason attached to every input that could not be confirmed.
The gate does no fetching, no API calls, and no computation beyond validating and combining the three inputs it is given. It is the pipeline's synthesis center, not a data source.
将Jason Shapiro三步逆向投资流程的输出整合为一个可执行状态。cot-contrarian-detector(第一步)标记拥挤持仓情况,news-reaction-failure-analyzer(第二步)测试市场是否未对有利于持仓群体的新闻做出反应,technical-analyst的逆向确认模式(第三步)确认周价格走势的反转迹象。该网关读取这三份报告JSON,并应用一套经过全面测试的明确优先级规则集,生成一个
setup_status
,同时为每一项无法确认的输入附上故障关闭原因。
该网关不进行任何数据抓取、API调用,仅对给定的三个输入进行验证和整合,无额外计算。它是流程的整合中心,而非数据源。

When to Use

使用场景

  • After running cot-contrarian-detector (always required -- this is the pipeline's entry point)
  • Mid-pipeline, with only the detector report, to see the CROWDED state and what steps remain
  • After running news-reaction-failure-analyzer, to see whether the setup advances to WATCHING_PRICE or is REJECTED
  • After running technical-analyst's contrarian-confirmation mode, to see whether the setup reaches READY_FOR_PLAN
  • Before handing a symbol's direction and stop level to a position-sizing skill
  • 运行cot-contrarian-detector之后(此为流程的必填入口步骤)
  • 流程中途,仅持有检测器报告时,查看CROWDED状态及剩余待执行步骤
  • 运行news-reaction-failure-analyzer之后,查看配置是否推进至WATCHING_PRICE状态或被REJECTED
  • 运行technical-analyst的逆向确认模式之后,查看配置是否达到READY_FOR_PLAN状态
  • 将标的的方向和止损水平交付给仓位管理工具之前

Prerequisites

前置条件

  • Python 3.9+
  • No API keys -- this skill is fully offline
  • A cot-contrarian-detector JSON report for the symbol under evaluation (required)
  • Optionally, a news-reaction-failure-analyzer JSON report for the same symbol (step 2)
  • Optionally, a technical-analyst contrarian-confirmation JSON report for the same symbol (step 3)
  • Python 3.9+
  • 无需API密钥——本工具完全离线运行
  • 待评估标的的cot-contrarian-detector JSON报告(必填)
  • 可选:同一标的的news-reaction-failure-analyzer JSON报告(第二步)
  • 可选:同一标的的technical-analyst逆向确认JSON报告(第三步)

Workflow

工作流程

Step 1: Run the Gate

步骤1:运行网关

bash
python3 skills/contrarian-setup-gate/scripts/run_contrarian_setup_gate.py \
  --symbol B6 \
  --detector-json reports/cot_crowding_2026-07-12.json \
  --news-json reports/nrf_B6_2026-07-12.json \
  --price-action-json reports/ta_confirmation_B6_2026-07-12.json \
  --as-of 2026-07-15 \
  --output-dir reports/
--symbol
and
--detector-json
are required;
--news-json
and
--price-action-json
are optional -- omit either to see the state at that pipeline stage.
--as-of
is required (no implicit "today"): staleness is always evaluated against an explicit reference date so reruns are deterministic.
Exit behavior is intentionally asymmetric: a missing or malformed
--as-of
(or any other CLI usage error) is an operator config mistake, so the CLI exits
2
with usage text and writes no report. A problem with one of the three untrusted report files -- unreadable, malformed, stale, inconsistent -- is always handled fail-closed instead: the CLI exits
0
and writes a report naming the reason, exactly like every other skill in this pipeline.
bash
python3 skills/contrarian-setup-gate/scripts/run_contrarian_setup_gate.py \
  --symbol B6 \
  --detector-json reports/cot_crowding_2026-07-12.json \
  --news-json reports/nrf_B6_2026-07-12.json \
  --price-action-json reports/ta_confirmation_B6_2026-07-12.json \
  --as-of 2026-07-15 \
  --output-dir reports/
--symbol
--detector-json
为必填项;
--news-json
--price-action-json
为可选项——省略任意一项即可查看流程对应阶段的状态。
--as-of
为必填项(无默认“今日”值):始终基于明确的参考日期评估数据时效性,确保重复运行结果一致。
退出行为具有明确的不对称性:若
--as-of
缺失或格式错误(或其他CLI使用错误),属于操作者配置失误,CLI将以状态码
2
退出并输出使用说明,且不生成报告。若三份不可信报告文件存在问题——无法读取、格式错误、过期、不一致——则始终按故障关闭逻辑处理:CLI以状态码
0
退出并生成报告,明确标注原因,与本流程中的其他工具保持一致。

Step 2: Read the Setup Status

步骤2:查看配置状态

StatusMeaningNext Step
READY_FOR_PLAN
All three steps confirmed; direction, entry_trigger, and invalidation_level are populatedHand
direction
and
invalidation_level
to a position-sizing skill
WATCHING_PRICE
Crowding + news confirmed; price action still pendingRun technical-analyst's contrarian-confirmation mode
CROWDED
Crowding confirmed; news and/or price still pendingRun news-reaction-failure-analyzer
REJECTED
Crowding is NOT_CONFIRMED (classification NEUTRAL), or news/price came back NOT_CONFIRMEDStop -- do not run further steps for this symbol/direction
INSUFFICIENT_EVIDENCE
A required input is missing, unreadable, stale, inconsistent, or could not itself reach a verdictStop -- fix or regenerate the named input before rerunning
missing_confirmations
lists every step still blocking, with its
state
and
reason
.
warnings
never change the status -- they flag audit-worthy conditions such as a MEDIUM-confidence confirming signal or a near-stale input.
状态含义下一步操作
READY_FOR_PLAN
三步均已确认;已填充方向、entry_trigger和invalidation_level
direction
invalidation_level
交付给仓位管理工具
WATCHING_PRICE
拥挤度+新闻反应已确认;价格走势仍待确认运行technical-analyst的逆向确认模式
CROWDED
拥挤度已确认;新闻反应和/或价格走势仍待确认运行news-reaction-failure-analyzer
REJECTED
拥挤度未确认(分类为NEUTRAL),或新闻反应/价格走势未确认终止——无需对该标的/方向执行后续步骤
INSUFFICIENT_EVIDENCE
缺失必填输入、输入无法读取、过期、不一致,或无法得出判定结果终止——修复或重新生成指定输入后再重新运行
missing_confirmations
列出所有仍未完成的步骤及其
state
reason
warnings
不会改变状态——仅标记需审计的情况,如中等置信度的确认信号或接近过期的输入。

Step 3: Act on READY_FOR_PLAN Only

步骤3:仅对READY_FOR_PLAN状态执行操作

At
READY_FOR_PLAN
,
direction
(SHORT/LONG, the fade side of the crowd),
entry_trigger
(a factual echo of the confirming weekly signal), and
invalidation_level
(the stop reference from the price-action report) are populated.
gate_confidence
is the weaker of the news and price-action confidences (HIGH/MEDIUM/LOW --
LOW
is a token both upstream skills document as reserved but never actually emit; the gate accepts it and ranks it weakest rather than rejecting it as unknown). Position sizing is the next pipeline stage (not yet built as of this skill's release -- see the roadmap in the repository's workflow docs); this gate never places or recommends an order.
当状态为
READY_FOR_PLAN
时,
direction
(SHORT/LONG,即反向操作持仓群体的方向)、
entry_trigger
(确认周信号的事实性描述)和
invalidation_level
(价格走势报告中的止损参考值)已填充。
gate_confidence
取新闻反应和价格走势置信度中的较低值(HIGH/MEDIUM/LOW——
LOW
为上游工具预留但实际从未输出的标识;网关会接受该值并将其列为最低置信度,而非视为未知值拒绝)。仓位管理为流程的下一阶段(本工具发布时尚未开发——详见仓库工作流文档中的路线图);本网关绝不下达或推荐订单。

Precedence (Summary)

优先级规则(摘要)

Each step is evaluated in strict pipeline order -- crowding, then news, then price-action -- and each step fully settles before the next step's file is even consulted. An earlier step's definitive verdict is never softened by a later step's problem.
  1. Crowding is evaluated first and exclusively: INVALID/INSUFFICIENT crowding is always
    INSUFFICIENT_EVIDENCE
    ; a NOT_CONFIRMED (NEUTRAL) classification is always
    REJECTED
    , regardless of any downstream file's state or corruption.
  2. With crowding CONFIRMED, news is evaluated next, on its own: INVALID (unreadable, malformed, stale, symbol mismatch, direction mismatch, unsupported schema) forces
    INSUFFICIENT_EVIDENCE
    ; NOT_CONFIRMED forces
    REJECTED
    ; INSUFFICIENT forces
    INSUFFICIENT_EVIDENCE
    -- in every one of these cases, price-action is never even inspected for the decision.
  3. Once news is CONFIRMED (or PENDING, for out-of-order use), price-action is evaluated last, with the same four-way settlement. Running price-action before news (out-of-order pipeline use) caps the status at
    CROWDED
    with a warning -- a NOT_CONFIRMED price-action verdict still REJECTs even out of order, since price-action is still fully evaluated in that branch.
  4. Crowding confirmed, both downstream steps pending ->
    CROWDED
    .
  5. Crowding + news confirmed, price-action pending ->
    WATCHING_PRICE
    .
  6. All three confirmed ->
    READY_FOR_PLAN
    .
See
references/gate-decision-table.md
for the full decision table (every reachable {crowding} x {news} x {price-action} state combination), the reason-token glossary, and worked examples.
各步骤严格按照流程顺序评估——先拥挤度,再新闻反应,最后价格走势——且前一步骤得出明确判定后才会查看下一步骤的文件。早步骤的明确判定不会因晚步骤的问题而弱化。
  1. 首先且仅评估拥挤度:无效/证据不足的拥挤度始终对应
    INSUFFICIENT_EVIDENCE
    ;未确认(NEUTRAL)的分类始终对应
    REJECTED
    ,与下游文件的状态或损坏情况无关。
  2. 若拥挤度已确认,接下来评估新闻反应:无效(无法读取、格式错误、过期、标的不匹配、方向不匹配、不支持的 schema)将触发
    INSUFFICIENT_EVIDENCE
    ;未确认将触发
    REJECTED
    ;证据不足将触发
    INSUFFICIENT_EVIDENCE
    ——在上述所有情况下,价格走势文件不会被用于决策。
  3. 若新闻反应已确认(或流程乱序使用时处于待确认状态),最后评估价格走势,遵循相同的四种判定结果。若在新闻反应之前运行价格走势(流程乱序使用),状态将上限为
    CROWDED
    并附带警告——即使乱序,未确认的价格走势判定仍会触发
    REJECTED
    ,因为该分支中价格走势仍会被完整评估。
  4. 拥挤度已确认,下游两步均待确认 ->
    CROWDED
  5. 拥挤度+新闻反应已确认,价格走势待确认 ->
    WATCHING_PRICE
  6. 三步均已确认 ->
    READY_FOR_PLAN
详见
references/gate-decision-table.md
获取完整决策表(所有可达的{拥挤度}x{新闻反应}x{价格走势}状态组合)、原因标识术语表及示例。

Output Contract

输出约定

The script writes
contrarian_setup_gate_<SYMBOL>_<as-of>.json
and
.md
to
--output-dir
:
yaml
symbol: B6
setup_status: READY_FOR_PLAN | WATCHING_PRICE | CROWDED | REJECTED | INSUFFICIENT_EVIDENCE
direction: SHORT | LONG | null
gate_confidence: HIGH | MEDIUM | LOW | null
entry_trigger: string | null
invalidation_level: number | null
missing_confirmations: [{step, state, reason}, ...]
warnings: [string, ...]
inputs:
  crowding: {state, classification, data_date, age_days, report_path}
  news_failure: {state, verdict, confidence, verdict_reason, as_of, age_days, report_path}
  price_action: {state, verdict, confidence, verdict_reason, stop_reference, as_of, age_days, report_path}
run_context: {symbol, as_of, max_detector_age_days, max_report_age_days, schema_version, skill}
Every input's
state
is one of
CONFIRMED
,
NOT_CONFIRMED
,
INSUFFICIENT
,
PENDING
(report not provided), or
INVALID
(a report was provided but is unusable -- unreadable, malformed, stale, or inconsistent with the other inputs; always carries a named reason).
脚本会在
--output-dir
目录下生成
contrarian_setup_gate_<SYMBOL>_<as-of>.json
.md
文件:
yaml
symbol: B6
setup_status: READY_FOR_PLAN | WATCHING_PRICE | CROWDED | REJECTED | INSUFFICIENT_EVIDENCE
direction: SHORT | LONG | null
gate_confidence: HIGH | MEDIUM | LOW | null
entry_trigger: string | null
invalidation_level: number | null
missing_confirmations: [{step, state, reason}, ...]
warnings: [string, ...]
inputs:
  crowding: {state, classification, data_date, age_days, report_path}
  news_failure: {state, verdict, confidence, verdict_reason, as_of, age_days, report_path}
  price_action: {state, verdict, confidence, verdict_reason, stop_reference, as_of, age_days, report_path}
run_context: {symbol, as_of, max_detector_age_days, max_report_age_days, schema_version, skill}
每个输入的
state
为以下值之一:
CONFIRMED
NOT_CONFIRMED
INSUFFICIENT
PENDING
(未提供报告)或
INVALID
(提供了报告但无法使用——无法读取、格式错误、过期或与其他输入不一致;始终附带明确原因)。

Guardrails

防护规则

  1. Never places or recommends orders.
    READY_FOR_PLAN
    is the furthest state this skill reaches. Order entry and position sizing are separate, downstream decisions.
  2. INSUFFICIENT_EVIDENCE and REJECTED never advance. No warning, confidence, or partial input ever pushes the status past what the precedence rules allow.
  3. Fail closed on every input, always. An unreadable, malformed, stale, symbol-mismatched, or unknown-enum report is never treated as a pass -- it is named and blocks or downgrades the status. This includes the price-action report's
    verdict_reason
    (allowlisted against technical-analyst's actual confirming-signal vocabulary, not merely type-checked) and its
    stop_reference
    (must be a finite, positive number -- never non-finite, zero, negative, or a boolean). Before any of the three report files reaches this validation, the CLI also rejects a file outright (reason
    <input>_non_finite
    ) if it contains a non-finite number (
    Infinity
    /
    -Infinity
    /
    NaN
    , including an ordinary-looking number like
    1e309
    that overflows on parse) ANYWHERE in it, not just in a field the gate reads -- this is what keeps every report a valid, complete JSON file even under adversarial input.
  4. READY_FOR_PLAN
    always carries a usable plan.
    entry_trigger
    is guaranteed non-empty and
    invalidation_level
    is guaranteed a finite positive number whenever the status is
    READY_FOR_PLAN
    -- enforced both by input validation and by a defensive invariant check.
  5. Not investment advice.
    entry_trigger
    and
    invalidation_level
    are factual echoes of the upstream price-action report, not recommendations.
  1. 绝不下达或推荐订单
    READY_FOR_PLAN
    是本工具能达到的最高状态。订单下达和仓位管理是独立的下游决策环节。
  2. INSUFFICIENT_EVIDENCE和REJECTED状态绝不推进。任何警告、置信度或部分输入都不会突破优先级规则允许的状态上限。
  3. 对所有输入始终执行故障关闭逻辑。无法读取、格式错误、过期、标的不匹配或枚举值未知的报告绝不会被视为通过——会被明确标记并阻止或降低状态。这包括价格走势报告的
    verdict_reason
    (需与technical-analyst实际使用的确认信号词汇表匹配,而非仅做类型检查)及其
    stop_reference
    (必须为有限正数——绝不能是非有限值、零、负数或布尔值)。在对三份报告文件进行上述验证之前,若文件中任何位置包含非有限数值(
    Infinity
    /
    -Infinity
    /
    NaN
    ,包括解析时会溢出的普通数字如
    1e309
    ),CLI会直接拒绝该文件(原因标识为
    <input>_non_finite
    )——这确保即使在恶意输入下,每份报告仍是有效的完整JSON文件。
  4. READY_FOR_PLAN状态始终包含可用方案。当状态为
    READY_FOR_PLAN
    时,
    entry_trigger
    保证非空,
    invalidation_level
    保证为有限正数——通过输入验证和防御性不变量检查双重保障。
  5. 不构成投资建议
    entry_trigger
    invalidation_level
    是上游价格走势报告的事实性转述,而非建议。

Resources

资源

  • scripts/run_contrarian_setup_gate.py
    -- CLI: hardened JSON loading (unreadable / parse_error incl. RecursionError / non_finite via an iterative whole-file scan), report generation
  • scripts/gate_logic.py
    -- Pure synthesis core: normalization (incl. malformed-shape detection), consistency checks, the precedence state machine
  • references/gate-decision-table.md
    -- Full decision table, reason-token glossary, worked examples (including the real B6 REJECTED case)
  • scripts/run_contrarian_setup_gate.py
    ——CLI:增强型JSON加载(处理无法读取/解析错误包括RecursionError/通过迭代全文件扫描检测非有限值)、报告生成
  • scripts/gate_logic.py
    ——纯整合核心:标准化(包括格式错误检测)、一致性检查、优先级状态机
  • references/gate-decision-table.md
    ——完整决策表、原因标识术语表、示例(包括真实的B6标的REJECTED案例)