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:
@@ -36,7 +36,11 @@ from app.services.outcome_service import (
|
||||
evaluate_setup_against_bars,
|
||||
)
|
||||
from app.services.price_service import query_ohlcv
|
||||
from app.services.qualification import best_target_probability, setup_qualifies
|
||||
from app.services.qualification import (
|
||||
best_target_probability,
|
||||
expected_value_r,
|
||||
setup_qualifies,
|
||||
)
|
||||
from app.services.recommendation_service import (
|
||||
_choose_recommended_action,
|
||||
_classify_by_probability,
|
||||
@@ -131,6 +135,10 @@ def _window_setups(
|
||||
primary = _select_primary_target(targets)
|
||||
if primary is None:
|
||||
continue
|
||||
# Flag the primary so qualification's EV uses the primary target's
|
||||
# probability (matching production's enhance_trade_setup).
|
||||
for t in targets:
|
||||
t["is_primary"] = t is primary
|
||||
per_dir[direction] = {"stop": stop, "targets": targets, "primary": primary}
|
||||
|
||||
available = set(per_dir.keys())
|
||||
@@ -160,12 +168,13 @@ def _window_setups(
|
||||
stop_loss=stop,
|
||||
entry_price=entry,
|
||||
)
|
||||
# meets_core = clears every gate EXCEPT target probability, so the report
|
||||
# can sweep the min_target_probability threshold without re-replaying.
|
||||
core_config = {**activation, "min_target_probability": 0.0}
|
||||
# meets_core = clears every gate EXCEPT the expected-value floor, so the
|
||||
# report can sweep the min_expected_value threshold without re-replaying.
|
||||
core_config = {**activation, "min_expected_value": float("-inf")}
|
||||
meets_core = setup_qualifies(setup_ns, core_config)
|
||||
ev = expected_value_r(setup_ns)
|
||||
best_prob = best_target_probability(setup_ns)
|
||||
min_tp = float(activation.get("min_target_probability", 0.0))
|
||||
min_ev = float(activation.get("min_expected_value", 0.0))
|
||||
out.append({
|
||||
"direction": direction,
|
||||
"entry": entry,
|
||||
@@ -175,10 +184,11 @@ def _window_setups(
|
||||
"confidence": confidences[direction],
|
||||
"primary_prob": float(primary["probability"]),
|
||||
"best_prob": best_prob,
|
||||
"ev": ev,
|
||||
"meets_core": meets_core,
|
||||
"action": action,
|
||||
"risk_level": risk_level,
|
||||
"qualified": meets_core and best_prob >= min_tp,
|
||||
"qualified": meets_core and ev is not None and ev >= min_ev,
|
||||
})
|
||||
return out
|
||||
|
||||
@@ -216,6 +226,7 @@ def _replay_ticker(symbol: str, records: list, config: dict, activation: dict) -
|
||||
"confidence": s["confidence"],
|
||||
"primary_prob": s["primary_prob"],
|
||||
"best_prob": s["best_prob"],
|
||||
"ev": s["ev"],
|
||||
"meets_core": s["meets_core"],
|
||||
"qualified": s["qualified"],
|
||||
"outcome": outcome,
|
||||
@@ -288,14 +299,17 @@ async def run_backtest(
|
||||
longs = [c for c in qualified if c["direction"] == "long"]
|
||||
shorts = [c for c in qualified if c["direction"] == "short"]
|
||||
|
||||
# Threshold sweep: re-apply the gate at several min_target_probability values
|
||||
# Threshold sweep: re-apply the gate at several min_expected_value values
|
||||
# (holding the other conditions fixed) so the trade-off between how many
|
||||
# setups qualify and their expectancy is visible without re-replaying.
|
||||
current_min_tp = float(activation.get("min_target_probability", 60.0))
|
||||
current_min_ev = float(activation.get("min_expected_value", 0.15))
|
||||
sweep = []
|
||||
for threshold in (60, 55, 50, 45, 40, 35, 30):
|
||||
cands = [c for c in candidates if c["meets_core"] and c["best_prob"] >= threshold]
|
||||
sweep.append({"min_target_probability": threshold, **_bucket_stats(cands)})
|
||||
for threshold in (0.4, 0.3, 0.25, 0.2, 0.15, 0.1, 0.05, 0.0):
|
||||
cands = [
|
||||
c for c in candidates
|
||||
if c["meets_core"] and c["ev"] is not None and c["ev"] >= threshold
|
||||
]
|
||||
sweep.append({"min_expected_value": threshold, **_bucket_stats(cands)})
|
||||
|
||||
return {
|
||||
"generated_at": datetime.now(timezone.utc).isoformat(),
|
||||
@@ -310,7 +324,7 @@ async def run_backtest(
|
||||
"long": _bucket_stats(longs),
|
||||
"short": _bucket_stats(shorts),
|
||||
},
|
||||
"min_target_probability": current_min_tp,
|
||||
"min_expected_value": current_min_ev,
|
||||
"sweep": sweep,
|
||||
"calibration": _calibration(candidates),
|
||||
"note": (
|
||||
|
||||
Reference in New Issue
Block a user