def test_sample_points(): original_quotes_points = Quote.mock_ohlcv_points([(1, 2.2, 0.9, 2), (2, 3.1, 1.9, 3), (3, 5.1, 2.9, 5)], t_start=0, t_step=1) f = Quotes(1, quote_points=original_quotes_points) ps = f.sample_points() assert ps == original_quotes_points ps = f.sample_points(domain=Interval.open_closed(1, 2)) assert ps == original_quotes_points[1:3] ps = f.sample_points(domain=Interval.closed(1, 2)) assert ps == original_quotes_points[1:3] ps = f.sample_points(domain=Interval.closed(3, 4)) assert ps == [] ps = f.sample_points(domain=Interval.closed(-1, 0)) assert ps == original_quotes_points[0:1]
def test_volume(): ps = Quotes(1, quote_points=Quote.mock_ohlcv_points([(1, 2.2, 0.9, 2, 10), (2, 3.1, 1.9, 3, 20), (3, 5.1, 2.9, 5, 30)], t_start=10, t_step=1)).volume assert ps.domain.start == 10 assert ps.domain.end == 12 assert ps.x_next(9) == 10 assert ps.x_next(10) == 11 assert ps.x_next(10.5) == 11 assert ps.x_next(11.5) == 12 assert ps.x_next(12) is None assert ps.sample_points() == [(10, 10), (11, 20), (12, 30)] assert ps(9.5) is None assert ps(10.5) == 10 assert ps(11.5) == 20 assert ps(12.5) is None
def test_hl2(): ps = Quotes(1, quote_points=Quote.mock_ohlcv_points([(1, 2.2, 0.9, 2), (2, 3.1, 1.9, 3), (3, 5.1, 2.9, 5)], t_start=10, t_step=1)).hl2 assert ps.domain.start == 10 assert ps.domain.end == 12 assert ps.x_next(9) == 10 assert ps.x_next(10) == 11 assert ps.x_next(10.5) == 11 assert ps.x_next(11.5) == 12 assert ps.x_next(12) is None assert ps.sample_points() == [(10, 1.55), (11, 2.5), (12, 4)] assert ps(9.5) is None assert ps(10.5) == 1.55 assert ps(11.5) == 2.5 assert ps(12.5) is None