redesign activation gate to expected value + make pipelines cron-configurable
Diagnosing "no qualified signals for 5 days": setups were generated but none qualified. The gate required BOTH a high min_rr (2.0) AND a high min_target_probability (60), which became contradictory after the Jun-15 probability recalibration — probability already embeds R:R via the 1/(rr+1) ruin term, so high-R:R targets are inherently low-probability and nothing cleared both. Gate is now expected value (R): p*rr - (1-p) from the primary target's probability. R:R and confidence stay as floors; high-conviction / exclude-conflicts / min-target-probability become optional tighteners (default off). Defaults: min_expected_value=0.15, min_rr=1.2, min_confidence=55. EV is only enforced when computable. Migration 009 clears stored activation_* rows so the new defaults apply. Backtest sweeps min_expected_value instead of target probability. Scheduling: pipelines are now cron-configurable in Admin -> Jobs. daily_pipeline (full, default 0 7 * * *) plus a new light intraday_pipeline (OHLCV + outcome eval, default hourly US session) that keeps prices/live-R:R current without setup churn. Fundamentals on its own early weekly cron. Timezone configurable (default Europe/Berlin). Moving interval->CronTrigger also fixes the restart-deferral bug where an interval job's countdown resets on every process restart. 319 backend unit tests pass; frontend tsc clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
"""Shared definition of a 'qualified' (actionable) trade setup.
|
||||
|
||||
A single predicate, driven by the admin activation config, used by the
|
||||
performance stats (server) and mirrored on the frontend. Beyond raw R:R and
|
||||
confidence, an actionable setup must show genuine conviction: a high-conviction
|
||||
recommended action, a clean (conflict-free) read, and a probable primary target.
|
||||
performance stats (server) and mirrored on the frontend. The core gate is
|
||||
expected value (in R): a setup must promise positive, probability-weighted
|
||||
asymmetry, not just a fat-but-improbable target or a likely-but-thin one. R:R
|
||||
and confidence remain as floors, and conviction/conflict/target-probability
|
||||
survive as optional tighteners (off by default).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -20,6 +22,37 @@ def best_target_probability(setup: Any) -> float:
|
||||
return max(probs, default=0.0)
|
||||
|
||||
|
||||
def primary_target_probability(setup: Any) -> float | None:
|
||||
"""Probability of the starred primary target (the one the headline R:R refers
|
||||
to). Falls back to the best target's probability when none is flagged primary,
|
||||
and None when there are no targets at all (probability unknowable).
|
||||
"""
|
||||
targets = getattr(setup, "targets", None) or []
|
||||
primary = next(
|
||||
(t for t in targets if isinstance(t, dict) and t.get("is_primary")), None
|
||||
)
|
||||
if primary is not None:
|
||||
return float(primary.get("probability", 0.0))
|
||||
probs = [float(t.get("probability", 0.0)) for t in targets if isinstance(t, dict)]
|
||||
return max(probs) if probs else None
|
||||
|
||||
|
||||
def expected_value_r(setup: Any) -> float | None:
|
||||
"""Expected value per unit of risk, in R: ``p·(R:R) − (1 − p)``.
|
||||
|
||||
``p`` is the primary target's hit probability. This single number captures
|
||||
"is this worth taking": it rewards both a good payoff ratio and a likely
|
||||
target, so a fat-but-improbable target can't outrank a solid, probable one —
|
||||
and a high R:R no longer fights a high probability the way the old separate
|
||||
gates did. Returns None when no target probability is known.
|
||||
"""
|
||||
p = primary_target_probability(setup)
|
||||
if p is None:
|
||||
return None
|
||||
p = p / 100.0
|
||||
return p * setup.rr_ratio - (1.0 - p)
|
||||
|
||||
|
||||
def live_risk_reward(setup: Any, current_price: float) -> float | None:
|
||||
"""R:R recomputed from the CURRENT price, not the (possibly stale) entry.
|
||||
|
||||
@@ -43,6 +76,11 @@ def setup_qualifies(setup: Any, config: dict) -> bool:
|
||||
|
||||
``setup`` is duck-typed: any object exposing rr_ratio, confidence_score,
|
||||
recommended_action, risk_level and a ``targets`` list of dicts.
|
||||
|
||||
Gate order: R:R floor → freshness (live R:R) → confidence floor → expected
|
||||
value (the core test) → optional conviction / conflict / target-probability
|
||||
tighteners. ``min_expected_value`` defaults to -inf for callers that pass a
|
||||
legacy config without the key, so they behave exactly as before.
|
||||
"""
|
||||
if setup.rr_ratio < config["min_rr"]:
|
||||
return False
|
||||
@@ -56,6 +94,13 @@ def setup_qualifies(setup: Any, config: dict) -> bool:
|
||||
return False
|
||||
if (setup.confidence_score or 0.0) < config["min_confidence"]:
|
||||
return False
|
||||
# Expected value (R): the core gate. Only enforced when computable — setups
|
||||
# without target probabilities (e.g. legacy historical rows) defer to the
|
||||
# R:R + confidence floors above rather than being silently dropped.
|
||||
min_ev = float(config.get("min_expected_value", float("-inf")))
|
||||
ev = expected_value_r(setup)
|
||||
if ev is not None and ev < min_ev:
|
||||
return False
|
||||
if config.get("require_high_conviction"):
|
||||
if (setup.recommended_action or "") not in HIGH_CONVICTION_ACTIONS:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user