Lightweight, parallel, and reproducible Monte Carlo simulation framework
Project description
mcframework
Lightweight, reproducible, and deterministic Monte Carlo simulation framework with statistically robust analytics and parallel execution.
📚 Documentation
The documentation includes:
- Getting Started — Installation and quick examples
- API Reference — Complete module documentation with type hints
- System Design — Architecture diagrams, UML, and design patterns
- Project Plan — Requirements, stakeholders, and methodology
Installation
From Source (Development)
git clone https://github.com/milanfusco/mcframework.git
cd mcframework
pip install -e .
Dependencies
| Package | Version | Purpose |
|---|---|---|
| Python | ≥ 3.10 | Runtime |
| NumPy | ≥ 1.24 | Arrays, RNG |
| SciPy | ≥ 1.10 | Statistics |
| Matplotlib | ≥ 3.7 | Visualization |
Optional Dependencies
# All extras
pip install -e ".[dev,test,docs,gui]"
# Individual extras
pip install -e ".[dev]" # Linting (ruff, pylint)
pip install -e ".[test]" # Testing (pytest, coverage)
pip install -e ".[docs]" # Documentation (Sphinx, themes)
pip install -e ".[gui]" # GUI application (PySide6)
Features
Core Framework
- Abstract base class (
MonteCarloSimulation) — Define simulations by implementingsingle_simulation() - Deterministic parallelism — Reproducible results via NumPy
SeedSequencespawning - Cross-platform execution — Threads on POSIX, processes on Windows
- Structured results —
SimulationResultdataclass with metadata and formatting
Statistics Engine
- Descriptive statistics — Mean, std, percentiles, skew, kurtosis
- Parametric CI — z/t critical values with auto-selection
- Bootstrap CI — Percentile and BCa methods
- Distribution-free bounds — Chebyshev intervals, Markov probability
Built-in Simulations
- Pi Estimation — Geometric probability on unit disk
- Portfolio Simulation — GBM wealth dynamics
- Black-Scholes — European/American option pricing with Greeks
Quick Start
from mcframework import MonteCarloFramework, PiEstimationSimulation
sim = PiEstimationSimulation()
sim.set_seed(123)
fw = MonteCarloFramework()
fw.register_simulation(sim)
result = fw.run_simulation("Pi Estimation", 10_000, n_points=5000, parallel=True)
print(result.result_to_string())
Defining a Custom Simulation
from mcframework import MonteCarloSimulation
class DiceSumSimulation(MonteCarloSimulation):
def __init__(self):
super().__init__("Dice Sum")
def single_simulation(self, _rng=None, n_dice: int = 5) -> float:
rng = self._rng(_rng, self.rng)
return float(rng.integers(1, 7, size=n_dice).sum())
sim = DiceSumSimulation()
sim.set_seed(42)
result = sim.run(10_000, parallel=True)
print(f"Mean: {result.mean:.2f}") # ~17.5
Extended Statistics
result = sim.run(
50_000,
percentiles=(1, 5, 50, 95, 99),
confidence=0.99,
ci_method="auto",
)
print(result.stats["ci_mean"]) # 99% confidence interval
Package Structure
mcframework/
├── __init__.py # Public API exports
├── core.py # MonteCarloSimulation, SimulationResult, MonteCarloFramework
├── stats_engine.py # StatsEngine, StatsContext, ComputeResult, metrics
├── utils.py # z_crit, t_crit, autocrit
└── sims/
├── __init__.py # Simulation catalog
├── pi.py # PiEstimationSimulation
├── portfolio.py # PortfolioSimulation
└── black_scholes.py # BlackScholesSimulation, BlackScholesPathSimulation
GUI Application
The framework includes a PySide6 GUI for Black-Scholes Monte Carlo simulations:
pip install -e ".[gui]"
python demos/gui/quant_black_scholes.py
Features:
- Live stock data from Yahoo Finance
- Monte Carlo path simulations
- Option pricing with Greeks (Δ, Γ, ν, Θ, ρ)
- Interactive what-if analysis
- 3D option price surfaces
- HTML report export
Scenario Presets: High volatility (TSLA), Index ETFs (SPY), Crypto-adjacent (COIN), Dividend stocks (JNJ)
Cross-Platform Parallel Execution
MonteCarloSimulation.run(..., parallel=True) automatically selects the optimal backend:
| Platform | Default Backend | Reason |
|---|---|---|
| POSIX (Linux, macOS) | ThreadPoolExecutor |
NumPy releases GIL |
| Windows | ProcessPoolExecutor |
Avoids GIL serialization |
Override explicitly with parallel_backend="thread" or parallel_backend="process".
Development
Testing
# Run tests with coverage
pytest --cov=mcframework -v
# Generate coverage reports
pytest --cov=mcframework --cov-report=xml:coverage.xml # XML
pytest --cov=mcframework --cov-report=html # HTML
Linting
ruff check src/
pylint src/mcframework/
Documentation
# Install docs dependencies
pip install -e ".[docs]"
# Build HTML documentation
sphinx-build -b html docs/source docs/_build/html
# Serve locally
python -m http.server 8000 -d docs/_build/html
The documentation uses:
- Sphinx with pydata-sphinx-theme
- Mermaid for interactive diagrams
- NumPy-style docstrings with LaTeX math
- Light/dark theme toggle with diagram re-rendering
License
MIT License. See LICENSE file.
Authors
- Milan Fusco — mdfusco@student.ysu.edu
- James Gabbert — jdgabbert@student.ysu.edu
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcframework-0.1.0.tar.gz.
File metadata
- Download URL: mcframework-0.1.0.tar.gz
- Upload date:
- Size: 56.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88f50b35e2781384d4f1b31272af3a08af5b8b68a980896a7eb9e00671d2a623
|
|
| MD5 |
8c89d52fece03cc5d52126d6d7a33ed4
|
|
| BLAKE2b-256 |
3d29a7deffd3a23f010704852c4d749ffc9191b89362a975d55b8db05d541e7c
|
Provenance
The following attestation bundles were made for mcframework-0.1.0.tar.gz:
Publisher:
publish.yml on milanfusco/mcFramework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcframework-0.1.0.tar.gz -
Subject digest:
88f50b35e2781384d4f1b31272af3a08af5b8b68a980896a7eb9e00671d2a623 - Sigstore transparency entry: 744139959
- Sigstore integration time:
-
Permalink:
milanfusco/mcFramework@0fdc17855cd3b9cbc7d3f9d194bba73825e38277 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/milanfusco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0fdc17855cd3b9cbc7d3f9d194bba73825e38277 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mcframework-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcframework-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81401780177af77095ed0e1e97fb1e42c52dbb021fd6eac602564adb753b3aec
|
|
| MD5 |
e512677d57f07af9b5a20df2f7166cde
|
|
| BLAKE2b-256 |
bae54fbb45d20bfa9f569e51f16d725cbf62b09eacc9f51532e2a296ab8c2173
|
Provenance
The following attestation bundles were made for mcframework-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on milanfusco/mcFramework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcframework-0.1.0-py3-none-any.whl -
Subject digest:
81401780177af77095ed0e1e97fb1e42c52dbb021fd6eac602564adb753b3aec - Sigstore transparency entry: 744139968
- Sigstore integration time:
-
Permalink:
milanfusco/mcFramework@0fdc17855cd3b9cbc7d3f9d194bba73825e38277 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/milanfusco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0fdc17855cd3b9cbc7d3f9d194bba73825e38277 -
Trigger Event:
workflow_dispatch
-
Statement type: