Coverage for aether_quant/hello.py: 100%

16 statements  

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

1"""The hello world as a library call (V6.6.5): what `aq hello` does, for a notebook or a script. 

2 

3 from aether_quant import hello 

4 report = hello.run(offline=True) # the bundled sample; offline=False downloads from Coinbase's public candles 

5 print(hello.render_text(report)) 

6 report.equity.plot() # the shipped rule's equity curve (needs matplotlib) 

7""" 

8 

9from __future__ import annotations 

10 

11from pathlib import Path 

12 

13from data_pipeline.public_candles import DEFAULT_CACHE_DIR 

14from evaluation.hello_world import HELLO_RULE, RESEARCH_TRIALS, HelloReport, StatsRow, known_at_sessions, load_closes, render_html, render_text, rule_weights, run_hello 

15 

16__all__ = ["HELLO_RULE", "RESEARCH_TRIALS", "HelloReport", "StatsRow", "known_at_sessions", "load_closes", "render_html", "render_text", "rule_weights", "run", "run_hello", "save"] 

17 

18 

19def run(offline: bool = False, *, start: str = "2022-01-01", end: str | None = None, cache: bool = True) -> HelloReport: 

20 """Load the data (download unless `offline`, falling back to the sample) and run the whole demo.""" 

21 closes, source, notice = load_closes(offline=offline, start=start, end=end, cache_dir=DEFAULT_CACHE_DIR if cache else None) 

22 if notice: 

23 print(notice) 

24 return run_hello(closes, start=start, end=end, data_source=source) 

25 

26 

27def save(report: HelloReport, *, html_path: str | Path | None = None, json_path: str | Path | None = None) -> None: 

28 """Write the HTML page and/or the JSON report.""" 

29 from json_safety import atomic_write_json, atomic_write_text 

30 

31 if html_path: 

32 atomic_write_text(Path(html_path), render_html(report)) 

33 if json_path: 

34 atomic_write_json(Path(json_path), report.to_dict(), indent=2) 

35