Coverage for examples/aether_quant_quickstart.py: 100%

40 statements  

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

1"""A tour of the aether_quant library (V6.4.3): every call below is the same pure function the live algorithm or the 

2research chain uses. Runs in a few seconds on synthetic data: 

3 

4 python examples/aether_quant_quickstart.py 

5""" 

6 

7from __future__ import annotations 

8 

9import sys 

10from pathlib import Path 

11 

12import numpy as np 

13import pandas as pd 

14 

15sys.path.insert(0, str(Path(__file__).resolve().parents[1])) 

16 

17from aether_quant import audit, execution, formal, portfolio, research, risk 

18 

19 

20def main() -> int: 

21 # 1. a market-neutral book: per-name cap, sector cap, dollar neutrality, gross cap 

22 weights, diagnostics = portfolio.apply_book_neutrality( 

23 {"AAA": 0.20, "BBB": 0.10, "CCC": -0.15, "DDD": -0.05}, 

24 sector_by_symbol={"AAA": "tech", "BBB": "tech", "CCC": "energy", "DDD": "tech"}, 

25 dollar_neutral=True, sector_neutral=True, gross_exposure_cap=0.5, max_weight_per_name=0.12, sector_max_net_weight=0.15, 

26 reapply_sector_cap_after_dollar_neutral=True, 

27 ) 

28 print("book:", {k: round(v, 4) for k, v in weights.items()}, "steps:", diagnostics["steps_applied"]) 

29 

30 # 2. the order gate never trades in observation mode, and a risk lock stops paper/live 

31 print("observation may trade:", execution.resolve_order_permission("observation", True, True, True)[0]) 

32 print("paper with a tripped lock:", execution.resolve_order_permission("paper", True, True, False)) 

33 

34 # 3. sizing never flips a trade and never exceeds the cap 

35 decision = risk.build_dynamic_position_sizing(-0.3, 0.9, 0.02, 0.10) 

36 print("sized target:", round(decision.target_weight, 4)) 

37 

38 # 4. a tamper-evident log, anchored so truncation is caught too 

39 rows, prev = [], audit.GENESIS_HASH 

40 for index in range(3): 

41 row = {"prev_hash": prev, "event_type": "fill", "created_at": f"2026-11-02T10:0{index}:00", "payload": {"n": index}} 

42 row["hash"] = audit.compute_entry_hash(prev, row["event_type"], row["created_at"], row["payload"]) 

43 rows.append(row) 

44 prev = row["hash"] 

45 print("chain ok:", audit.verify_chain(rows), "truncated:", audit.verify_chain(rows[:2], expected_tail_hash=prev)) 

46 

47 # 5. research: IC report, factor spanning and PBO for a synthetic signal 

48 rng = np.random.default_rng(0) 

49 dates = pd.date_range("2024-01-01", periods=160, freq="B").strftime("%Y-%m-%d") 

50 rows = [] 

51 for date in dates: 

52 future = rng.normal(size=30) 

53 score = 0.3 * future + rng.normal(size=30) 

54 ranks = pd.Series(future).rank(pct=True).to_numpy() 

55 for i in range(30): 

56 rows.append({"date": date, "ticker": f"T{i}", "split": "validation", "score": score[i], "target_rank_20d": ranks[i], 

57 "target_rank_5d": ranks[i], "target_return_1d": future[i] / 100}) 

58 frame = pd.DataFrame(rows) 

59 report = research.evaluate_signal(frame, score_column="score", splits=("validation",), bootstrap_draws=200) 

60 h20 = report["splits"]["validation"]["h20"] 

61 print(f"IC {h20['mean_ic']:.3f}, HAC t {h20['hac_t']:.1f}, CI {[round(x, 3) for x in h20['ci95']]}") 

62 returns = rng.normal(0, 0.01, size=(400, 8)) 

63 print("PBO of 8 noise variants:", research.probability_of_backtest_overfitting(returns, blocks=8)["pbo"]) 

64 

65 # 6. the Lean 4 differential cases ship with the library 

66 print("formal targets:", formal.targets()) 

67 return 0 

68 

69 

70if __name__ == "__main__": 

71 raise SystemExit(main())