Skip to main content

Simulate realistic financial markets from historical price data

Project description

🔥 pathforge

Simulate realistic financial markets from historical price data — for strategy testing, research, and risk analysis.

PyPI version License: MIT Python 3.9+

Why pathforge?

Testing a trading strategy on a single historical price series tells you how it performed on one specific path the market happened to take. That's not enough. A robust strategy should work across the full range of outcomes the market could have produced.

pathforge learns the statistical behaviour of any asset from its historical prices and generates hundreds of realistic alternative price paths. Test your strategy across all of them and you'll know how robust it really is.

Installation

pip install pathforge

To use the built-in plot functionality:

pip install pathforge[examples]

Quick Start

import pathforge as pf
import yfinance as yf

# Download historical price data
ticker = yf.Ticker("AAPL")
prices = ticker.history(period="5y")["Close"]

# Create a forge and fit a model
forge = pf.PathForge(prices)
forge.fit(model="garch")

# Simulate one year of trading days across 100 paths
sim = forge.simulate(days=252, n_paths=100, seed=42)

# Explore the results
sim.summary()
sim.plot()

# Get the paths as a DataFrame for your own analysis
df = sim.to_dataframe()  # shape: (253, 100)

Models

Model model= Best for
Geometric Brownian Motion "gbm" Fast baseline, simple assumptions
GARCH(1,1) "garch" Realistic volatility clustering
Block Bootstrap "bootstrap" Non-parametric, no distributional assumptions
Merton Jump Diffusion "jump_diffusion" Capturing sudden crashes and spikes

Which model should I use?

  • GBM — good sanity check, fast, but underestimates tail risk
  • GARCH — best for most use cases, captures the volatility clustering seen in real markets
  • Bootstrap — most honest for strategy testing, resamples real historical behaviour directly
  • Jump Diffusion — best when your data contains sudden large moves you want to preserve

API Reference

PathForge(data)

The main class. Pass a pd.Series or pd.DataFrame of daily closing prices.

Method Description
.fit(model="garch") Fit a simulation model to the historical data
.simulate(days=252, n_paths=100, start_price=None, seed=None) Generate simulated price paths

SimulationResult

Returned by .simulate().

Attribute / Method Description
.paths np.ndarray of shape (days+1, n_paths)
.to_dataframe() Paths as a pd.DataFrame, one column per path
.summary() Print statistical summary of the simulation
.plot(max_paths=50) Plot simulated paths with historical context

Roadmap

  • Poisson jump diffusion ✅
  • Intraday timeframes (1m, 5m, 15m, 1h)
  • Multi-asset correlated simulation
  • Regime switching model
  • CLI: pathforge simulate AAPL --days 252 --paths 500

Contributing

PRs and issues welcome at github.com/franmanz/pathforge.

License

MIT © 2026 franmanz

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

pathforge-0.1.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

pathforge-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pathforge-0.1.1.tar.gz.

File metadata

  • Download URL: pathforge-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pathforge-0.1.1.tar.gz
Algorithm Hash digest
SHA256 73ed07f8fb2df88c09bc7b2eae49cf2438d26e51e1e7331eb1e716a7e6749a4b
MD5 494d1eb429d35493b5d094c798a247ea
BLAKE2b-256 958034c95905ea66533079867292d29d415a5af4ad30e86857436dc106082f3a

See more details on using hashes here.

File details

Details for the file pathforge-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pathforge-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pathforge-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a5ec0e49f7b8fea9e5e5f693f15f04577a97394f48d54ced5ffd33d380b8463f
MD5 808739745a3dc5048ee7b6aada93ffe9
BLAKE2b-256 cba828748080a9dd238ffeecf6da8785a4dbbfb93a3be082ab994307238b5f71

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