Files
signal-platform/alembic/versions/016_add_signal_context_snapshots.py
T
dennisthiessen 80b4113280
Deploy / lint (push) Successful in 7s
Deploy / test (push) Successful in 1m1s
Deploy / deploy (push) Successful in 33s
feat: add strategy variant lab and signal context snapshots
Backtest report now includes research-only hold-to-horizon portfolio variants comparing raw vs residual 12-1 momentum, cutoff 80 vs 90, max 10 vs 15 positions, and SPY-200 risk scaling. A dynamic research recommendation panel flags residual momentum, cutoff 90, or regime scaling only when transparent promotion rules pass.

Adds signal_context_snapshots with migration 016 and captures one point-in-time context row per newly generated TradeSetup: setup fields, composite/dimensions, latest sentiment, latest fundamentals, and strategy_version=momentum_12_1_rr_time_v1. This is forward-only; no historical sentiment/fundamental backfill is attempted.

No live gate, paper-trade exit, or production ranking behavior changes.

Verification: 458 backend tests pass, ruff check app/ clean, frontend npm run build clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 16:25:04 +02:00

56 lines
2.2 KiB
Python

"""add signal context snapshots
Revision ID: 016
Revises: 015
Create Date: 2026-07-02 00:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "016"
down_revision: Union[str, None] = "015"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"signal_context_snapshots",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("trade_setup_id", sa.Integer(), nullable=False),
sa.Column("ticker_id", sa.Integer(), nullable=False),
sa.Column("detected_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("strategy_version", sa.String(length=80), nullable=False),
sa.Column("direction", sa.String(length=10), nullable=False),
sa.Column("entry_price", sa.Float(), nullable=False),
sa.Column("stop_loss", sa.Float(), nullable=False),
sa.Column("target", sa.Float(), nullable=False),
sa.Column("rr_ratio", sa.Float(), nullable=False),
sa.Column("confidence_score", sa.Float(), nullable=True),
sa.Column("recommended_action", sa.String(length=20), nullable=True),
sa.Column("risk_level", sa.String(length=10), nullable=True),
sa.Column("momentum_percentile", sa.Float(), nullable=True),
sa.Column("score_context_json", sa.Text(), nullable=False),
sa.Column("sentiment_context_json", sa.Text(), nullable=False),
sa.Column("fundamental_context_json", sa.Text(), nullable=False),
sa.ForeignKeyConstraint(["ticker_id"], ["tickers.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["trade_setup_id"], ["trade_setups.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("trade_setup_id", name="uq_signal_context_trade_setup"),
)
op.create_index(
"ix_signal_context_ticker_detected",
"signal_context_snapshots",
["ticker_id", "detected_at"],
)
def downgrade() -> None:
op.drop_index("ix_signal_context_ticker_detected", table_name="signal_context_snapshots")
op.drop_table("signal_context_snapshots")