Skip to main content

A comprehensive visualization package for risk analysis with ridge plots, heatmaps, waterfall charts, and time series tools

Project description

RiskPlot

PyPI version Tests Documentation Coverage License: MIT

A comprehensive Python package for risk analysis visualization, featuring ridge plots, heatmaps, waterfall charts, network diagrams, globe visualizations, and surface plots.

🚀 Features

Core Visualizations

  • Ridge Plots: Distribution comparisons across categories
  • Heatmaps: Correlation matrices and risk matrices
  • Waterfall Charts: Risk attribution and P&L decomposition
  • Time Series: VaR tracking and drawdown analysis

Advanced Visualizations ✨

  • Network Plots: Entity relationship networks (requires networkx)
  • Globe Visualizations: Interactive geographic risk mapping (requires plotly)
  • Surface Plots: 2D/3D risk landscapes (requires plotly, scipy)

🎯 Use Cases

  • Financial Risk Management: Portfolio analysis, VaR calculations, stress testing
  • Country Risk Analysis: Geographic risk assessment and monitoring
  • Network Analysis: Financial interconnectedness, trade relationships
  • Regulatory Reporting: Risk visualization for compliance and reporting

📦 Installation

Basic Installation

pip install riskplot

With Optional Dependencies

# For network visualizations
pip install riskplot[network]

# For globe visualizations
pip install riskplot[globe]

# For all features
pip install riskplot[all]

⚡ Quick Start

import riskplot
import pandas as pd
import numpy as np

# Create sample data
data = pd.DataFrame({
    'category': ['Portfolio A', 'Portfolio B', 'Portfolio C'],
    'returns': [np.random.normal(0.05, 0.1, 100),
                np.random.normal(0.03, 0.08, 100),
                np.random.normal(0.07, 0.15, 100)]
})

# Ridge plot
fig, ax = riskplot.ridge_plot(data, 'category', 'returns')

# Correlation heatmap
correlation_matrix = pd.DataFrame(np.random.rand(5, 5))
fig, ax = riskplot.correlation_heatmap(correlation_matrix)

# Network visualization (requires networkx)
network_data = pd.DataFrame({
    'source': ['A', 'B', 'C'],
    'target': ['B', 'C', 'A'],
    'weight': [0.8, 1.2, 0.5]
})
fig, ax = riskplot.country_interaction_network(network_data)

# Interactive globe (requires plotly)
country_data = pd.DataFrame({
    'country': ['USA', 'CHN', 'GBR'],
    'risk_score': [0.3, 0.7, 0.4]
})
fig = riskplot.country_risk_globe(country_data)
fig.show()

Chart Types

Ridge Plots

# Basic ridge plot
rp.ridge_plot(data, 'category', 'value')

# Dual group comparison
rp.ridge_plot(data, 'category', 'value', 'group')

Heatmaps

# Correlation matrix
rp.correlation_heatmap(data)

# Risk matrix
rp.risk_matrix(data, 'probability', 'impact', 'label')

# Exposure heatmap
rp.exposure_heatmap(data, 'entity', 'sector', 'exposure')

Waterfall Charts

# Risk attribution
rp.risk_attribution_waterfall(data, 'factor', 'contribution')

# P&L waterfall
rp.pnl_waterfall(data, 'component', 'amount')

# VaR decomposition
rp.var_decomposition(data, 'component', 'var_contribution')

Distribution Plots

# Violin plots
violin = rp.ViolinPlot()
fig, ax = violin.plot(data, 'category', 'value')

# Distribution summary
rp.risk_distribution_summary(data, 'returns')

Time Series

# Rolling risk metrics
rp.rolling_risk_metrics(data, 'date', 'returns')

# Drawdown analysis
drawdown = rp.DrawdownChart()
fig, axes = drawdown.plot(data, 'date', 'value', show_underwater=True)

Advanced Usage

Custom Configuration

config = rp.PlotConfig(
    figsize=(12, 8),
    colormap='plasma',
    style='seaborn'
)

# Use with any visualization class
heatmap = rp.RiskHeatmap(config=config)

Extending the Framework

class CustomRiskPlot(rp.RiskVisualization):
    def plot(self, data, **kwargs):
        fig, ax = self._setup_figure(**kwargs)
        # Your custom plotting logic
        return fig, ax

Examples

  • examples/basic_usage.py - Basic functionality demonstration
  • examples/recreate_original.py - Recreates original ridge plot example
  • examples/comprehensive_demo.py - Complete feature showcase

📚 Documentation

🧪 Dependencies

Core Dependencies

  • matplotlib >= 3.5.0
  • pandas >= 1.3.0
  • numpy >= 1.20.0
  • scipy >= 1.7.0

Optional Dependencies

  • networkx >= 2.6.0 (for network visualizations)
  • plotly >= 5.0.0 (for globe and interactive surface plots)

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Links


Made with ❤️ for the risk management community

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

riskplot-0.2.0.tar.gz (4.3 MB view details)

Uploaded Source

Built Distribution

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

riskplot-0.2.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file riskplot-0.2.0.tar.gz.

File metadata

  • Download URL: riskplot-0.2.0.tar.gz
  • Upload date:
  • Size: 4.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for riskplot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 270bafbec370336584d8656c543d8790a2683b409ac9fdac2b9baab6bacc1910
MD5 2f92238e79cb9a58b84de52c98a60b87
BLAKE2b-256 dcad3cbf946aab07b1b72a456f438ded4bf941b1e943a05aab5ba04149454548

See more details on using hashes here.

Provenance

The following attestation bundles were made for riskplot-0.2.0.tar.gz:

Publisher: publish-to-pypi.yml on OwenDinsmore/riskplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file riskplot-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: riskplot-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for riskplot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f719c94ff9af2ddda38da3912edadc1c87bb925fd8012ea94349f28d9b8ec36a
MD5 03c8888f02ecb031a7123d1ef0ee55f1
BLAKE2b-256 95619105ec5f01cd9585baf96ebfcfe78fa5f1a46e511312e86c980d8144870a

See more details on using hashes here.

Provenance

The following attestation bundles were made for riskplot-0.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on OwenDinsmore/riskplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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