Common financial return and risk metrics in Python.
Maintenance and new projects
We continue to maintain Empyrical Reloaded for bug, security, and compatibility fixes.
Our new feature development focuses on ML4T Diagnostic,
part of the ML4T libraries.
For new projects, start with Diagnostic's maintained
Empyrical migration guide
and published documentation.
Check each recipe's package and release requirements before using APIs documented in source.
Keep annualization, periodic versus annual rates, missing-value policies and return/loss signs
explicit; similarly named metrics need not have equivalent behavior.
The historical ten-metric comparison,
and
retain earlier tested versions and findings. They do not describe current successor coverage
or establish complete replacement of Empyrical.
Empyrical Reloaded supports Python 3.11 through 3.15. Python 3.9 and 3.10 are retired
for this release; historical packages retain their original Python requirements.
You can install it using pip:
pip install empyrical-reloaded
or conda from the conda-forge channel
conda install empyrical-reloaded -c conda-forge
The installer provides NumPy, pandas, SciPy and the other declared runtime dependencies.
Note that Numpy>=2.0 requires pandas>=2.2.2. If you are using an older version of pandas, you may need to upgrade
accordingly, otherwise you may encounter compatibility issues.
Empyrical computes basic metrics from returns and volatility to alpha and beta, Value at Risk, and Sharpe or Sortino
ratios.
import numpy as np
from empyrical import max_drawdown, alpha_beta
returns = np.array([.01, .02, .03, -.4, -.06, -.02])
benchmark_returns = np.array([.02, .02, .03, -.35, -.05, -.01])
# calculate the max drawdown
max_drawdown(returns)
# calculate alpha and beta
alpha, beta = alpha_beta(returns, benchmark_returns)
Rolling Measures
Empyrical also aggregates return and risk metrics for rolling windows:
import numpy as np
from empyrical import roll_max_drawdown
returns = np.array([.01, .02, .03, -.4, -.06, -.02])
# calculate the rolling max drawdown
roll_max_drawdown(returns, window=3)
Pandas Support
Empyrical also works with both NumPy arrays and Pandas data
structures:
import pandas as pd
from empyrical import roll_up_capture, capture
returns = pd.Series([.01, .02, .03, -.4, -.06, -.02])
factor_returns = pd.Series([.02, .01, .03, -.01, -.02, .02])
# calculate a capture ratio
capture(returns, factor_returns)
-0.147387712263491
Fama-French Risk Factors
Empyrical downloads Fama-French risk factors from 1970 onward:
Requires optional dependency pandas-datareader - see installation instructions above.
Empyrical Reloaded accepts bug, security, and compatibility fixes. Read the
contribution guide
for issue scope, regression evidence, review checks, and AI disclosure requirements.
Testing
install requirements
"pytest>=6.2.0",
pytest tests
Works well with
Use together with empyrical-reloaded: extensions, drivers, servers and companion tools.
ffnPythie’s Index: 91Financial functions for Python85.5K downloads/mo