Coverage for notebooks/src/00_hello_world.py: 100%
26 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
1# %% [markdown]
2# # Hello world: the shipped book in one call
3#
4# [](https://colab.research.google.com/github/leon1706-lol/Aether-quant/blob/main/notebooks/00_hello_world.ipynb)
5#
6# This is `aq hello` as a library call. It runs the project's shipped book on daily bars for 11 coins, through a cost-aware backtest, and prints the report: benchmarks, overfitting checks, and an honest note. No key, no Docker, no Lean.
7#
8# The rule is long a coin while its trailing return over 20, 60 and 120 sessions is positive, with one vote per lookback. Weights are vol-scaled and capped, rebalanced every 5 sessions, and charged Coinbase's taker fee plus slippage.
10# %%
11import sys
12from pathlib import Path
14if "google.colab" in sys.modules: # Colab: install the library (numpy and pandas come with it)
15 get_ipython().run_line_magic("pip", 'install -q "aether-quant[notebooks]"') # noqa: F821
16else: # a clone: run against the checkout's code
17 for parent in (Path.cwd(), *Path.cwd().parents):
18 if (parent / "aether_quant" / "__init__.py").is_file():
19 sys.path.insert(0, str(parent))
20 break
22# %% [markdown]
23# ## Run it
24#
25# `offline=True` uses the sample that ships in the wheel (2021-06 to 2026-10), so this notebook gives the same numbers everywhere. Use `offline=False` to download fresh bars from Coinbase's public candles. A failed download falls back to the sample.
27# %%
28from aether_quant import hello
30report = hello.run(offline=True)
31print(hello.render_text(report))
33# %% [markdown]
34# ## The equity curve against BTC
35#
36# The shipped sleeve holds about 11% gross on average, so it is a small, low-volatility slice next to buying BTC outright. Compare Sharpe and drawdown, not total return.
38# %%
39import matplotlib.pyplot as plt
40import pandas as pd
42curves = pd.DataFrame({"shipped rule": report.equity, "BTC buy & hold": report.benchmark_equity})
43curves.index = pd.to_datetime(curves.index)
44axes = curves.plot(logy=True, figsize=(9, 4), color=["#d97706", "#64748b"], title="Growth of $1 (log scale)")
45axes.set_xlabel("")
46plt.show()
48# %% [markdown]
49# ## The robustness grid
50#
51# The same rule on 8 lookback variants. CSCV's PBO asks how often the variant that looked best in one half of the history did worse than the median variant in the other half. Above 0.5 means picking the best-looking variant is worse than picking one at random.
53# %%
54grid = pd.Series(report.grid_sharpes, name="Sharpe (no T-bill)")
55grid.index = [f"a={a}, c={c}" for a in (10, 20, 30, 40) for c in (120, 180)]
56print(f"PBO: {report.pbo:.2f}")
57grid.to_frame()
59# %% [markdown]
60# ## Save it
61#
62# `hello.save` writes a self-contained HTML page (no scripts, no external files) and/or the JSON report.
64# %%
65import tempfile
67out = Path(tempfile.mkdtemp())
68hello.save(report, html_path=out / "hello.html", json_path=out / "hello.json")
69sorted(path.name for path in out.iterdir())
71# %% [markdown]
72# **Next:** [01 signal evaluation](01_signal_evaluation.ipynb) · [02 book construction](02_book_construction.ipynb) · [03 overfitting tests](03_overfitting_tests.ipynb)
73#
74# *No verified edge: this is the project's shipped book, labelled improved, not verified.*