VaRpy - Value at Risk Models
A Python library for computing Value at Risk (VaR) and Conditional Value at Risk (CVaR) using various statistical distributions and GARCH models.
Download
pip install varpy
Recent Refactoring
The codebase has undergone a major refactoring to improve code organization, maintainability, and consistency. Here are the key changes:
1. Standardized Model Structure
Each VaR model (Normal, Student's t, EVT) follows the same pattern:
- Constructor takes only
thetaandhorizonparameters runmethod accepts returns data as input- Private helper methods for specific computations
- Consistent method naming and documentation
Example structure:
class SomeVar(BaseVar):
def __init__(self, theta: float, horizon: int):
super().__init__(theta, horizon)
def run(self, ret: NDArray[np.float64]) -> None:
# 1. Get GARCH forecasts
# 2. Process innovations
# 3. Fit distribution
# 4. Compute VaR/CVaR
pass
3. Improved Type Hints
- Added comprehensive type hints using
numpy.typing - Consistent use of
NDArray[np.float64]for numpy arrays - Proper return type annotations for all methods
5. Enhanced Documentation
- Comprehensive docstrings for all classes and methods
- Clear parameter and return type documentation
- Consistent documentation style across all models
6. Code Organization
- Moved models to
varpy/var/models/directory - Consistent file naming (lowercase with underscores)
- Clear separation of concerns between models
Available Models
Normal Distribution
- Assumes returns follow a normal distribution
- Uses GARCH(1,1) with Gaussian innovations
- Suitable for well-behaved financial returns
Student's t Distribution
- Assumes returns follow a Student's t distribution
- Uses GARCH(1,1) with Student's t innovations
- Better suited for heavy-tailed returns
Extreme Value Theory (EVT)
- Uses Generalized Pareto Distribution for tail modeling
- Combines GARCH with EVT for better tail estimation
- Most suitable for extreme risk measurement
Usage Example
import numpy as np
from varpy.var.models import Normal, Student, EVT
# Initialize model
model = Normal(theta=0.05, horizon=1)
# Compute VaR and CVaR
returns = np.array([...]) # Your return data
model.run(returns)
# Get results
var = model.var
cvar = model.cvar
More exemples here
Dependencies
- numpy
- scipy
- arch (for GARCH modeling)
Contributing
When adding new VaR models, please follow the established pattern:
- Inherit from
BaseVar - Implement the
runmethod - Use private helper methods for specific computations
- Add comprehensive type hints and documentation
- Follow the modular design pattern
Metadata
Release files for varpy 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| varpy-2.0.1.tar.gz | 84.0 kB | Without provenance | Details for varpy-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| varpy-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for varpy-2.0.1-py3-none-any.whl |
Total release size: 168.2 kB
Release files / varpy-2.0.1.tar.gz
| Download URL | varpy-2.0.1.tar.gz |
|---|---|
| Size | 84.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
254779b32dda803d84ebb48c5c47ee37c225f13086bf861fad1d59f7df29117c
|
|
BLAKE2b-256 checksum How to use checksums |
ed923cc9fe37ce5f7efda2bdd3fd3e585436c943043851cbf23bf0ca388d0b41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.2
|
Release files / varpy-2.0.1-py3-none-any.whl
| Download URL | varpy-2.0.1-py3-none-any.whl |
|---|---|
| Size | 84.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c2736bef959f0f7806443bd1e0519e17875f341cfeab922b2f22412629df315
|
|
BLAKE2b-256 checksum How to use checksums |
b6c65845b15e79267cc593051b20d92aa856d85000c4f48b53b44929a575d4fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.2
|
Security for varpy 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.