48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""PriceSeries gains high/low keyword fields defaulting to close (a flat bar)."""
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from fxhnt.domain.models import AssetClass, Market, PriceSeries
|
|
|
|
_M = Market(symbol="X", asset_class=AssetClass.FUTURE)
|
|
|
|
|
|
def test_high_low_default_to_close_when_absent() -> None:
|
|
c = np.array([100.0, 101.0, 102.0])
|
|
ps = PriceSeries(market=_M, dates=("0", "1", "2"), close=c)
|
|
assert np.array_equal(ps.high, c)
|
|
assert np.array_equal(ps.low, c)
|
|
assert ps.high is not c
|
|
assert ps.low is not c
|
|
|
|
|
|
def test_high_low_are_kept_when_supplied() -> None:
|
|
c = np.array([100.0, 101.0])
|
|
h = np.array([101.0, 102.0])
|
|
low = np.array([99.0, 100.0])
|
|
ps = PriceSeries(market=_M, dates=("0", "1"), close=c, high=h, low=low)
|
|
assert np.array_equal(ps.high, h)
|
|
assert np.array_equal(ps.low, low)
|
|
|
|
|
|
def test_mismatched_high_length_raises() -> None:
|
|
with pytest.raises(ValueError):
|
|
PriceSeries(market=_M, dates=("0", "1"), close=np.array([1.0, 2.0]),
|
|
high=np.array([1.0]), low=np.array([1.0, 2.0]))
|
|
|
|
|
|
def test_mismatched_low_length_raises() -> None:
|
|
with pytest.raises(ValueError):
|
|
PriceSeries(market=_M, dates=("0", "1"), close=np.array([1.0, 2.0]),
|
|
high=np.array([1.0, 2.0]), low=np.array([1.0]))
|
|
|
|
|
|
def test_partial_supply_defaults_only_missing_side() -> None:
|
|
c = np.array([100.0, 101.0])
|
|
h = np.array([101.0, 102.0])
|
|
ps = PriceSeries(market=_M, dates=("0", "1"), close=c, high=h)
|
|
assert np.array_equal(ps.high, h)
|
|
assert np.array_equal(ps.low, c)
|