Skip to main content

Readable financial contagion library from market data to portfolio analytics

Project description

fincontagion

fincontagion is a Python library for financial contagion analysis, from market data preparation to network-aware portfolio analytics.

It provides:

  • price download and cleaning utilities
  • infection-state construction using volatility and SIR-like states
  • tail-dependence estimation and multiplex network construction
  • crisis-window parameter estimation and Monte Carlo simulation
  • contagion-aware portfolio rebalancing and performance summaries
  • optional Plotly visualizations

Installation

Install the core package:

pip install fincontagion

Install with optional extras:

pip install "fincontagion[full]"
  • full includes: networkx, cvxpy, plotly
  • dev includes: pytest

Quick Start

import fincontagion as fc

universe = {
    "AAPL": {"region": "USA", "sector": "Technology"},
    "MSFT": {"region": "USA", "sector": "Technology"},
    "JPM": {"region": "USA", "sector": "Finance"},
}

config = fc.PipelineConfig(
    tickers=list(universe.keys()),
    start="2020-01-01",
    end="2024-12-31",
    crises={"COVID_2020": ("2020-02-20", "2020-05-31")},
    universe=universe,
)

result = fc.run_full_pipeline(config)
print(result["portfolio"]["summary"])

Main API

  • run_full_pipeline, PipelineConfig
  • prepare_market_data, prices_to_log_returns
  • compute_infection_states
  • compute_tail_dependence
  • build_network_layers
  • estimate_parameters, simulate_sir, predict_crises
  • rebalance_portfolio

Visualization helpers:

  • plot_infection_timeline
  • plot_region_infection_heatmap
  • plot_sector_infection_breakdown
  • plot_tail_dependence_heatmap
  • plot_firm_network
  • plot_portfolio_performance
  • plot_portfolio_weights

Development

Run tests:

pytest -q

License

MIT License.

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

fincontagion-0.2.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

fincontagion-0.2.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fincontagion-0.2.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for fincontagion-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5c2257b604f4ee357b85c1394c8de0871f22cd180043841cef66a59881930e07
MD5 3760c80fdc092ac75701970a1d3c575c
BLAKE2b-256 100a940aa05fa136783153f415ffc8053c847e00037caa3a9e555612aa115db2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fincontagion-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for fincontagion-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efedee7c3b1f470a45f6e63dd09c23a01952793d56ea196cdd7ae4f0da4df2b5
MD5 e4c207075e60b1e24b30c08a510f7491
BLAKE2b-256 2802a9604945dc0beab6acce0592c26501b83ba3d30475d85d2e8eb8bfb83b9a

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