All use cases

Financial computing

Monte Carlo simulations, risk models, and pricing with a rewrite-optional path.

Quantitative finance runs on Python. Pricing models, risk calculations, Monte Carlo simulations, backtesting engines -- all written in Python, all CPU-bound, all slow.

The industry workaround is rewriting hotspots in C++ or moving to proprietary platforms. Epochly offers a different path: keep your Python code, accelerate the bottlenecks.


Where Financial Computing Time Goes

WorkloadTypical BottleneckEpochly Level
Monte Carlo simulationNested numerical loopsLevel 2 JIT (58-193x)
Portfolio risk (VaR)Matrix operations + loopsLevel 2 + Level 4
Option pricing (Black-Scholes)Numerical computationLevel 2 JIT
Backtesting engineSequential iterationLevel 3 Parallel (8-12x)
Time series analysisSliding window loopsLevel 2 JIT

Most financial computing bottlenecks are pure Python loops with numerical operations -- the ideal target for JIT compilation.


Monte Carlo Simulations

Monte Carlo pricing models run millions of path simulations. Each path involves numerical iteration.

import epochly
import numpy as np
@epochly.optimize
def monte_carlo_option_price(S0, K, r, sigma, T, num_paths=1_000_000):
"""European call option pricing via Monte Carlo."""
dt = T / 252 # Daily steps
num_steps = int(T * 252)
payoffs = np.zeros(num_paths)
for i in range(num_paths):
S = S0
for t in range(num_steps):
z = np.random.standard_normal()
S = S * np.exp((r - 0.5 * sigma**2) * dt + sigma * np.sqrt(dt) * z)
payoffs[i] = max(S - K, 0)
return np.exp(-r * T) * np.mean(payoffs)

The nested loop above iterates num_paths * num_steps times. With 1M paths and 252 steps, that's 252 million iterations of interpreted Python.

Level 2 JIT compiles this to native code: 58-193x speedup (113x average on numerical loops). On our benchmark hardware, a 1M-path simulation dropped from minutes to seconds.

Parallel Monte Carlo

When paths are independent (they usually are), Level 3 distributes them across cores.

@epochly.optimize
def parallel_monte_carlo(S0, K, r, sigma, T, num_paths=10_000_000):
"""Parallel Monte Carlo with automatic work distribution."""
# Epochly automatically distributes independent paths across cores
# Combined with JIT: 113x (JIT) * 8-12x (parallel) = up to ~1,350x
pass

Combined JIT + parallel: ~1,350x theoretical maximum on 16 cores. Your mileage depends on path independence and numerical density of the inner loop.


Risk Calculations

Value at Risk (VaR) and Expected Shortfall (ES) calculations involve repeated portfolio evaluation under different scenarios.

import epochly
import numpy as np
@epochly.optimize
def compute_var(portfolio_values, confidence=0.99):
"""Historical VaR calculation with custom rolling computation."""
n = len(portfolio_values)
returns = np.zeros(n - 1)
for i in range(1, n):
returns[i-1] = (portfolio_values[i] - portfolio_values[i-1]) / portfolio_values[i-1]
sorted_returns = np.sort(returns)
var_index = int((1 - confidence) * len(sorted_returns))
return -sorted_returns[var_index]

The loop computing returns is a JIT target. For large portfolios with millions of historical data points, GPU acceleration (Level 4) on the sort and array operations adds further speedup: up to 70x on 10M+ element arrays.


Backtesting Engines

Backtesting iterates through historical data sequentially. While individual ticks are sequential, evaluating multiple strategies or parameter sets is parallelizable.

import epochly
@epochly.optimize
def backtest_strategies(strategies, historical_data):
"""Evaluate multiple trading strategies in parallel."""
results = []
for strategy in strategies:
pnl = 0.0
position = 0
for tick in historical_data:
signal = strategy.evaluate(tick)
if signal > 0 and position == 0:
position = 1
entry_price = tick['price']
elif signal < 0 and position == 1:
position = 0
pnl += tick['price'] - entry_price
results.append(pnl)
return results

Level 3 parallel execution distributes strategy evaluations across cores: 8-12x on 16 cores. If the inner loop is numerical, Level 2 JIT adds another 58-193x.


What Epochly Does NOT Help in Finance

  • Database queries: Portfolio data fetches are I/O-bound. ~1.0x.
  • Already vectorized NumPy: If your risk model is purely np.matmul and np.linalg, BLAS already optimizes it. ~1.0x.
  • Real-time tick processing: If latency requirements are sub-millisecond, Epochly's process spawn overhead (~200ms) disqualifies Level 3. Use Level 2 JIT instead.
  • Small calculations: Pricing a single option takes microseconds. Overhead exceeds benefit.

Getting Started

pip install epochly
import epochly
@epochly.optimize
def your_pricing_model(params):
# Your existing pricing code
pass
@epochly.optimize
def your_risk_calculation(portfolio):
# Your existing risk code
pass

Start with Level 0 monitoring on your most expensive functions. Epochly identifies the bottleneck type and graduates to the appropriate optimization level.


Benchmark conditions: Python 3.12.3, Linux WSL2, 16 cores, NVIDIA Quadro M6000 24GB (CUDA 12.1). January 29, 2026 comprehensive benchmark report.

pythonfinancequantitativemonte-carlorisktrading