Files
fxhnt/tests/unit/test_unlock_current_weights.py
2026-06-21 20:15:39 +02:00

31 lines
1.2 KiB
Python

from fxhnt.application.unlock_runner import UnlockShortRunner
def _series(start, n, close=100.0, qvol=1e8, funding=0.0, vol=0.03):
out = {}
px = close
for i in range(n):
# alternate up/down so name vol is well-defined and > 0
px = px * (1.0 + (vol if i % 2 == 0 else -vol))
out[start + i] = (px, qvol, funding)
return out
def test_in_window_name_gets_negative_weight():
# ALT has a big unlock cliff at day 150; window is [cliff-pre, cliff)
panel = {
"ALTUSDT": _series(100, 80),
"BTCUSDT": _series(100, 80),
}
events = [{"sym": "ALT", "cliff_day": 150, "n": 5e7, "cat": "insiders"}]
r = UnlockShortRunner(panel, events, pre_window=10, min_qvol=1e6, min_shock=0.0)
w = r.current_weights("epoch:145") # 140 <= 145 < 150 -> in window
assert w.get("ALTUSDT", 0.0) < 0
def test_no_active_window_is_empty():
panel = {"ALTUSDT": _series(100, 80), "BTCUSDT": _series(100, 80)}
events = [{"sym": "ALT", "cliff_day": 150, "n": 5e7, "cat": "insiders"}]
r = UnlockShortRunner(panel, events, pre_window=10, min_qvol=1e6, min_shock=0.0)
assert r.current_weights("epoch:120") == {} # well before window