28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
import json
|
|
import numpy as np
|
|
from typer.testing import CliRunner
|
|
from fxhnt.cli import app
|
|
|
|
|
|
def _write_pit(d):
|
|
fund = {"HI": 0.0015, "MID": 0.0008, "LO": 0.0001, "NEG": -0.0010}
|
|
for sym, f in fund.items():
|
|
days = np.array([1000 + i for i in range(200)], dtype=np.int64)
|
|
np.savez(d / f"{sym}.npz", day=days, close=np.ones(200), qvol=np.full(200, 5e6),
|
|
funding=np.full(200, f))
|
|
|
|
|
|
def test_cli_backtest_funding_writes_report(tmp_path, monkeypatch):
|
|
pit = tmp_path / "pit"; pit.mkdir(); _write_pit(pit)
|
|
out = tmp_path / "funding_report.json"
|
|
monkeypatch.setenv("FXHNT_CRYPTO_PIT_DIR", str(pit))
|
|
from fxhnt import cli as climod
|
|
climod.get_settings.cache_clear()
|
|
res = CliRunner().invoke(app, ["backtest-funding", "--floors", "1e6", "--quantile", "0.5",
|
|
"--cost-bps", "8", "--out", str(out)])
|
|
assert res.exit_code == 0, res.output
|
|
report = json.loads(out.read_text())
|
|
modes = {c["mode"] for c in report["cells"].values()}
|
|
assert modes == {"long_tilt", "market_neutral", "executable"}
|
|
assert "FUNDING-CARRY-ONLY" in res.output # CLI prints the funding-only caveat once
|