|
8 | 8 | FeatureSnapshotContextRequest, |
9 | 9 | FeatureSnapshotRuntimeSettings, |
10 | 10 | evaluate_feature_snapshot_strategy, |
| 11 | + extract_feature_snapshot_managed_symbols, |
11 | 12 | ) |
12 | 13 | from quant_platform_kit.strategy_contracts import ( |
13 | 14 | CallableStrategyEntrypoint, |
@@ -42,6 +43,62 @@ def _entrypoint() -> CallableStrategyEntrypoint: |
42 | 43 |
|
43 | 44 |
|
44 | 45 | class FeatureSnapshotRuntimeTests(unittest.TestCase): |
| 46 | + def test_managed_symbol_extractor_accepts_safe_haven_symbol_contract(self) -> None: |
| 47 | + observed: dict[str, object] = {} |
| 48 | + |
| 49 | + def extractor( |
| 50 | + _snapshot: object, |
| 51 | + *, |
| 52 | + benchmark_symbol: str | None = None, |
| 53 | + safe_haven_symbol: str | None = None, |
| 54 | + ) -> tuple[str, ...]: |
| 55 | + observed["benchmark_symbol"] = benchmark_symbol |
| 56 | + observed["safe_haven_symbol"] = safe_haven_symbol |
| 57 | + return ("VT", str(safe_haven_symbol)) |
| 58 | + |
| 59 | + symbols = extract_feature_snapshot_managed_symbols( |
| 60 | + runtime_adapter=StrategyRuntimeAdapter( |
| 61 | + managed_symbols_extractor=extractor, |
| 62 | + ), |
| 63 | + feature_snapshot=(), |
| 64 | + benchmark_symbol="VOO", |
| 65 | + safe_haven_symbol="BIL", |
| 66 | + ) |
| 67 | + |
| 68 | + self.assertEqual(symbols, ("VT", "BIL")) |
| 69 | + self.assertEqual(observed, { |
| 70 | + "benchmark_symbol": "VOO", |
| 71 | + "safe_haven_symbol": "BIL", |
| 72 | + }) |
| 73 | + |
| 74 | + def test_managed_symbol_extractor_retains_legacy_safe_haven_contract(self) -> None: |
| 75 | + observed: dict[str, object] = {} |
| 76 | + |
| 77 | + def extractor( |
| 78 | + _snapshot: object, |
| 79 | + *, |
| 80 | + benchmark_symbol: str | None = None, |
| 81 | + safe_haven: str | None = None, |
| 82 | + ) -> tuple[str, ...]: |
| 83 | + observed["benchmark_symbol"] = benchmark_symbol |
| 84 | + observed["safe_haven"] = safe_haven |
| 85 | + return ("QQQ", str(safe_haven)) |
| 86 | + |
| 87 | + symbols = extract_feature_snapshot_managed_symbols( |
| 88 | + runtime_adapter=StrategyRuntimeAdapter( |
| 89 | + managed_symbols_extractor=extractor, |
| 90 | + ), |
| 91 | + feature_snapshot=(), |
| 92 | + benchmark_symbol="QQQ", |
| 93 | + safe_haven_symbol="BOXX", |
| 94 | + ) |
| 95 | + |
| 96 | + self.assertEqual(symbols, ("QQQ", "BOXX")) |
| 97 | + self.assertEqual(observed, { |
| 98 | + "benchmark_symbol": "QQQ", |
| 99 | + "safe_haven": "BOXX", |
| 100 | + }) |
| 101 | + |
45 | 102 | def test_fail_closes_when_path_missing(self) -> None: |
46 | 103 | result = evaluate_feature_snapshot_strategy( |
47 | 104 | entrypoint=_entrypoint(), |
|
0 commit comments