feat(ga): fitness v0 (DSR - dd_penalty * max_dd, kill on adversarial high)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
from multi_swarm.agents.adversarial import AdversarialReport, Finding, Severity
|
||||
from multi_swarm.agents.falsification import FalsificationReport
|
||||
from multi_swarm.ga.fitness import compute_fitness
|
||||
|
||||
|
||||
def make_falsification(
|
||||
dsr: float = 0.7, max_dd: float = 0.2, n_trades: int = 30
|
||||
) -> FalsificationReport:
|
||||
return FalsificationReport(
|
||||
sharpe=1.5,
|
||||
dsr=dsr,
|
||||
dsr_pvalue=0.05,
|
||||
max_drawdown=max_dd,
|
||||
total_return=0.3,
|
||||
n_trades=n_trades,
|
||||
n_bars=500,
|
||||
)
|
||||
|
||||
|
||||
def test_fitness_zero_trades_is_zero() -> None:
|
||||
f = make_falsification(n_trades=0)
|
||||
a = AdversarialReport()
|
||||
assert compute_fitness(f, a) == 0.0
|
||||
|
||||
|
||||
def test_fitness_increases_with_dsr() -> None:
|
||||
a = AdversarialReport()
|
||||
f1 = make_falsification(dsr=0.5)
|
||||
f2 = make_falsification(dsr=0.9)
|
||||
assert compute_fitness(f2, a) > compute_fitness(f1, a)
|
||||
|
||||
|
||||
def test_fitness_decreases_with_drawdown() -> None:
|
||||
a = AdversarialReport()
|
||||
f1 = make_falsification(max_dd=0.1)
|
||||
f2 = make_falsification(max_dd=0.4)
|
||||
assert compute_fitness(f1, a) > compute_fitness(f2, a)
|
||||
|
||||
|
||||
def test_fitness_zeroed_by_high_severity_finding() -> None:
|
||||
f = make_falsification()
|
||||
a = AdversarialReport(
|
||||
findings=[Finding(name="degenerate", severity=Severity.HIGH, detail="x")]
|
||||
)
|
||||
assert compute_fitness(f, a) == 0.0
|
||||
Reference in New Issue
Block a user