-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddstats.pyi
More file actions
96 lines (83 loc) · 2.03 KB
/
ddstats.pyi
File metadata and controls
96 lines (83 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from __future__ import annotations
from typing import Literal
from numpy.typing import NDArray
import numpy as np
__version__: str
def max_drawdown(returns: NDArray[np.float64], /) -> float:
"""
Compute the maximum drawdown (MDD).
Parameters
----------
returns : numpy.ndarray (float64, 1-D)
Return series over time.
Returns
-------
float
Positive drawdown fraction (e.g., 0.25 == -25%).
"""
def rolling_max_drawdown(
returns: NDArray[np.float64],
window: int,
min_window: int | None = ...,
step: int | None = ...,
*,
parallel: bool = True,
) -> NDArray[np.float64]:
"""
Rolling maximum drawdown (MDD).
Parameters
----------
returns : ndarray[float64], shape (n,)
window : int
min_window : int, optional
step : int, optional
parallel : bool, default True
Returns
-------
ndarray[float64]
Rolling MDD values.
"""
def ced(
returns: NDArray[np.float64],
t: int = 21,
alpha: float = 0.9,
*,
parallel: bool = True,
) -> float:
"""
Conditional Expected Drawdown (CED).
Parameters
----------
returns : ndarray[float64], shape (n,)
t : int, default 21
alpha : float, default 0.9
parallel : bool, default True
Returns
-------
float
Mean of the top (1 - alpha) tail of rolling MDDs (NumPy-linear, >= threshold).
"""
def expanding_ced(
returns: NDArray[np.float64],
t: int = 21,
alpha: float = 0.9,
*,
method: Literal["heap", "sort"] = "heap",
parallel: bool = True,
) -> NDArray[np.float64]:
"""
Expanding CED series.
Parameters
----------
returns : ndarray[float64], shape (n,)
t : int, default 21
alpha : float, default 0.9
method : {'heap','sort'}, default 'heap'
'heap' matches NumPy selection (>= quantile) with O(n log n);
'sort' is exact but slower.
parallel : bool, default True
Returns
-------
ndarray[float64]
Expanding CED with NaN until index t-1.
"""