openstatz 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. openstatz-0.1.0/.gitignore +29 -0
  2. openstatz-0.1.0/2026-rebuild-architecture.md +322 -0
  3. openstatz-0.1.0/CHANGELOG.md +35 -0
  4. openstatz-0.1.0/LICENSE.txt +202 -0
  5. openstatz-0.1.0/NOTICE +16 -0
  6. openstatz-0.1.0/PKG-INFO +189 -0
  7. openstatz-0.1.0/README.md +131 -0
  8. openstatz-0.1.0/openstatz/__init__.py +161 -0
  9. openstatz-0.1.0/openstatz/__main__.py +11 -0
  10. openstatz-0.1.0/openstatz/_compat.py +430 -0
  11. openstatz-0.1.0/openstatz/_context.py +123 -0
  12. openstatz-0.1.0/openstatz/_kernels.py +83 -0
  13. openstatz-0.1.0/openstatz/_montecarlo.py +295 -0
  14. openstatz-0.1.0/openstatz/_numpy_compat.py +288 -0
  15. openstatz-0.1.0/openstatz/_plotting/__init__.py +0 -0
  16. openstatz-0.1.0/openstatz/_plotting/core.py +2137 -0
  17. openstatz-0.1.0/openstatz/_plotting/wrappers.py +2114 -0
  18. openstatz-0.1.0/openstatz/app/__init__.py +9 -0
  19. openstatz-0.1.0/openstatz/app/cli.py +62 -0
  20. openstatz-0.1.0/openstatz/app/schemas.py +149 -0
  21. openstatz-0.1.0/openstatz/app/serializers.py +383 -0
  22. openstatz-0.1.0/openstatz/app/server.py +183 -0
  23. openstatz-0.1.0/openstatz/app/static/assets/index-ChOfSsMx.css +1 -0
  24. openstatz-0.1.0/openstatz/app/static/assets/index-uPeRPPQG.js +76 -0
  25. openstatz-0.1.0/openstatz/app/static/assets/index-uPeRPPQG.js.map +1 -0
  26. openstatz-0.1.0/openstatz/app/static/index.html +27 -0
  27. openstatz-0.1.0/openstatz/compat.py +56 -0
  28. openstatz-0.1.0/openstatz/plots.py +27 -0
  29. openstatz-0.1.0/openstatz/providers.py +138 -0
  30. openstatz-0.1.0/openstatz/py.typed +0 -0
  31. openstatz-0.1.0/openstatz/report.html +65 -0
  32. openstatz-0.1.0/openstatz/reports.py +2515 -0
  33. openstatz-0.1.0/openstatz/stats.py +3307 -0
  34. openstatz-0.1.0/openstatz/utils.py +1002 -0
  35. openstatz-0.1.0/openstatz/version.py +1 -0
  36. openstatz-0.1.0/pyproject.toml +168 -0
