Fast drawdown & CED metrics in Rust with NumPy bindings.
ddstats provides high-performance financial metrics, including drawdown and Conditional Expected Drawdown (CED), implemented in Rust and exposed to Python via NumPy bindings. This allows for fast computations directly from Python, leveraging Rust's speed and safety.
- Drawdown metrics: Compute maximum drawdown and related statistics.
- CED (Conditional Expected Drawdown): Efficient calculation for risk analysis.
- NumPy integration: Seamless usage from Python with NumPy arrays.
- Cross-platform: Works on Windows, macOS, and Linux.
You can install ddstats using pip:
pip install ddstatsOr build from source:
git clone https://github.com/integerQuant/ddstats.git
cd ddstats
pip install maturin
maturin developimport numpy as np
import ddstats
x = np.array([0.01, -0.02, 0.03], dtype=float)
max_dd = ddstats.max_drawdown(x)
print("Max Drawdown:", max_dd)Computes the maximum drawdown of a time series.
- x: 1D NumPy array of floats.
Computes the Conditional Expected Drawdown at a given confidence level.
- x: 1D NumPy array of floats.
- t: Rolling drawdown distribution window size.
- alpha: Confidence level (between 0 and 1).
- Any
NaNin inputs yieldsNaNin the corresponding output. - Empty inputs return
NaN. - Rolling windows honor
min_windowwarm-up andstepstride.
python -m pip install maturin pytest
maturin develop
pytest
cargo testThis project uses maturin for building Python bindings:
maturin buildMIT License. See LICENSE.
Inspired by the work of Lisa R. Goldberg and Ola Mahmoud, Drawdown: From Practice to Theory and Back Again. arXiv:1404.7493