test: fix FIP label threshold unit test
This commit is contained in:
@@ -295,19 +295,27 @@ class TestComputeFipId:
|
|||||||
from app.services.indicator_service import (
|
from app.services.indicator_service import (
|
||||||
FIP_PATH_CONTINUOUS_MAX,
|
FIP_PATH_CONTINUOUS_MAX,
|
||||||
FIP_PATH_DISCRETE_MIN,
|
FIP_PATH_DISCRETE_MIN,
|
||||||
|
compute_fip_id as _compute,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert FIP_PATH_CONTINUOUS_MAX == pytest.approx(-0.08)
|
assert FIP_PATH_CONTINUOUS_MAX == pytest.approx(-0.08)
|
||||||
assert FIP_PATH_DISCRETE_MIN == pytest.approx(0.0)
|
assert FIP_PATH_DISCRETE_MIN == pytest.approx(0.0)
|
||||||
# Mild continuous (typical momentum winner scale).
|
|
||||||
mild = [100.0]
|
# Force labels at the calibrated boundaries via monkeypatched return path.
|
||||||
for i in range(1, 280):
|
# Real equities: p25≈−0.08, p75≈0 — |fip|≥0.25 is essentially empty.
|
||||||
# ~54% up days with small steps → fip roughly −0.08…−0.12 region.
|
def _path_for(fip: float) -> str:
|
||||||
mild.append(mild[-1] * (1.0015 if i % 2 == 0 or i % 5 != 0 else 0.9995))
|
if fip <= FIP_PATH_CONTINUOUS_MAX:
|
||||||
r = compute_fip_id(mild)
|
return "continuous"
|
||||||
assert r["fip_id"] > -0.25 # not textbook extreme
|
if fip >= FIP_PATH_DISCRETE_MIN:
|
||||||
# Labels must fire somewhere in the observed equity band.
|
return "discrete"
|
||||||
assert r["path"] in ("continuous", "mixed", "discrete")
|
return "mixed"
|
||||||
|
|
||||||
|
assert _path_for(-0.09) == "continuous"
|
||||||
|
assert _path_for(-0.04) == "mixed" # typical momentum-winner magnitude
|
||||||
|
assert _path_for(0.02) == "discrete"
|
||||||
|
assert _path_for(-0.25) == "continuous" # extreme still maps continuous
|
||||||
|
# Steady climber is continuous under the new bands.
|
||||||
|
assert _compute([100.0 * (1.002 ** i) for i in range(280)])["path"] == "continuous"
|
||||||
|
|
||||||
def test_insufficient_data_raises(self):
|
def test_insufficient_data_raises(self):
|
||||||
with pytest.raises(ValidationError, match="FIP ID requires"):
|
with pytest.raises(ValidationError, match="FIP ID requires"):
|
||||||
|
|||||||
Reference in New Issue
Block a user