News informational-only: gate sentiment bonus/penalty off by default

Add NewsConfig.sentiment_affects_signals (default False), gating the +5
aligned-sentiment confidence bonus and the 10-pt news_conflict penalty.
With event_risk_caps_signals already False, live decisions are now pure
technical, matching the backtester (use_news=False). Warnings and the
sentiment display are unchanged. Adds a gating regression test.

Claude-Session: https://claude.ai/code/session_01FMaaPdrrrQuh1VvGQH1icN
This commit is contained in:
Harwinder Sekhon
2026-07-17 16:02:47 -04:00
parent c87bb14830
commit c21c102536
4 changed files with 45 additions and 7 deletions
+32
View File
@@ -1240,6 +1240,38 @@ def _():
assert PlatformConfig().news.event_risk_caps_signals is False
@test("Sentiment signal gating obeys news.sentiment_affects_signals")
def _():
config = PlatformConfig()
agg = SignalAggregator(config)
dfs = {
Timeframe.H1: make_ohlcv(300, seed=42),
Timeframe.M15: make_ohlcv(300, seed=43),
Timeframe.H4: make_ohlcv(300, seed=44),
}
report = agg.analyze_from_dataframes("XAU/USD", dfs, use_news=False)
def recompute(sentiment, affects):
config.news.sentiment_affects_signals = affects
report.news_sentiment = sentiment
report.warnings = []
agg._compute_final_signal(report)
return report.final_confidence
score_sign = 1 if report.primary_score >= 0 else -1
aligned, conflicting = 0.5 * score_sign, -0.5 * score_sign
baseline = recompute(0.0, False)
# default: neither aligned sentiment nor conflict moves confidence
assert recompute(aligned, False) == baseline, "aligned sentiment must not add confidence"
assert recompute(conflicting, False) == baseline, "conflicting sentiment must not penalize"
assert any("CONFLICTS" in w for w in report.warnings), "conflict warning must persist"
# flag on: aligned sentiment adds confidence again
assert recompute(aligned, True) > baseline, "flag on must restore the alignment bonus"
# PlatformConfig default is off (news is informational only)
assert PlatformConfig().news.sentiment_affects_signals is False
@test("SignalAggregator._generate_trade_setup BUY direction")
def _():
config = PlatformConfig()