Coverage for scripts/v660_crypto_splices.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""Which coins in data_crypto_wide carry a price break no market move explains (a redenomination or token swap spliced into one Binance pair), 

2and did a V6.6.0 crypto book hold one across it? Reads prices and the recorded weights' tickers only; scores nothing. 

3 

4 python scripts/v660_crypto_splices.py 

5""" 

6 

7from __future__ import annotations 

8 

9import csv 

10import io 

11import json 

12import sys 

13import zipfile 

14from pathlib import Path 

15 

16ROOT = Path(__file__).resolve().parents[1] 

17sys.path.insert(0, str(ROOT)) 

18 

19from data_pipeline.binance_archive import price_breaks # noqa: E402 

20 

21DAILY = ROOT / "data_crypto_wide" / "crypto" / "coinbase" / "daily" 

22OUT = ROOT / "ml" / "evaluation" / "v660" / "crypto_price_breaks.json" 

23 

24 

25def closes_of(path: Path) -> dict[str, float]: 

26 with zipfile.ZipFile(path) as archive, archive.open(archive.namelist()[0]) as handle: 

27 rows = list(csv.reader(io.TextIOWrapper(handle, encoding="utf-8"))) 

28 return {f"{row[0][:4]}-{row[0][4:6]}-{row[0][6:8]}": float(row[4]) for row in rows} 

29 

30 

31def main() -> int: 

32 breaks = {} 

33 coins = sorted(DAILY.glob("*_trade.zip")) 

34 for path in coins: 

35 found = price_breaks(closes_of(path)) 

36 if found: 

37 breaks[path.name.split("_")[0].upper()] = found 

38 report = {"coins": len(coins), "coins_with_a_break": len(breaks), "breaks": breaks} 

39 OUT.write_text(json.dumps(report, indent=1), encoding="utf-8", newline="\n") 

40 print(json.dumps({"coins": len(coins), "coins_with_a_break": len(breaks)})) 

41 for ticker, found in sorted(breaks.items()): 

42 print(ticker, [(row["from"], row["to"], round(row["ratio"], 4)) for row in found][:4]) 

43 return 0 

44 

45 

46if __name__ == "__main__": 

47 raise SystemExit(main())