Risk Metrics library for financial analysis
Project description
pyAdverse
pyadverse is a Python library for calculating various financial risk metrics from return data.
Installation
Install the package from PyPI:
pip install pyadverse
Example Usage
import numpy as np
from pyadverse import RiskMetrics
# Sample daily return data
returns = np.array([0.01, -0.02, 0.03, -0.01, 0.015, -0.005, 0.007, -0.03])
# Create the RiskMetrics object
risk = RiskMetrics(returns)
print("VaR (95%):", risk.value_at_risk(0.95)) # alpha = 0.95
print("CVaR (95%):", risk.conditional_var(0.95)) # alpha = 0.95
print("Max Drawdown:", risk.max_drawdown()) # no parameters
print("Expected Drawdown (0.01):", risk.expected_drawdown(0.01)) # threshold = 0.01
print("Conditional Drawdown (95%):", risk.conditional_drawdown(0.95)) # alpha = 0.95
print("Lower Partial Moment (threshold=0.0, order=2):", risk.lower_partial_moment(0.0, 2)) # threshold = 0.0, order = 2
print("Variance:", risk.variance()) # no parameters
print("Standard Deviation:", risk.std_deviation()) # no parameters
print("Skewness:", risk.skewness()) # no parameters
print("Kurtosis:", risk.kurtosis()) # no parameters
print("Volatility (annualized):", risk.volatility()) # assumes 252 trading days
Risk Metrics Descriptions
-
Value at Risk (VaR): Estimates the maximum potential loss at a given confidence level (e.g., 95%).
-
Conditional Value at Risk (CVaR): Measures the expected loss given that the loss is beyond the VaR threshold.
-
Max Drawdown: The maximum observed loss from a peak to a trough before a new peak is attained.
-
Expected Drawdown: The average drawdown that exceeds a user-defined threshold.
-
Conditional Drawdown (CDaR): The average of the worst-case drawdowns, defined by a confidence percentile.
-
Lower Partial Moment (LPM): Measures downside risk. The higher the order, the more sensitive to extreme losses.
-
Variance: The average squared deviation from the mean return; basic risk indicator.
-
Standard Deviation: Square root of the variance; common measure of return volatility.
-
Skewness: Measures asymmetry of the return distribution. Negative skew indicates more left tail risk.
-
Kurtosis: Measures "tailedness" of the return distribution. Higher values mean more outlier-prone.
-
Volatility: Annualized standard deviation of returns (assuming 252 trading days).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyadverse-0.0.3.tar.gz.
File metadata
- Download URL: pyadverse-0.0.3.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2649181f0fd33cd3223e6a23a0c9e6a16ab0b91de7f4c22ba6de57dc0a455ea9
|
|
| MD5 |
acf03146c60513f6316be0f02d9b075d
|
|
| BLAKE2b-256 |
4e1b9e17a3dd68473cbec27936a1163828d45af3c66bfdedbe548428531d982a
|
File details
Details for the file pyadverse-0.0.3-py3-none-any.whl.
File metadata
- Download URL: pyadverse-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbfda21d384b24c56eb78928301e0e6353d0b30fc61d872b6fb946e64c919673
|
|
| MD5 |
35aba9f0039242dc4f15bdc52569325d
|
|
| BLAKE2b-256 |
32360669af4da33d1fcb773efc427cc71ed0aec5e33ad38973f0ed9fc682789b
|