23 lines
876 B
Python
23 lines
876 B
Python
"""The panel builder turns {sym: {day: close}} into aligned (days, syms, close, ret) — shared by the
|
|
raw-file and warehouse sources so they produce identical panels."""
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
|
|
from fxhnt.application.crypto_momentum_research import _panel
|
|
|
|
|
|
def test_panel_aligns_and_computes_returns() -> None:
|
|
data = {"BTCUSDT": {19000: 100.0, 19001: 110.0}, "ETHUSDT": {19001: 50.0, 19002: 55.0}}
|
|
days, syms, close, ret = _panel(data)
|
|
assert days == [19000, 19001, 19002]
|
|
assert syms == ["BTCUSDT", "ETHUSDT"]
|
|
assert np.isnan(close[0, 1]) and close[1, 0] == 110.0 and close[2, 1] == 55.0
|
|
assert abs(ret[1, 0] - 0.10) < 1e-12 # 110/100 - 1
|
|
assert np.isnan(ret[0, 0])
|
|
|
|
|
|
def test_panel_empty() -> None:
|
|
days, syms, close, ret = _panel({})
|
|
assert days == [] and syms == [] and close.shape == (0, 0)
|