A GPU-accelerated Monte Carlo simulation library for quantitative finance using PyTorch. finsimtorch provides efficient implementations of well-known stochastic models like GJR-GARCH, Rough Heston, and Rough Bergomi.
- GPU Acceleration: Leverages PyTorch for efficient GPU-based computations
- Modern Stochastic Models: Implementation of cutting-edge financial models
- Easy to Use: Clean, intuitive API for Monte Carlo simulation
- Well Tested: Comprehensive test suite and documentation
pip install finsimtorchpip install finsimtorch[examples]git clone https://github.com/simu-ai/finsimtorch.git
cd finsimtorch
pip install -e .import torch
from finsimtorch import GjrGarch
# Auto-detect best available device
if torch.cuda.is_available():
device = 'cuda'
elif hasattr(torch.backends, 'mps') and torch.backends.mps.is_available():
device = 'mps' # MacBook GPU
else:
device = 'cpu'
# Create a GJR-GARCH model (HansenSkewedT created internally)
model = GjrGarch(
mu=0.0, omega=0.1, alpha=0.1, gamma=0.05, beta=0.8,
initial_variance=1.0, device=device
)
# Simulate paths (supports any iterable!)
returns = model.paths(range(1, 21), 1000) # Memory efficient with range()finsimtorch supports multiple compute devices for GPU acceleration:
- CUDA: NVIDIA GPUs (
device='cuda') - MPS: Apple Silicon MacBooks (
device='mps') - CPU: Fallback option (
device='cpu')
The library automatically detects the best available device, prioritizing GPU acceleration when available.
The Glosten-Jagannathan-Runkle GARCH model with asymmetric volatility:
from finsimtorch import GjrGarch
model = GjrGarch(
mu=0.0, # Mean return
omega=0.1, # Variance intercept
alpha=0.1, # ARCH coefficient
gamma=0.05, # Asymmetry coefficient
beta=0.8, # GARCH coefficient
initial_variance=1.0, # Initial variance
device='cuda' # PyTorch device: 'cuda', 'mps' (MacBook), or 'cpu'
)
# Simulate 1000 paths (supports range, list, tuple, numpy arrays, etc.)
returns = model.paths(range(1, 51), 1000)For rough volatility models:
from finsimtorch import FractionalBrownianMotion
import numpy as np
# Create fBM with Hurst parameter H = 0.1 (rough volatility)
fbm = FractionalBrownianMotion(hurst=0.1, device='cuda')
# Generate time points
time_points = np.linspace(0, 1, 100)
# Generate 1000 fBM paths
fbm._reset(1000)
paths = fbm.paths(time_points)Full documentation is available at finsimtorch.readthedocs.io.
Check out the examples directory for Jupyter notebooks demonstrating various use cases.
git clone https://github.com/simu-ai/finsimtorch.git
cd finsimtorch
poetry install --with dev
pre-commit installpoetry run pytestcd docs
make htmlWe welcome contributions! Please see our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use finsimtorch in your research, please cite:
@software{finsimtorch,
title={finsimtorch: GPU-accelerated Monte Carlo simulation for quantitative finance},
author={simu.ai},
year={2024},
url={https://github.com/simu-ai/finsimtorch}
}For questions and support, please open an issue on GitHub.