Files
fxhnt/tests/unit/test_allocation_policy.py
2026-07-09 20:58:21 +02:00

39 lines
1.3 KiB
Python

from fxhnt.application.allocation_policy import (
ALLOCATION_POLICY,
ALLOCATION_POLICY_VERSION,
AllocationPolicy,
allocation_policy_hash,
)
_EXPECTED_HASH = "4d583ec175bc721ee2d2277cc9e736184d25bc6b210037d64664b64e59509c84"
def test_policy_defaults():
p = ALLOCATION_POLICY
assert (p.target_vol, p.kelly_fraction, p.max_leverage, p.max_strategy_weight) == (
0.12,
0.5,
1.5,
0.5,
)
assert (p.marginal_gate, p.min_history_days) == (True, 60)
assert (p.kill_dd, p.reenter_dd) == (0.25, 0.10)
assert p.capital_ceiling == 35_000.0
def test_hash_content_derived_and_pinned():
assert allocation_policy_hash(ALLOCATION_POLICY, ALLOCATION_POLICY_VERSION) == allocation_policy_hash(
ALLOCATION_POLICY, ALLOCATION_POLICY_VERSION
) # stable
assert allocation_policy_hash(
AllocationPolicy(target_vol=0.10), ALLOCATION_POLICY_VERSION
) != allocation_policy_hash(ALLOCATION_POLICY, ALLOCATION_POLICY_VERSION) # field change
assert (
allocation_policy_hash(ALLOCATION_POLICY, 2)
!= allocation_policy_hash(ALLOCATION_POLICY, 1)
)
assert (
allocation_policy_hash(ALLOCATION_POLICY, ALLOCATION_POLICY_VERSION)
== _EXPECTED_HASH # noqa: F821
)