@@ -0,0 +1,29 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .venv/
9
+ venv/
10
+ .pytest_cache/
11
+ .ruff_cache/
12
+ .benchmarks/
13
+ .hypothesis/
14
+
15
+ # Node / web UI
16
+ app/node_modules/
17
+ app/dist/
18
+ app/.vite/
19
+
20
+ # Built UI copied into the package (force-included in the wheel via pyproject
21
+ # [tool.hatch.build.targets.wheel] artifacts; rebuilt from app/ at release time)
22
+ openstatz/app/static/
23
+
24
+ # OS
25
+ .DS_Store
26
+ Thumbs.db
27
+
28
+ # NOTE: tests/parity/fixtures/*.pkl ARE committed on purpose — they are the
29
+ # golden master the CI parity gate runs against.
@@ -0,0 +1,322 @@
1
+ # OpenStatz — 2026 Rebuild Architecture
2
+
3
+ > A modern rebuild of QuantStats: same trusted analytics, a fast pandas+Numba core,
4
+ > and an optional modern web UI — with **100% output parity** to the original library.
5
+
6
+ > **Implementation note (2026-06-29):** Numba acceleration is **deferred for the time being** —
7
+ > it creates compatibility friction with current NumPy. The loop-shaped kernels described below
8
+ > (`openstatz/_kernels.py`) are implemented in **pure vectorized NumPy** instead; they are still
9
+ > gated by the parity suite and already deliver the key speedups (e.g. ~11x on the Monte Carlo
10
+ > per-column max-drawdown). Numba can be reintroduced later behind the same parity gate without
11
+ > changing any public API.
12
+
13
+ ---
14
+
15
+ ## 0. TL;DR
16
+
17
+ - **OpenStatz stays a normal Python library.** `pip install openstatz` → `import openstatz as os`
18
+ behaves exactly like `quantstats` (same functions, same numbers, `extend_pandas()`).
19
+ - **The web UI is an optional layer**, not a replacement. `pip install openstatz[app]`
20
+ adds a FastAPI server + a modern React UI that *imports the same library core*.
21
+ - **Compute stays on pandas** (not Polars) for guaranteed numerical parity, with **NumPy +
22
+ Numba** accelerating only a handful of loop-shaped kernels — each gated by a parity test.
23
+ - **Parity is enforced, not promised**: a golden-master suite snapshots the current
24
+ QuantStats output and CI asserts OpenStatz reproduces every metric (`rtol=1e-9`) and
25
+ every chart's underlying data series.
26
+
27
+ ---
28
+
29
+ ## 1. Can it run as a library? (Yes — both at once)
30
+
31
+ OpenStatz is **library-first**. The layering guarantees three usage modes from one codebase:
32
+
33
+ | Mode | Install | Usage |
34
+ |---|---|---|
35
+ | Library (drop-in) | `pip install openstatz` | `import openstatz as os; os.stats.sharpe(r)` |
36
+ | Pandas extension | `pip install openstatz` | `os.extend_pandas(); r.sharpe()` |
37
+ | Web app | `pip install openstatz[app]` | `openstatz serve` → browser UI |
38
+
39
+ > **Alias caveat:** the documented alias is `os` (`import openstatz as os`). This intentionally
40
+ > shadows Python's standard-library `os` module within any file that uses it — `os.path`,
41
+ > `os.getcwd()`, etc. will not be available there. Code that needs the stdlib alongside OpenStatz
42
+ > should `import os as _os` (or import OpenStatz under a different name in that file). The library
43
+ > itself never relies on the alias, so this only affects user scripts.
44
+
45
+ The core never imports FastAPI, matplotlib-for-web, or any UI dependency. I/O and presentation
46
+ live in adapters. This is what keeps the library lean and embeddable while the app sits on top.
47
+
48
+ ---
49
+
50
+ ## 2. Design principle: reuse, don't reimplement
51
+
52
+ 100% numerical parity is only *free* when the new core runs the **same engine** on the same
53
+ data. Reimplementing ~80 metric functions on a different engine (e.g. Polars) would mean proving
54
+ bit-identical results despite differences in NaN handling, `ddof`, rolling-window edges,
55
+ percentile interpolation, and float reduction order. Staying on **pandas** removes that risk.
56
+
57
+ > **Rule: the metric math is reused from the proven QuantStats implementation. OpenStatz adds a
58
+ > modern packaging, an API adapter, a web UI, and *gated* Numba acceleration — it does not
59
+ > re-derive the numbers.**
60
+
61
+ ---
62
+
63
+ ## 3. Final stack decisions
64
+
65
+ ### 3.1 Compute core (Python)
66
+ - **Python** >= 3.10
67
+ - **pandas** (primary engine — same as QuantStats, for parity & compatibility)
68
+ - **numpy** (vectorized math)
69
+ - **numba** (`@njit`) — **only** on loop-shaped hot kernels, behind existing signatures, gated by parity tests
70
+ - **scipy** (distribution fits where already used)
71
+ - Packaging: **hatchling**, env/deps via **uv**
72
+
73
+ ### 3.2 API / service layer (optional `[app]` extra)
74
+ - **FastAPI** (async) — serializes library outputs to JSON; performs no math
75
+ - **Pydantic v2** — typed request/response schemas (TS types generated from these)
76
+ - **uvicorn** — ASGI server
77
+ - **httpx** — async data fetching (yfinance wrapped behind a provider interface)
78
+
79
+ ### 3.3 Web UI (separate `app/` workspace)
80
+ - **Vite + React + TypeScript**
81
+ - **Tailwind CSS + shadcn/ui** — design system
82
+ - **TanStack Query** (data) + **TanStack Table** (sortable metrics grid)
83
+ - **lightweight-charts** (Apache-2.0, canvas) — all time-axis panels
84
+ - **Confined behind a `<TimeSeriesChart>` adapter** so it can be swapped for **openalgo-charts** later with a one-file change
85
+ - **Bespoke SVG components** on `d3-scale` + `d3-array` — monthly heatmap, distribution, box/quantile/violin (low-cardinality, vector-crisp, PDF-perfect, fully themeable)
86
+
87
+ ### 3.4 Quality tooling
88
+ - **ruff** (lint+format), **pyright** (types), **pytest** (+ **pytest-benchmark**, **hypothesis**)
89
+ - **GitHub Actions** matrix (3.10–3.13)
90
+
91
+ ---
92
+
93
+ ## 4. Architecture layers
94
+
95
+ ```
96
+ +-------------------------------------------------------------+
97
+ | openstatz (PURE LIBRARY — pip install openstatz) |
98
+ | |
99
+ | stats.py utils.py reports.py plots.py |
100
+ | _kernels.py (Numba; gated, same signatures) |
101
+ | ReturnsContext (compute returns/cumulative/dd once) |
102
+ | | pandas in -> DataFrame/Series/dict out |
103
+ +--------|----------------------------------------------------+
104
+ |
105
+ | (optional) imported by:
106
+ v
107
+ +-------------------------------------------------------------+
108
+ | openstatz.app (FastAPI adapter — pip install openstatz[app]) |
109
+ | - calls library, serializes metrics + chart series to JSON |
110
+ | - Pydantic v2 schemas -> generated TypeScript types |
111
+ | - NO math here |
112
+ +--------|----------------------------------------------------+
113
+ | JSON { metrics[], series{time,value}[], tables[] }
114
+ v
115
+ +-------------------------------------------------------------+
116
+ | app/ (Vite + React + TS + Tailwind + shadcn) |
117
+ | TanStack Table (metrics) TanStack Query (fetch) |
118
+ | <TimeSeriesChart> -> lightweight-charts (-> openalgo-charts)|
119
+ | <BoxPlot> <MonthlyHeatmap> <Distribution> -> bespoke SVG |
120
+ | PDF export via headless Chromium (vector) |
121
+ +-------------------------------------------------------------+
122
+ ```
123
+
124
+ ---
125
+
126
+ ## 5. Repository structure (monorepo)
127
+
128
+ ```
129
+ openstatz/
130
+ ├── pyproject.toml # library + [app] optional extra
131
+ ├── 2026-rebuild-architecture.md
132
+ ├── openstatz/ # THE LIBRARY (drop-in for quantstats)
133
+ │ ├── __init__.py # exports + extend_pandas()
134
+ │ ├── stats.py
135
+ │ ├── utils.py
136
+ │ ├── reports.py
137
+ │ ├── plots.py # matplotlib (kept for library/HTML parity)
138
+ │ ├── _plotting/
139
+ │ ├── _kernels.py # NEW: Numba kernels, gated by parity tests
140
+ │ ├── _montecarlo.py
141
+ │ ├── _context.py # NEW: ReturnsContext (compute-once)
142
+ │ ├── version.py
143
+ │ └── py.typed
144
+ │ └── app/ # OPTIONAL: FastAPI adapter (extra = [app])
145
+ │ ├── server.py
146
+ │ ├── schemas.py # Pydantic v2
147
+ │ └── serializers.py # library output -> JSON
148
+ ├── app/ # OPTIONAL: web UI (separate workspace)
149
+ │ ├── package.json
150
+ │ ├── vite.config.ts
151
+ │ └── src/
152
+ │ ├── components/charts/ # <TimeSeriesChart>, <BoxPlot>, <MonthlyHeatmap>...
153
+ │ ├── components/table/ # metrics grid (TanStack Table)
154
+ │ ├── lib/format.ts # single number-format layer
155
+ │ └── theme/tokens.css # dark quant design tokens
156
+ └── tests/
157
+ ├── test_stats.py ... # ported from quantstats
158
+ └── parity/ # NEW: golden-master parity suite
159
+ ├── generate_fixtures.py
160
+ ├── fixtures/ # pickled current-quantstats outputs
161
+ └── test_parity.py
162
+ ```
163
+
164
+ ---
165
+
166
+ ## 6. Parity contract (the enforcement mechanism)
167
+
168
+ "100% parity" is a checklist with an automated gate. Three dimensions:
169
+
170
+ ### 6.1 Function parity — every public symbol exists
171
+ - **`stats.py`** (~80): pct_rank, compsum, comp, expected_return, geometric_mean, ghpr,
172
+ outliers, remove_outliers, best, worst, consecutive_wins/losses, exposure, win_rate,
173
+ avg_return/win/loss, volatility, rolling_volatility, implied_volatility, sharpe,
174
+ smart_sharpe, rolling_sharpe, sortino, smart_sortino, rolling_sortino, adjusted_sortino,
175
+ probabilistic_(sharpe|sortino|adjusted_sortino)_ratio, treynor_ratio, omega,
176
+ gain_to_pain_ratio, cagr, rar, skew, kurtosis, calmar, ulcer_index,
177
+ ulcer_performance_index, upi, serenity_index, risk_of_ruin, ror, value_at_risk, var,
178
+ conditional_value_at_risk, cvar, expected_shortfall, tail_ratio, payoff_ratio,
179
+ win_loss_ratio, profit_ratio, profit_factor, cpc_index, common_sense_ratio,
180
+ outlier_win/loss_ratio, recovery_factor, risk_return_ratio, max_drawdown,
181
+ to_drawdown_series, kelly_criterion, r_squared, r2, information_ratio, greeks,
182
+ rolling_greeks, compare, monthly_returns, drawdown_details, montecarlo,
183
+ montecarlo_sharpe, montecarlo_drawdown, montecarlo_cagr.
184
+ - **`utils.py`** (public): to_returns, to_prices, log_returns, to_log_returns,
185
+ exponential_stdev, rebase, aggregate_returns, group_returns, to_excess_returns,
186
+ multi_shift, download_returns, make_index, make_portfolio, mtd/qtd/ytd helpers.
187
+ - **`reports.py`**: html, full, basic, metrics, plots.
188
+ - **`extend_pandas()`**: the full `_po.*` method map (stats + utils + plotting + metrics).
189
+
190
+ ### 6.2 Report-output parity — every metric row, in order
191
+ `reports.metrics(mode="full")` produces this exact ordered set (the canonical output spec):
192
+
193
+ Start Period · End Period · Risk-Free Rate % · Time in Market % · Cumulative Return % /
194
+ Total Return % · CAGR % · Sharpe · Prob. Sharpe Ratio % · Smart Sharpe · Sortino ·
195
+ Smart Sortino · Sortino/√2 · Smart Sortino/√2 · Omega · Max Drawdown % · Max DD Date ·
196
+ Max DD Period Start/End · Longest DD Days · Volatility (ann.) % · R^2 · Information Ratio ·
197
+ Calmar · Skew · Kurtosis · Ulcer Performance Index · Risk-Adjusted Return % ·
198
+ Risk-Return Ratio · Avg. Return/Win/Loss % · Win/Loss Ratio · Profit Ratio ·
199
+ Expected Daily/Monthly/Yearly % · Kelly Criterion % · Risk of Ruin % · Daily Value-at-Risk % ·
200
+ Expected Shortfall (cVaR) % · Max Consecutive Wins/Losses · Gain/Pain Ratio · Gain/Pain (1M) ·
201
+ Payoff Ratio · Profit Factor · Common Sense Ratio · CPC Index · Tail Ratio ·
202
+ Outlier Win/Loss Ratio · MTD/3M/6M/YTD/1Y % · 3Y/5Y/10Y/All-time (ann.) % ·
203
+ Best/Worst Day/Month/Year % · Avg. Drawdown · Avg. Drawdown Days · Recovery Factor ·
204
+ Ulcer Index · Serenity Index · Avg. Up/Down Month % · Win Days/Month/Quarter/Year % ·
205
+ Beta · Alpha · Correlation · Treynor Ratio.
206
+
207
+ Plus the **EOY Returns (vs Benchmark)** table and the **Worst-5 / Worst-10 Drawdowns** table.
208
+
209
+ ### 6.3 Plot parity — every chart reproduced
210
+ returns · log_returns · vol-matched returns · yearly_returns · histogram · daily_returns ·
211
+ rolling_beta · rolling_volatility · rolling_sharpe · rolling_sortino · drawdowns_periods ·
212
+ drawdown (underwater) · monthly_heatmap · distribution · snapshot · earnings · montecarlo ·
213
+ montecarlo_distribution.
214
+
215
+ Chart parity = **same underlying data + same transforms** (compounded / log / match_volatility /
216
+ rolling windows), NOT pixel-identical to matplotlib (the new charts are the upgrade). The
217
+ golden-master snapshots the data array each matplotlib plot consumes; the UI must render from
218
+ the identical array.
219
+
220
+ ### 6.4 The gate (golden master)
221
+ 1. `generate_fixtures.py` runs the **current quantstats** on a corpus:
222
+ - single-strategy Series; multi-strategy DataFrame
223
+ - with benchmark / without benchmark
224
+ - compounded / simple
225
+ - daily / monthly frequency
226
+ 2. It pickles every metric row, every table, and every chart's source series into `fixtures/`.
227
+ 3. `test_parity.py` runs **openstatz** on the same corpus and asserts:
228
+ - metric numbers match to `rtol=1e-9, atol=1e-12`
229
+ - tables match structurally (rows, order, labels)
230
+ - chart series match exactly
231
+ 4. CI runs this on every commit. A Numba kernel that diverges does not merge.
232
+
233
+ ---
234
+
235
+ ## 7. Performance plan
236
+
237
+ - **`ReturnsContext`**: clean returns, compounded cumulative, log returns, and drawdown series
238
+ computed **once** per request; all metrics read from it (today each metric re-prepares).
239
+ - **Numba kernels** (`_kernels.py`, `@njit(cache=True, nogil=True)`), each gated by §6.4:
240
+ - `montecarlo*` — `parallel=True` + `prange`, pre-generated seeded index matrix for
241
+ deterministic, thread-count-independent results (the big win)
242
+ - `drawdown_details`, `consecutive_wins/losses`, `_count_consecutive` — stateful scans
243
+ - custom rolling kernels where pandas `.apply` is the bottleneck
244
+ - **Leave pure-NumPy reductions alone** (sharpe, vol, var, ratios) — already BLAS-fast; Numba
245
+ adds only warmup cost.
246
+ - `nogil=True` lets FastAPI run kernels in a threadpool without blocking the event loop.
247
+ - Content-hash caching of the full metrics bundle keyed on the returns series.
248
+
249
+ ---
250
+
251
+ ## 8. UI / design ("great quant look")
252
+
253
+ - **Split by cardinality**: canvas (lightweight-charts) for high-cardinality time series;
254
+ bespoke SVG for low-cardinality statistical panels.
255
+ - **Chart adapter boundary**: only `<TimeSeriesChart>` imports lightweight-charts. Normalized
256
+ series contract `{ time: number; value: number }` from the API feeds both it and the future
257
+ openalgo-charts engine.
258
+ - **Typography**: grotesk UI font (Inter/Geist) + **tabular/monospaced numerals** everywhere
259
+ numbers appear; right-align numeric columns. (The signature of a pro financial UI.)
260
+ - **Color**: deep desaturated dark base (not pure black); green/red reserved strictly for P&L
261
+ semantics; one accent; diverging perceptually-uniform scale centered at 0 for the heatmap.
262
+ - **Data-ink**: hairline borders, minimal gridlines, no chartjunk; card layout.
263
+ - **One formatting layer** (`lib/format.ts`): %, bps, decimals, thousands separators, negative
264
+ styling — used by every cell and axis.
265
+ - **PDF export** via headless Chromium (vector SVG stays crisp) — replaces matplotlib raster.
266
+
267
+ ---
268
+
269
+ ## 9. Phased roadmap
270
+
271
+ ### Phase 0 — Foundation & parity harness (highest leverage)
272
+ - [ ] Scaffold repo (pyproject with `[app]` extra, uv, ruff, pyright, CI matrix)
273
+ - [ ] Port quantstats library code into `openstatz/` (rename, keep behavior identical)
274
+ - [ ] Build `tests/parity/` golden-master generator + `test_parity.py`; capture baseline
275
+ - [ ] Green parity run proves drop-in equivalence BEFORE any change
276
+
277
+ ### Phase 1 — Performance (behind parity gate)
278
+ - [ ] Introduce `ReturnsContext`
279
+ - [ ] Add `_kernels.py` Numba kernels (montecarlo first), each must pass §6.4
280
+ - [ ] `pytest-benchmark` baseline vs current; record speedups
281
+
282
+ ### Phase 2 — API adapter
283
+ - [ ] Pydantic v2 schemas + serializers (metrics, tables, chart series)
284
+ - [ ] FastAPI `serve` command; `openstatz serve`
285
+ - [ ] Generate TypeScript types from schemas
286
+
287
+ ### Phase 3 — Web UI
288
+ - [ ] Vite + React + TS + Tailwind + shadcn skeleton
289
+ - [ ] `<TimeSeriesChart>` (lightweight-charts) + EquityPanel/Drawdown/Rolling panels
290
+ - [ ] Bespoke SVG: MonthlyHeatmap, Distribution, BoxPlot
291
+ - [ ] TanStack metrics table (parity-ordered rows)
292
+ - [ ] Design tokens + format layer + PDF export
293
+
294
+ ### Phase 4 — Polish & release
295
+ - [ ] Docs (mkdocs-material), examples
296
+ - [ ] openalgo-charts swap behind `<TimeSeriesChart>` (when ready)
297
+ - [ ] v1.0.0
298
+
299
+ ---
300
+
301
+ ## 10. Compatibility / migration notes
302
+
303
+ - **Public API identical** to quantstats so existing user code works by changing only the import
304
+ (`import openstatz as os`). Note: quantstats tutorials use the `qs` alias; either alias works,
305
+ but the documented OpenStatz convention is `os` (see the alias caveat in §1). Optionally ship a
306
+ thin `quantstats` shim that re-exports openstatz.
307
+ - pandas at the edges keeps `extend_pandas()` and all DataFrame/Series semantics intact.
308
+ - HTML `reports.html()` retained (matplotlib path) so the *library* output matches byte-for-byte;
309
+ the interactive UI is an additional surface, not a replacement.
310
+
311
+ ---
312
+
313
+ ## 11. Open decisions
314
+
315
+ - [x] Package name on PyPI: `openstatz` — **confirmed available**. Documented import alias: `os`.
316
+ - [x] `quantstats`-compat shim: shipped as **opt-in** `openstatz.compat.install_quantstats_shim()`
317
+ (does not silently shadow a real quantstats install).
318
+ - [x] Monorepo for `app/` (web UI lives in this repo alongside the library).
319
+ - [x] Provider abstraction for data: `openstatz.providers` with `yfinance` (default) and an
320
+ optional `OpenAlgo` provider; `ReturnsProvider` protocol for custom backends.
321
+ - [x] Numba: **deferred for now** (compatibility friction with current NumPy). Kernels are pure
322
+ vectorized NumPy and still parity-gated; reintroduce later behind the same gate.
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ All notable changes to OpenStatz are documented here. This project adheres to
4
+ [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [0.1.0] — unreleased
7
+
8
+ The initial OpenStatz rebuild of QuantStats. **Numerically bit-identical** to the
9
+ upstream library (enforced by the golden-master parity suite).
10
+
11
+ ### Added
12
+ - **Library core** (`openstatz/`): the full QuantStats API ported verbatim — `stats`,
13
+ `utils`, `reports`, `plots`, `_montecarlo`, `extend_pandas()` — with identical numbers.
14
+ - **Parity gate** (`tests/parity/`): deterministic corpus × ~70 probes per case, asserting
15
+ openstatz reproduces reference QuantStats to `rtol=1e-9` (metrics, tables, chart series,
16
+ and matching exception classes). Fixtures are committed; CI runs the gate on every commit.
17
+ - **Vectorized kernels** (`openstatz/_kernels.py`): pure-NumPy Monte Carlo cumulative + a
18
+ vectorized per-column max-drawdown (~11× faster, bit-identical). *(Numba is intentionally
19
+ deferred — it creates NumPy-compatibility friction.)*
20
+ - **`ReturnsContext`** (`openstatz/_context.py`): compute the shared derived series once, with
21
+ a content hash for caching.
22
+ - **FastAPI adapter** (`openstatz/app/`, `pip install openstatz[app]`): `serializers` (no math),
23
+ Pydantic v2 `schemas`, a `server` (`/api/health`, `/api/analyze`), and the `openstatz serve`
24
+ CLI. OpenAPI exported for TypeScript generation.
25
+ - **Web UI** (`app/`): Vite + React + TS + Tailwind tearsheet — `TimeSeriesChart` adapter over
26
+ `lightweight-charts`, bespoke SVG heatmap/distribution/box plots, a TanStack metrics table,
27
+ one formatting layer, dark "pro quant" tokens, and vector PDF export.
28
+ - **Data providers** (`openstatz/providers.py`): pluggable `ReturnsProvider` — `yfinance`
29
+ (default) and an optional `OpenAlgo` provider.
30
+ - **quantstats-compat shim** (`openstatz/compat.py`): opt-in `install_quantstats_shim()` so
31
+ `import quantstats as qs` runs on OpenStatz unmodified.
32
+
33
+ ### Notes
34
+ - Public API is identical to QuantStats; existing code works by changing only the import
35
+ (`import openstatz as os`, or the `qs` alias).
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
openstatz-0.1.0/NOTICE ADDED
@@ -0,0 +1,16 @@
1
+ OpenStatz
2
+ Copyright 2026 OpenStatz contributors
3
+
4
+ This product is a rebuild of QuantStats and reuses its portfolio-analytics
5
+ implementation verbatim for numerical parity.
6
+
7
+ QuantStats
8
+ Copyright 2019-2025 Ran Aroussi
9
+ https://github.com/ranaroussi/quantstats
10
+ Licensed under the Apache License, Version 2.0.
11
+
12
+ Licensed under the Apache License, Version 2.0 (the "License");
13
+ you may not use this file except in compliance with the License.
14
+ You may obtain a copy of the License at
15
+
16
+ http://www.apache.org/licenses/LICENSE-2.0