Skip to main content

Value at Risk tools

Project description

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 theta and horizon parameters
  • run method 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:

  1. Inherit from BaseVar
  2. Implement the run method
  3. Use private helper methods for specific computations
  4. Add comprehensive type hints and documentation
  5. Follow the modular design pattern

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

varpy-2.0.1.tar.gz (84.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

varpy-2.0.1-py3-none-any.whl (84.2 kB view details)

Uploaded Python 3

File details

Details for the file varpy-2.0.1.tar.gz.

File metadata

  • Download URL: varpy-2.0.1.tar.gz
  • Upload date:
  • Size: 84.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.2

File hashes

Hashes for varpy-2.0.1.tar.gz
Algorithm Hash digest
SHA256 254779b32dda803d84ebb48c5c47ee37c225f13086bf861fad1d59f7df29117c
MD5 23cea0e76ff34ff7bea19fc8e60100d0
BLAKE2b-256 ed923cc9fe37ce5f7efda2bdd3fd3e585436c943043851cbf23bf0ca388d0b41

See more details on using hashes here.

File details

Details for the file varpy-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: varpy-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 84.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.2

File hashes

Hashes for varpy-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c2736bef959f0f7806443bd1e0519e17875f341cfeab922b2f22412629df315
MD5 f8f83d8d5f29dd0abed9033f36d3512c
BLAKE2b-256 b6c65845b15e79267cc593051b20d92aa856d85000c4f48b53b44929a575d4fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page