Isolate legacy range-grid features
This commit is contained in:
@@ -6,6 +6,8 @@ from app.services.sr_service import (
|
||||
MAX_LEVELS,
|
||||
_bar_respect_weight,
|
||||
_cap_levels,
|
||||
_legacy_range_grid_nodes,
|
||||
_legacy_volume_profile_nodes,
|
||||
_merge_levels,
|
||||
_round_number_candidates,
|
||||
_strength_from_respects,
|
||||
@@ -267,3 +269,65 @@ class TestDetectSrLevels:
|
||||
assert pivots and traffic
|
||||
assert all(level["sources"] == ["pivot_point"] for level in pivots)
|
||||
assert all(level["sources"] == ["volume_profile"] for level in traffic)
|
||||
|
||||
def test_legacy_profile_union_matches_explicit_range_grid(self):
|
||||
highs, lows, closes, volumes = _make_series(n=500)
|
||||
deployed = _legacy_volume_profile_nodes(highs, lows, closes, volumes)
|
||||
explicit = _legacy_range_grid_nodes(highs, lows, closes)
|
||||
assert sorted(deployed) == explicit
|
||||
assert len(explicit) == 20
|
||||
|
||||
def test_explicit_range_grid_is_volume_independent(self):
|
||||
highs, lows, closes, volumes = _make_series(n=500)
|
||||
shifted_volumes = [volume * (i + 1) for i, volume in enumerate(volumes)]
|
||||
baseline = detect_sr_levels_legacy(
|
||||
highs,
|
||||
lows,
|
||||
closes,
|
||||
volumes,
|
||||
include_pivots=False,
|
||||
explicit_range_grid=True,
|
||||
)
|
||||
shifted = detect_sr_levels_legacy(
|
||||
highs,
|
||||
lows,
|
||||
closes,
|
||||
shifted_volumes,
|
||||
include_pivots=False,
|
||||
explicit_range_grid=True,
|
||||
)
|
||||
assert shifted == baseline
|
||||
|
||||
def test_explicit_range_grid_neutral_changes_only_strength(self):
|
||||
highs, lows, closes, volumes = _make_series(n=500)
|
||||
touch = detect_sr_levels_legacy(
|
||||
highs,
|
||||
lows,
|
||||
closes,
|
||||
volumes,
|
||||
include_pivots=False,
|
||||
explicit_range_grid=True,
|
||||
)
|
||||
neutral = detect_sr_levels_legacy(
|
||||
highs,
|
||||
lows,
|
||||
closes,
|
||||
volumes,
|
||||
include_pivots=False,
|
||||
neutral_strength=True,
|
||||
explicit_range_grid=True,
|
||||
)
|
||||
touch_by_price = {level["price_level"]: level for level in touch}
|
||||
neutral_by_price = {level["price_level"]: level for level in neutral}
|
||||
assert neutral_by_price.keys() == touch_by_price.keys()
|
||||
for price, neutral_level in neutral_by_price.items():
|
||||
assert neutral_level["strength"] == 50
|
||||
assert {
|
||||
key: value
|
||||
for key, value in neutral_level.items()
|
||||
if key != "strength"
|
||||
} == {
|
||||
key: value
|
||||
for key, value in touch_by_price[price].items()
|
||||
if key != "strength"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user