Coverage for examples/aether_quant_cycle.py: 100%

28 statements  

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

1"""The research cycle from the library, on made-up numbers: two generations share a book, the old one's capital glides to the new one, a third trips its guard. No data, no network; runs in seconds. 

2 

3 python examples/aether_quant_cycle.py 

4""" 

5 

6from __future__ import annotations 

7 

8import sys 

9from pathlib import Path 

10 

11import numpy as np 

12 

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

14 

15from aether_quant.cycle import DecayConfig, GlidePolicy, blend_generation_rows, decay_state, update_generation_shares 

16 

17POLICY = GlidePolicy(glide_sessions=252, entry_share=0.30, retire_share=0.05) 

18OLD_ROW = {"BTCUSD": 0.02, "ETHUSD": 0.01} 

19NEW_ROW = {"AAPL": 0.03, "MSFT": -0.03, "BTCUSD": 0.01} 

20 

21 

22def main() -> list[dict[str, float]]: 

23 stages = {"old": "active", "new": "ramping"} 

24 shares = {"old": 1.0, "new": 0.0} 

25 path = [] 

26 print(f"{'session':>8} {'old':>6} {'new':>6} blended book") 

27 for session in range(280): 

28 shares = update_generation_shares(shares, stages, {}, {}, POLICY) 

29 path.append(dict(shares)) 

30 if session % 63 == 0 or session == 279: 

31 book = blend_generation_rows({"old": OLD_ROW, "new": NEW_ROW}, shares) 

32 print(f"{session:8d} {shares['old']:6.2f} {shares['new']:6.2f} " + " ".join(f"{ticker} {weight:+.4f}" for ticker, weight in sorted(book.items()))) 

33 

34 returns = np.random.default_rng(1).normal(-0.0015, 0.01, 800) 

35 report = decay_state(returns, expected_sharpe=0.5, config=DecayConfig()) 

36 print(f"\na generation that stopped earning, 800 sessions on: {report.state} ({report.reason})") 

37 

38 tripped = update_generation_shares({"old": 0.2, "new": 0.8}, stages, {"new": "tripped"}, {}, POLICY) 

39 print(f"a guard trip takes risk off at once, not by the ladder: {tripped}; {1.0 - sum(tripped.values()):.2f} goes to T-bills") 

40 return path 

41 

42 

43if __name__ == "__main__": 

44 main()