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 is inspired by and extends the framework proposed in:

Bozhidarova, Ball, van Gennip, O'Dea & Stupfler (2024). Describing financial crisis propagation through epidemic modelling on multiplex networks. Proc. R. Soc. A 480: 20230787. https://doi.org/10.1098/rspa.2023.0787

This library was developed as part of the Computational Finance course (PGDM) at Madras School of Economics, taught by Dr. Parthajit Kayal and Dr. Sumanjay Datta, by students Arjun Balakrishnan, Sriharinandan Raghuraman, and Yogesh Verma — who extended the original theoretical framework into a practical, deployable Python library.

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

Credits & Acknowledgements

This library builds directly on the theoretical framework of Bozhidarova et al. (2024), and full credit is due to the original authors for their pioneering work on SIR-based financial contagion modelling on multiplex networks.

The library was built and extended by:

  • Arjun Balakrishnan
  • Sriharinandan Raghuraman
  • Yogesh Verma

under the guidance of:

  • Dr. Parthajit Kayal (Madras School of Economics)
  • Dr. Sumanjay Datta (Madras School of Economics)

as part of the Computational Finance course, where the original model was extended into an agentic AI-driven financial decision platform — combining agent-based contagion dynamics, adaptive decision-making, portfolio optimization under systemic risk, and emergent market simulation.

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.1.tar.gz (18.3 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.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fincontagion-0.2.1.tar.gz
  • Upload date:
  • Size: 18.3 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.1.tar.gz
Algorithm Hash digest
SHA256 00fe9ca57af2650ccdfa5d25e49c62768ca1db2bcd42c40ba1c3d430028d2d56
MD5 ea86e125ce2ade00b4ec4d2af867f125
BLAKE2b-256 2f05578ae90a5127dfd02ff957c7e9bc0ba5dc51ef3bf990637d7a98e8719425

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fincontagion-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a295e2490dc55ebf4611e4916a943fc5859a1e6eb394dc0056c6bb4ca2c3944b
MD5 4ba582288025473c8fdf7dae966257ba
BLAKE2b-256 49636e96a706981e34abeb5790154fbf9e458a6241606a441bbf605808e3aa07

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