quantstats-pro 0.4.1__py3-none-any.whl
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.
- quantstats/__init__.py +163 -0
- quantstats/_compat.py +431 -0
- quantstats/_montecarlo.py +296 -0
- quantstats/_numpy_compat.py +289 -0
- quantstats/_plotting/__init__.py +0 -0
- quantstats/_plotting/core.py +2173 -0
- quantstats/_plotting/wrappers.py +2109 -0
- quantstats/_reporting/__init__.py +12 -0
- quantstats/_reporting/engine.py +37 -0
- quantstats/_reporting/sections.py +223 -0
- quantstats/alphadecay/__init__.py +25 -0
- quantstats/alphadecay/core.py +712 -0
- quantstats/alphadecay/plotting.py +206 -0
- quantstats/montecarlo/__init__.py +34 -0
- quantstats/montecarlo/analytics.py +291 -0
- quantstats/montecarlo/base.py +92 -0
- quantstats/montecarlo/core.py +175 -0
- quantstats/montecarlo/models/__init__.py +15 -0
- quantstats/montecarlo/models/bayesian.py +88 -0
- quantstats/montecarlo/models/block_bootstrap.py +108 -0
- quantstats/montecarlo/models/bootstrap.py +38 -0
- quantstats/montecarlo/models/garch.py +83 -0
- quantstats/montecarlo/models/gbm.py +44 -0
- quantstats/montecarlo/models/heston.py +103 -0
- quantstats/montecarlo/models/jump_diffusion.py +86 -0
- quantstats/montecarlo/models/shuffle.py +49 -0
- quantstats/montecarlo/models/trimmed.py +50 -0
- quantstats/montecarlo/plotting.py +324 -0
- quantstats/montecarlo/registry.py +34 -0
- quantstats/plots.py +27 -0
- quantstats/py.typed +0 -0
- quantstats/report.html +64 -0
- quantstats/report_alpha_decay.html +43 -0
- quantstats/report_montecarlo.html +62 -0
- quantstats/report_simple.html +58 -0
- quantstats/reports.py +3502 -0
- quantstats/stats.py +3321 -0
- quantstats/utils.py +1011 -0
- quantstats/version.py +1 -0
- quantstats_pro-0.4.1.dist-info/METADATA +509 -0
- quantstats_pro-0.4.1.dist-info/RECORD +43 -0
- quantstats_pro-0.4.1.dist-info/WHEEL +4 -0
- quantstats_pro-0.4.1.dist-info/licenses/LICENSE.txt +202 -0
quantstats/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = "0.4.1"
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quantstats-pro
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Enhanced drop-in replacement for QuantStats — portfolio analytics for quants
|
|
5
|
+
Project-URL: Homepage, https://github.com/diegoalvarezmgl/quantstats-pro
|
|
6
|
+
Project-URL: Documentation, https://github.com/diegoalvarezmgl/quantstats-pro
|
|
7
|
+
Project-URL: Repository, https://github.com/diegoalvarezmgl/quantstats-pro
|
|
8
|
+
Project-URL: Changelog, https://github.com/diegoalvarezmgl/quantstats-pro/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Upstream, https://github.com/ranaroussi/quantstats
|
|
10
|
+
Author-email: Diego Alvarez <diegoalvarezmiguel@gmail.com>, Ran Aroussi <ran@aroussi.com>
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE.txt
|
|
13
|
+
Keywords: algo-trading,algorithmic-trading,algotrading,finance,plotting,portfolio,quant,quantitative-analysis,quantitative-trading,visualization
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
26
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering
|
|
28
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
29
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
30
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
31
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
32
|
+
Requires-Python: >=3.10
|
|
33
|
+
Requires-Dist: arch>=6.0
|
|
34
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
35
|
+
Requires-Dist: numpy>=1.24.0
|
|
36
|
+
Requires-Dist: pandas>=1.5.0
|
|
37
|
+
Requires-Dist: python-dateutil>=2.8.0
|
|
38
|
+
Requires-Dist: scipy>=1.11.0
|
|
39
|
+
Requires-Dist: seaborn>=0.13.0
|
|
40
|
+
Requires-Dist: tabulate>=0.9.0
|
|
41
|
+
Requires-Dist: yfinance>=0.2.40
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: ipython>=8.0.0; extra == 'dev'
|
|
44
|
+
Requires-Dist: pandas-stubs>=2.0.0; extra == 'dev'
|
|
45
|
+
Requires-Dist: pyright>=1.1.0; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
48
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
49
|
+
Provides-Extra: plotly
|
|
50
|
+
Requires-Dist: plotly>=5.0.0; extra == 'plotly'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
[](https://pypi.org/project/quantstats-pro/)
|
|
54
|
+
[](https://pypi.org/project/quantstats-pro/)
|
|
55
|
+
[](https://github.com/diegoalvarezmgl/quantstats-pro/actions/workflows/ci.yml)
|
|
56
|
+
[](LICENSE.txt)
|
|
57
|
+
|
|
58
|
+
# QuantStats Pro: Portfolio analytics for quants
|
|
59
|
+
|
|
60
|
+
**QuantStats Pro** is an enhanced, actively maintained **drop-in replacement** for [QuantStats](https://github.com/ranaroussi/quantstats) by Ran Aroussi. It performs portfolio profiling, allowing quants and portfolio managers to understand their performance with in-depth analytics and risk metrics.
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install quantstats-pro # replaces: pip install quantstats
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import quantstats as qs # import unchanged
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
> **Note:** QuantStats Pro **cannot coexist** with the original `quantstats`
|
|
71
|
+
> package in the same environment — both provide the `quantstats` import
|
|
72
|
+
> namespace. Uninstall `quantstats` before installing `quantstats-pro`
|
|
73
|
+
> (`pip uninstall quantstats`).
|
|
74
|
+
|
|
75
|
+
[Changelog »](./CHANGELOG.md) · [Upstream »](https://github.com/ranaroussi/quantstats) · [Contributing »](./CONTRIBUTING.md)
|
|
76
|
+
|
|
77
|
+
### Why QuantStats Pro?
|
|
78
|
+
|
|
79
|
+
This fork fixes known bugs, improves reliability, and evolves reports and visualizations — while keeping the same `import quantstats as qs` API.
|
|
80
|
+
|
|
81
|
+
**What's new in Pro (beyond upstream):**
|
|
82
|
+
|
|
83
|
+
- **`quantstats.montecarlo`** — multi-model Monte Carlo engine (GBM, GARCH, Heston, bootstraps, Bayesian, …) with cross-model analytics and an institutional HTML tearsheet
|
|
84
|
+
- **`quantstats.alphadecay`** — rolling-window alpha-decay monitor with z-score traffic lights, CUSUM, and time-underwater diagnostics
|
|
85
|
+
- **New HTML tearsheets** — `html_simple`, `html_montecarlo`, `html_alpha_decay` (plus the classic full `html` report)
|
|
86
|
+
- **Visual redesign** — updated branding and chart palette on the classic tearsheet (v0.2.0+)
|
|
87
|
+
|
|
88
|
+
### Package modules
|
|
89
|
+
|
|
90
|
+
| Module | Purpose |
|
|
91
|
+
|--------|---------|
|
|
92
|
+
| `quantstats.stats` | 50+ performance metrics (Sharpe, Sortino, drawdown, VaR, …) |
|
|
93
|
+
| `quantstats.plots` | Performance visualizations (returns, drawdown, heatmaps, rolling stats, …) |
|
|
94
|
+
| `quantstats.reports` | HTML tearsheets and metrics tables |
|
|
95
|
+
| `quantstats.montecarlo` | Multi-model forward simulation engine and analytics |
|
|
96
|
+
| `quantstats.alphadecay` | Short-horizon rolling risk analysis and decay detection |
|
|
97
|
+
| `quantstats.utils` | Data prep, `download_returns`, pandas helpers |
|
|
98
|
+
|
|
99
|
+
Legacy shuffle-based Monte Carlo remains at `qs.stats.montecarlo()` for backward compatibility. The new engine lives under `quantstats.montecarlo` and powers `qs.reports.html_montecarlo()`.
|
|
100
|
+
|
|
101
|
+
### Crypto and 24/7 markets
|
|
102
|
+
|
|
103
|
+
For daily crypto data, pass `periods_per_year=365` to reports and stats that annualize:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import quantstats as qs
|
|
107
|
+
|
|
108
|
+
qs.extend_pandas()
|
|
109
|
+
returns = qs.utils.download_returns("BTC-USD")
|
|
110
|
+
|
|
111
|
+
# Tearsheet with 365 trading days per year
|
|
112
|
+
qs.reports.html(returns, periods_per_year=365, output="btc_report.html")
|
|
113
|
+
|
|
114
|
+
# Individual metrics
|
|
115
|
+
qs.stats.sharpe(returns, periods=365)
|
|
116
|
+
qs.stats.rar(returns, periods=365)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
qs.stats.rar(returns, periods=365)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## HTML Tearsheets
|
|
125
|
+
|
|
126
|
+
QuantStats Pro ships **four** HTML report types. All open in the browser by default, or save to disk with `output="path.html"`.
|
|
127
|
+
|
|
128
|
+
| Function | Use case |
|
|
129
|
+
|----------|----------|
|
|
130
|
+
| `qs.reports.html(...)` | Full classic tearsheet (metrics + all charts) |
|
|
131
|
+
| `qs.reports.html_simple(...)` | Lean equity-curve tearsheet — core metrics and charts only |
|
|
132
|
+
| `qs.reports.html_montecarlo(...)` | Multi-model Monte Carlo risk analysis (1y forward horizon by default) |
|
|
133
|
+
| `qs.reports.html_alpha_decay(...)` | Short-window alpha-decay health monitor (7/15/30d) |
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import quantstats as qs
|
|
137
|
+
|
|
138
|
+
returns = qs.utils.download_returns("QQQ")
|
|
139
|
+
|
|
140
|
+
# Classic full report vs benchmark
|
|
141
|
+
qs.reports.html(returns, benchmark="SPY", output="qqq_full.html")
|
|
142
|
+
|
|
143
|
+
# Simplified equity-curve view
|
|
144
|
+
qs.reports.html_simple(returns, benchmark="SPY", output="qqq_simple.html")
|
|
145
|
+
|
|
146
|
+
# Multi-model Monte Carlo (median consensus + stress envelope)
|
|
147
|
+
qs.reports.html_montecarlo(
|
|
148
|
+
returns,
|
|
149
|
+
bust=-0.25, # P(Bust): drawdown threshold
|
|
150
|
+
goal=0.50, # P(Goal): terminal return target
|
|
151
|
+
sims=500,
|
|
152
|
+
seed=42,
|
|
153
|
+
output="qqq_montecarlo.html",
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Alpha decay monitor
|
|
157
|
+
qs.reports.html_alpha_decay(
|
|
158
|
+
returns,
|
|
159
|
+
windows=(7, 15, 30),
|
|
160
|
+
output="qqq_alpha_decay.html",
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
[View sample classic tearsheet](./docs/tearsheet.html) · [Monte Carlo docs](./docs/montecarlo.md)
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Monte Carlo Engine
|
|
169
|
+
|
|
170
|
+
`quantstats.montecarlo` characterises an asset with several stochastic models, simulates forward paths from each, and compares the distribution of outcomes (CAGR, max drawdown, bust/goal probabilities, CVaR).
|
|
171
|
+
|
|
172
|
+
### Built-in models
|
|
173
|
+
|
|
174
|
+
| Model | Name | Category |
|
|
175
|
+
|-------|------|----------|
|
|
176
|
+
| GBM | `gbm` | Monte Carlo |
|
|
177
|
+
| Shuffle (legacy) | `shuffle` | Monte Carlo |
|
|
178
|
+
| Bootstrap | `bootstrap` | Monte Carlo |
|
|
179
|
+
| Block Bootstrap | `block_bootstrap` | Monte Carlo |
|
|
180
|
+
| Jump Diffusion (Merton) | `jump_diffusion` | Monte Carlo |
|
|
181
|
+
| GARCH(1,1)-t | `garch` | Monte Carlo |
|
|
182
|
+
| Heston (SV) | `heston` | Monte Carlo |
|
|
183
|
+
| Bayesian (NIG) | `bayesian` | Monte Carlo |
|
|
184
|
+
| Bayesian Bootstrap | `bayesian_bootstrap` | Monte Carlo |
|
|
185
|
+
| Trimmed Bootstrap (top 1%) | `trimmed_1pct` | Stress |
|
|
186
|
+
|
|
187
|
+
### Programmatic API
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from quantstats.montecarlo import run_models, available_models
|
|
191
|
+
from quantstats.montecarlo import analytics as mca
|
|
192
|
+
|
|
193
|
+
print(available_models())
|
|
194
|
+
# ['bayesian', 'bayesian_bootstrap', 'block_bootstrap', 'bootstrap', ...]
|
|
195
|
+
|
|
196
|
+
results = run_models(
|
|
197
|
+
returns,
|
|
198
|
+
models=["gbm", "garch", "bootstrap"],
|
|
199
|
+
horizon=252, # 1 year (default: periods_per_year)
|
|
200
|
+
sims=1000,
|
|
201
|
+
bust=-0.25,
|
|
202
|
+
goal=0.50,
|
|
203
|
+
seed=42,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
# Per-model summary row
|
|
207
|
+
gbm = results["gbm"]
|
|
208
|
+
print(gbm.summary) # cagr_p5, cagr_median, maxdd_p95, prob_loss, cvar_5, …
|
|
209
|
+
print(gbm.sim_returns.shape) # (horizon, sims)
|
|
210
|
+
|
|
211
|
+
# Cross-model consensus and stress envelope
|
|
212
|
+
median = mca.model_median_summary(results)
|
|
213
|
+
envelope = mca.conservative_envelope(results)
|
|
214
|
+
hist = mca.historical_summary(returns, horizon=252)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Legacy shuffle Monte Carlo
|
|
218
|
+
|
|
219
|
+
The original upstream API still works — random permutation of historical returns:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
mc = qs.stats.montecarlo(returns, sims=1000, bust=-0.20, goal=0.50, seed=42)
|
|
223
|
+
print(f"Bust probability: {mc.bust_probability:.1%}")
|
|
224
|
+
print(f"Goal probability: {mc.goal_probability:.1%}")
|
|
225
|
+
mc.plot()
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
[Full Monte Carlo documentation »](./docs/montecarlo.md)
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Alpha Decay Monitor
|
|
233
|
+
|
|
234
|
+
`quantstats.alphadecay` tracks whether a strategy's short-term risk profile is drifting from its historical norm. It computes **10 rolling metrics** over configurable windows (default 7/15/30 days):
|
|
235
|
+
|
|
236
|
+
CAGR · Volatility · Downside Vol · Max Drawdown · Mean Drawdown · Win Rate · VaR 95% · Expected Shortfall 95% · Payoff Ratio · Skew
|
|
237
|
+
|
|
238
|
+
Each metric-window cell gets a **traffic-light status** (Excellent / Good / Warning / Critical) based on z-scores computed on a per-metric analysis scale (log transforms for skewed metrics). The tearsheet also includes:
|
|
239
|
+
|
|
240
|
+
- **Health score** — count of Good/Excellent cells
|
|
241
|
+
- **CUSUM** return-decay detector
|
|
242
|
+
- **Time underwater** duration analysis
|
|
243
|
+
- Per-metric distribution charts with current observation vs historical mean
|
|
244
|
+
|
|
245
|
+
### Programmatic API
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from quantstats.alphadecay import analyze, available_metrics
|
|
249
|
+
|
|
250
|
+
print(available_metrics())
|
|
251
|
+
# ['cagr', 'volatility', 'downside_vol', 'max_drawdown', ...]
|
|
252
|
+
|
|
253
|
+
result = analyze(
|
|
254
|
+
returns,
|
|
255
|
+
windows=(7, 15, 30),
|
|
256
|
+
rf=0.0,
|
|
257
|
+
periods=252,
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
print(f"Health: {result.score}/{result.total} ({result.score_pct:.0f}%)")
|
|
261
|
+
|
|
262
|
+
for metric in result.metrics:
|
|
263
|
+
wr = metric.windows[30] # latest 30-day window
|
|
264
|
+
print(f"{metric.spec.label}: z={wr.z_score:+.2f} → {wr.status}")
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Generate the full HTML tearsheet with `qs.reports.html_alpha_decay(returns)`.
|
|
268
|
+
|
|
269
|
+
[Alpha Decay documentation »](./docs/alphadecay.md)
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Quick Start
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
%matplotlib inline
|
|
277
|
+
import quantstats as qs
|
|
278
|
+
|
|
279
|
+
# extend pandas functionality with metrics, etc.
|
|
280
|
+
qs.extend_pandas()
|
|
281
|
+
|
|
282
|
+
# fetch the daily returns for a stock
|
|
283
|
+
stock = qs.utils.download_returns('META')
|
|
284
|
+
|
|
285
|
+
# show sharpe ratio
|
|
286
|
+
qs.stats.sharpe(stock)
|
|
287
|
+
|
|
288
|
+
# or using extend_pandas() :)
|
|
289
|
+
stock.sharpe()
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Output:
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
0.7604779884378278
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Visualize stock performance
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
qs.plots.snapshot(stock, title='Facebook Performance', show=True)
|
|
302
|
+
|
|
303
|
+
# can also be called via:
|
|
304
|
+
# stock.plot_snapshot(title='Facebook Performance', show=True)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Output:
|
|
308
|
+
|
|
309
|
+

|
|
310
|
+
|
|
311
|
+
### Creating a report
|
|
312
|
+
|
|
313
|
+
The classic full tearsheet compares a strategy against an optional benchmark:
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
# benchmark can be a pandas Series or ticker
|
|
317
|
+
qs.reports.html(stock, "SPY", output="meta_report.html")
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Output will generate something like this:
|
|
321
|
+
|
|
322
|
+

|
|
323
|
+
|
|
324
|
+
See [HTML Tearsheets](#html-tearsheets) above for `html_simple`, `html_montecarlo`, and `html_alpha_decay`.
|
|
325
|
+
|
|
326
|
+
### Available methods
|
|
327
|
+
|
|
328
|
+
To view a complete list of available methods, run:
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
[f for f in dir(qs.stats) if f[0] != '_']
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
```python
|
|
335
|
+
['avg_loss',
|
|
336
|
+
'avg_return',
|
|
337
|
+
'avg_win',
|
|
338
|
+
'best',
|
|
339
|
+
'cagr',
|
|
340
|
+
'calmar',
|
|
341
|
+
'common_sense_ratio',
|
|
342
|
+
'comp',
|
|
343
|
+
'compare',
|
|
344
|
+
'compsum',
|
|
345
|
+
'conditional_value_at_risk',
|
|
346
|
+
'consecutive_losses',
|
|
347
|
+
'consecutive_wins',
|
|
348
|
+
'cpc_index',
|
|
349
|
+
'cvar',
|
|
350
|
+
'drawdown_details',
|
|
351
|
+
'expected_return',
|
|
352
|
+
'expected_shortfall',
|
|
353
|
+
'exposure',
|
|
354
|
+
'gain_to_pain_ratio',
|
|
355
|
+
'geometric_mean',
|
|
356
|
+
'ghpr',
|
|
357
|
+
'greeks',
|
|
358
|
+
'implied_volatility',
|
|
359
|
+
'information_ratio',
|
|
360
|
+
'kelly_criterion',
|
|
361
|
+
'kurtosis',
|
|
362
|
+
'max_drawdown',
|
|
363
|
+
'monthly_returns',
|
|
364
|
+
'montecarlo',
|
|
365
|
+
'montecarlo_cagr',
|
|
366
|
+
'montecarlo_drawdown',
|
|
367
|
+
'montecarlo_sharpe',
|
|
368
|
+
'outlier_loss_ratio',
|
|
369
|
+
'outlier_win_ratio',
|
|
370
|
+
'outliers',
|
|
371
|
+
'payoff_ratio',
|
|
372
|
+
'profit_factor',
|
|
373
|
+
'profit_ratio',
|
|
374
|
+
'r2',
|
|
375
|
+
'r_squared',
|
|
376
|
+
'rar',
|
|
377
|
+
'recovery_factor',
|
|
378
|
+
'remove_outliers',
|
|
379
|
+
'risk_of_ruin',
|
|
380
|
+
'risk_return_ratio',
|
|
381
|
+
'rolling_greeks',
|
|
382
|
+
'ror',
|
|
383
|
+
'sharpe',
|
|
384
|
+
'skew',
|
|
385
|
+
'sortino',
|
|
386
|
+
'adjusted_sortino',
|
|
387
|
+
'tail_ratio',
|
|
388
|
+
'to_drawdown_series',
|
|
389
|
+
'ulcer_index',
|
|
390
|
+
'ulcer_performance_index',
|
|
391
|
+
'upi',
|
|
392
|
+
'value_at_risk',
|
|
393
|
+
'var',
|
|
394
|
+
'volatility',
|
|
395
|
+
'win_loss_ratio',
|
|
396
|
+
'win_rate',
|
|
397
|
+
'worst']
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
```python
|
|
401
|
+
[f for f in dir(qs.plots) if f[0] != '_']
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
```python
|
|
405
|
+
['daily_returns',
|
|
406
|
+
'distribution',
|
|
407
|
+
'drawdown',
|
|
408
|
+
'drawdowns_periods',
|
|
409
|
+
'earnings',
|
|
410
|
+
'histogram',
|
|
411
|
+
'log_returns',
|
|
412
|
+
'monthly_heatmap',
|
|
413
|
+
'montecarlo',
|
|
414
|
+
'montecarlo_distribution',
|
|
415
|
+
'returns',
|
|
416
|
+
'rolling_beta',
|
|
417
|
+
'rolling_sharpe',
|
|
418
|
+
'rolling_sortino',
|
|
419
|
+
'rolling_volatility',
|
|
420
|
+
'snapshot',
|
|
421
|
+
'yearly_returns']
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
See [Monte Carlo documentation](./docs/montecarlo.md) and `help(qs.stats.<method>)` for parameter details.
|
|
425
|
+
|
|
426
|
+
Console / notebook helpers:
|
|
427
|
+
|
|
428
|
+
```python
|
|
429
|
+
qs.reports.metrics(returns, mode="full") # metrics table
|
|
430
|
+
qs.reports.plots(returns, mode="full") # all plots
|
|
431
|
+
qs.reports.basic(returns) # basic metrics + plots
|
|
432
|
+
qs.reports.full(returns) # full metrics + plots
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Important: Period-Based vs Trade-Based Metrics
|
|
436
|
+
|
|
437
|
+
QuantStats analyzes **return series** (daily, weekly, monthly returns), not discrete trade data. This means:
|
|
438
|
+
|
|
439
|
+
- **Win Rate** = percentage of periods with positive returns
|
|
440
|
+
- **Consecutive Wins/Losses** = consecutive positive/negative return periods
|
|
441
|
+
- **Payoff Ratio** = average winning period return / average losing period return
|
|
442
|
+
- **Profit Factor** = sum of positive returns / sum of negative returns
|
|
443
|
+
|
|
444
|
+
These metrics are **valid and useful** for:
|
|
445
|
+
- Systematic/algorithmic strategies with regular rebalancing
|
|
446
|
+
- Analyzing return-series behavior over time
|
|
447
|
+
- Comparing strategies on a period-by-period basis
|
|
448
|
+
|
|
449
|
+
For **discretionary traders** with multi-day trades, these period-based metrics may differ from trade-level statistics. A single 5-day trade might span 3 positive days and 2 negative days - QuantStats would count these as 3 "wins" and 2 "losses" at the daily level.
|
|
450
|
+
|
|
451
|
+
This is consistent with how all return-based analytics work (Sharpe ratio, Sortino ratio, drawdown analysis, etc.) - they operate on return periods, not discrete trade entries/exits.
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
In the meantime, you can get insights as to optional parameters for each method, by using Python's `help` method:
|
|
456
|
+
|
|
457
|
+
```python
|
|
458
|
+
help(qs.stats.conditional_value_at_risk)
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
```
|
|
462
|
+
Help on function conditional_value_at_risk in module quantstats.stats:
|
|
463
|
+
|
|
464
|
+
conditional_value_at_risk(returns, sigma=1, confidence=0.99)
|
|
465
|
+
calculates the conditional daily value-at-risk (aka expected shortfall)
|
|
466
|
+
quantifies the amount of tail risk an investment
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
## Installation
|
|
470
|
+
|
|
471
|
+
Install using `pip`:
|
|
472
|
+
|
|
473
|
+
```bash
|
|
474
|
+
pip install quantstats-pro --upgrade
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
## Requirements
|
|
478
|
+
|
|
479
|
+
* [Python](https://www.python.org) >= 3.10
|
|
480
|
+
* [pandas](https://github.com/pydata/pandas) >= 1.5.0
|
|
481
|
+
* [numpy](http://www.numpy.org) >= 1.24.0
|
|
482
|
+
* [scipy](https://www.scipy.org) >= 1.11.0
|
|
483
|
+
* [matplotlib](https://matplotlib.org) >= 3.7.0
|
|
484
|
+
* [seaborn](https://seaborn.pydata.org) >= 0.13.0
|
|
485
|
+
* [tabulate](https://bitbucket.org/astanin/python-tabulate) >= 0.9.0
|
|
486
|
+
* [yfinance](https://github.com/ranaroussi/yfinance) >= 0.2.40
|
|
487
|
+
* [arch](https://github.com/bashtage/arch) >= 6.0 (GARCH calibration for Monte Carlo)
|
|
488
|
+
* [plotly](https://plot.ly/) >= 5.0.0 (optional, for using `plots.to_plotly()`)
|
|
489
|
+
|
|
490
|
+
## Questions?
|
|
491
|
+
|
|
492
|
+
If you find a bug, please [open an issue](https://github.com/diegoalvarezmgl/quantstats-pro/issues).
|
|
493
|
+
|
|
494
|
+
Contributions welcome — check [open issues](https://github.com/diegoalvarezmgl/quantstats-pro/issues) or upstream [QuantStats issues](https://github.com/ranaroussi/quantstats/issues) for bugs we're tracking.
|
|
495
|
+
|
|
496
|
+
## Known Issues
|
|
497
|
+
|
|
498
|
+
For some reason, I couldn't find a way to tell seaborn not to return the
|
|
499
|
+
monthly returns heatmap when instructed to save - so even if you save the plot (by passing `savefig={...}`) it will still show the plot.
|
|
500
|
+
|
|
501
|
+
## Legal Stuff
|
|
502
|
+
|
|
503
|
+
**QuantStats Pro** is a fork of **QuantStats** by Ran Aroussi, distributed under the **Apache Software License**. See [LICENSE.txt](./LICENSE.txt) for details.
|
|
504
|
+
|
|
505
|
+
## Credits
|
|
506
|
+
|
|
507
|
+
**QuantStats Pro** — maintained by [Diego Alvarez](https://github.com/diegoalvarezmgl)
|
|
508
|
+
|
|
509
|
+
**QuantStats** (original) — [Ran Aroussi](https://github.com/ranaroussi)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
quantstats/__init__.py,sha256=qwvrDhlqbq0AaNu_mT7bcfcMh8kldWszPHWvrj_fV8E,9172
|
|
2
|
+
quantstats/_compat.py,sha256=5wCRlfUyhZRNy28QkxtQx6vJ7sJyhig-rNpHXzl0gCk,14968
|
|
3
|
+
quantstats/_montecarlo.py,sha256=pZx6JZtWU8cJAYH1vVsGz5NxK9pRPkwHhqULyEDau9c,8983
|
|
4
|
+
quantstats/_numpy_compat.py,sha256=SOeFKc7zRdHc1O5JzDGy2fQZj4EoItL_Iqlhs5i6bPs,9682
|
|
5
|
+
quantstats/plots.py,sha256=SAiboz43k8xLN8MxhOVLNsdYyREynRcdQU_uNhqzEhM,857
|
|
6
|
+
quantstats/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
quantstats/report.html,sha256=9M3FjhfGkEMp3REH_pdcH6VKWHDL2-MVZWb-yCttdjI,3915
|
|
8
|
+
quantstats/report_alpha_decay.html,sha256=EuHUH90VY_rcxpS39qVaWKsiaNCxUDttcmriXBmN3jw,4474
|
|
9
|
+
quantstats/report_montecarlo.html,sha256=pfEqKj2VXPjdEyfHXcOIOgpmLxYrUaxI-uhrTJpDHpA,4855
|
|
10
|
+
quantstats/report_simple.html,sha256=8cnemCo9RdfPTOlMZOcJr2StmPlj_B8LfY-K_Sfga-E,3466
|
|
11
|
+
quantstats/reports.py,sha256=yyM0ucrVB6uiNizSST9vscZmyQqXcqCs68QbOUR4Tn4,124066
|
|
12
|
+
quantstats/stats.py,sha256=93Ke-6tbW19Pf4iuVjJeyrk3PP93By2U_SS5YqxH7hk,114564
|
|
13
|
+
quantstats/utils.py,sha256=OpcAguM8Z-3rbinQjE2uqXTwiiNhN3nqkhrZ2Lr1mkM,29887
|
|
14
|
+
quantstats/version.py,sha256=FBeN5tbWV0BpBmjJ3d3pzaNRlEg_Blp421Tbg8X3cAI,18
|
|
15
|
+
quantstats/_plotting/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
quantstats/_plotting/core.py,sha256=DEtT2PtPpiVkbcGts3-7lkxLUyIuz7s7afipZnv-jJ4,62162
|
|
17
|
+
quantstats/_plotting/wrappers.py,sha256=nZjiJJuAME801kxaDr9AHaXWN1odSLv01akWfBn9_SA,70482
|
|
18
|
+
quantstats/_reporting/__init__.py,sha256=zUMxPK6PvmujBhm_gP_3nPKG4PUYuOp5DrgxxX7iulc,399
|
|
19
|
+
quantstats/_reporting/engine.py,sha256=RPbyX7nUpcHNBdpYtmL2VCyrAc_SzGvjyIl1qzLQiIo,1122
|
|
20
|
+
quantstats/_reporting/sections.py,sha256=hkONuRQClAYod6gvAFr_P7kkEFqQXWMQ9xqqktqrVB4,6768
|
|
21
|
+
quantstats/alphadecay/__init__.py,sha256=JNpcjE33_QMW6_13FRA_ATFQlEDoU2npSy4lw3hDvNY,521
|
|
22
|
+
quantstats/alphadecay/core.py,sha256=jWWYIBRWhu28lddXRTUwwFGwOyJyGRmL7zI3-uF2LiQ,23425
|
|
23
|
+
quantstats/alphadecay/plotting.py,sha256=cCmh19OUfZhib8J6tvwxTBBkhTxebaLp5IyiIXHJ0zU,6693
|
|
24
|
+
quantstats/montecarlo/__init__.py,sha256=kAXaDjsOUIACkuqZAFvPMqmGvORpzU9dVRMp_hLRRN8,1051
|
|
25
|
+
quantstats/montecarlo/analytics.py,sha256=qYzBWsdneos0enjCXuwT1JJE8cSAKu9cNYg_LsBjYbI,9706
|
|
26
|
+
quantstats/montecarlo/base.py,sha256=uvw-FlbXt7RHKiAT95pbaaRezT2pzlaDmZhIlGzml-A,3119
|
|
27
|
+
quantstats/montecarlo/core.py,sha256=QDE4ySlhNxoYIUj42qtgHlj30vjFVQ8NZn6kSu1ZH9s,5850
|
|
28
|
+
quantstats/montecarlo/plotting.py,sha256=9mUDzApYujVSgaY6gC5EFJHhRuYYTiGjwIj0EmCgPeY,10051
|
|
29
|
+
quantstats/montecarlo/registry.py,sha256=ZuLfLV3B4HC-44C9o5cSxWalhSmzsMtcsFwQCGQ4Ud4,996
|
|
30
|
+
quantstats/montecarlo/models/__init__.py,sha256=gV_LCotG-LXwGJ-LRD2c2KVINwh5iWpHnnq8QBkDZjg,269
|
|
31
|
+
quantstats/montecarlo/models/bayesian.py,sha256=uI3NJ3xW4SpwTNjqWNoFa5WV4pQLO0oediHOKBLagF4,3121
|
|
32
|
+
quantstats/montecarlo/models/block_bootstrap.py,sha256=Ai0rOd7EIqPz-fhUTYNgWNZcvAI4inyqxY3oH1vVQ1Y,3600
|
|
33
|
+
quantstats/montecarlo/models/bootstrap.py,sha256=Hsj95ETYC0jEvkQGpwgZRk63rJzs1T9hcgs1BOid_Fk,1108
|
|
34
|
+
quantstats/montecarlo/models/garch.py,sha256=tUnOGiMhQUBwITaVLlqHPtK1VOM0GTnsIIO42qRc8O0,3090
|
|
35
|
+
quantstats/montecarlo/models/gbm.py,sha256=MyTSzcYFyAZKZpABn9EnoXIe2DtzaPwKNwzK0pvQPWs,1331
|
|
36
|
+
quantstats/montecarlo/models/heston.py,sha256=82nYY0XTOWuumxNyDeYxOwWWr2PMt8v7y500AGiisxw,3875
|
|
37
|
+
quantstats/montecarlo/models/jump_diffusion.py,sha256=e8gHTYqcaKSKLqBY23RveqdO620ub8CIv4N76HpTXA0,3196
|
|
38
|
+
quantstats/montecarlo/models/shuffle.py,sha256=PsReqfqcUgCzM6mo-qudOTUuP7TCzkxmwTKy16U_hME,1684
|
|
39
|
+
quantstats/montecarlo/models/trimmed.py,sha256=Z8fRsBN-9YG_e7lEhjlWilaq2-mRoFoGc0mKdQziPLo,1514
|
|
40
|
+
quantstats_pro-0.4.1.dist-info/METADATA,sha256=E0dLV69S2NFXOoQDwOak6jvzfDgyN6kG4l-tekaliUs,16764
|
|
41
|
+
quantstats_pro-0.4.1.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
42
|
+
quantstats_pro-0.4.1.dist-info/licenses/LICENSE.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
43
|
+
quantstats_pro-0.4.1.dist-info/RECORD,,
|