A nimble backtesting and statistics library for options strategies.
Test the trade before the trade tests you. Optopsy runs your option strategies through a full simulator, with exit rules, costs, and Sharpe and CVaR. Pick from 40 built-in strategies, set strikes by delta, and filter entries with 80+ technical indicators.
Full Documentation | API Reference | Examples
🤖 Looking for AI/LLM integration?
optopsy-mcp provides a high-performance MCP server for strategy screening and backtesting. Powered by a complete Rust rewrite of the Optopsy engine, it is specifically built for seamless interaction with Large Language Models.
Features
- 40 Built-in Strategies - From simple calls/puts to iron condors, butterflies, condors, ratio spreads, collars, calendars, and diagonals
- Per-Leg Delta Targeting - Select strikes by delta with
target, min, maxper leg - Trade Simulator - Chronological simulation with capital tracking, position limits, and equity curves via
simulate() - Portfolio Simulation - Weighted multi-strategy portfolio backtesting via
simulate_portfolio() - Early Exits - Stop-loss, take-profit, and max-hold-days rules for automatic position management
- Commissions - Model broker fees with per-contract, per-share, base fee, and min fee structures
- Risk Metrics - Sharpe, Sortino, VaR, CVaR, Calmar, Omega, tail ratio, and more via
compute_risk_metrics() - 80+ Entry Signals - Filter entries with TA indicators (RSI, MACD, Bollinger Bands, EMA, ATR, IV Rank) via pandas-ta-classic
- Custom Signals - Use
custom_signal()to drive entries from any DataFrame with a boolean flag column - Slippage Modeling - Realistic fills with mid, spread, liquidity-based, or per-leg slippage
- Live Data Providers - Fetch options chains and stock prices directly from supported data sources (e.g. EODHD)
- Smart Caching - Automatic local caching of fetched data with gap detection for efficient re-fetches
- Plugin System - Extend with custom strategies, signals, and data providers via entry points
Performance
Optopsy's strategy engine, early-exit scanner, and trade simulator are vectorized with Pandas and NumPy. In synthetic benchmarks (Python 3.12, 2 vCPU), a 40-strategy raw sweep on 1M rows achieved ~1.3M–2.9M rows/sec (with early-exit and 3M-row workloads around ~1.1M–2.6M rows/sec), scaling roughly linearly across the tested sizes with observed peak RSS around ~1.6×–2.1× the input DataFrame size. Actual timings and memory usage depend on hardware, chain density, and strategy parameters (such as exit_dte_tolerance or early exits).
Synthetic chain dimensions tested (all with 10 weekly expirations and both calls/puts):
- 100k rows: 1 symbol × 100 trading days × 50 strikes
- 500k rows: 1 symbol × 250 trading days × 100 strikes
- 1M rows: 2 symbols × 250 trading days × 100 strikes (1M-row 40-strategy sweep used 1 symbol × 500 trading days × 100 strikes)
- 3M rows: 3 symbols × 500 trading days × 100 strikes
| Workload | 100k rows | 500k rows | 1M rows | 3M rows |
|---|---|---|---|---|
short_puts (1-leg, raw) |
61 ms | 187 ms | 351 ms | 1.23 s |
long_call_spread (2-leg, raw) |
83 ms | 225 ms | 411 ms | 1.14 s |
long_call_calendar (cross-exp, raw) |
86 ms | 245 ms | 453 ms | 1.26 s |
iron_condor (4-leg, raw) |
154 ms | 416 ms | 863 ms | 2.37 s |
iron_condor (4-leg, grouped stats) |
197 ms | 443 ms | 761 ms | 2.07 s |
iron_condor + early exits (stop_loss/take_profit) |
257 ms | 568 ms | 966 ms | 2.74 s |
simulate(iron_condor) (full equity curve & risk metrics) |
200 ms | 435 ms | 754 ms | 2.46 s |
signal_dates(iv_rank_above) |
72 ms | 269 ms | 497 ms | 1.48 s |
Observed peak RSS was 361 MB across the 1M-row 40-strategy sweep (175 MB DataFrame) and 817 MB through the 3M-row scaling workloads (525 MB DataFrame).
Installation
# Core library only (latest stable release)
pip install optopsy
# With Data CLI (download & cache market data)
pip install optopsy[data]
Requirements: Python 3.12-3.13, Pandas 2.0+, NumPy 1.26+
Data Management
Optopsy includes a standalone data CLI for downloading and caching historical market data.
pip install optopsy[data]
# Download historical options data (requires EODHD_API_KEY)
optopsy-data download SPY
optopsy-data download SPY AAPL TSLA
# Download stock price history
optopsy-data download SPY --stocks
# List available symbols
optopsy-data symbols
optopsy-data symbols -q SPY
# Cache management
optopsy-data cache size
optopsy-data cache clear
Data is cached locally as Parquet files at ~/.optopsy/cache/. Re-running download only fetches new data since your last download. See the Data Management documentation for full details.
Core Library Quick Start
import optopsy as op
# Load your options data
data = op.csv_data(
"options_data.csv",
underlying_symbol=0,
option_type=2,
expiration=3,
quote_date=4,
strike=5,
bid=6,
ask=7,
delta=8,
)
# Backtest long calls and get performance statistics
results = op.long_calls(data)
print(results)
Output:
dte_range delta_range count mean std min 25% 50% 75% max win_rate profit_factor
0 (0, 7] (0.2, 0.3] 505 0.64 1.03 -1.00 0.14 0.37 0.87 7.62 ... ...
1 (0, 7] (0.3, 0.4] 269 2.34 8.65 -1.00 -1.00 -0.89 1.16 68.00 ... ...
2 (7, 14] (0.2, 0.3] 404 1.02 0.68 -0.46 0.58 0.86 1.32 4.40 ... ...
...
Results are grouped by DTE (days to expiration) and delta range, showing descriptive statistics for percentage returns. Every run also returns win_rate (the fraction of trades with a positive return) and profit_factor (gross wins over gross losses); the values above depend on your dataset and are elided here.
Simulator
Run a full trade-by-trade simulation with capital tracking, position limits, and performance metrics:
result = op.simulate(
data,
op.long_calls,
capital=100_000,
quantity=1,
max_positions=1,
selector="nearest", # "nearest", "highest_premium", "lowest_premium", or custom callable
max_entry_dte=45,
exit_dte=14,
)
print(result.summary) # win rate, profit factor, max drawdown, etc.
print(result.trade_log) # per-trade P&L, entry/exit dates, equity
print(result.equity_curve) # portfolio value over time
The simulator works with all 40 strategies. It selects one trade per entry date, enforces concurrent position limits, and computes a full equity curve with metrics like win rate, profit factor, max drawdown, and average days in trade.
Supported Strategies
| Category | Strategies |
|---|---|
| Single Leg | long_calls, short_calls, long_puts, short_puts |
| Straddles/Strangles | long_straddles, short_straddles, long_strangles, short_strangles |
| Vertical Spreads | long_call_spread, short_call_spread, long_put_spread, short_put_spread |
| Butterflies | long_call_butterfly, short_call_butterfly, long_put_butterfly, short_put_butterfly |
| Ratio Spreads | call_back_spread, put_back_spread, call_front_spread, put_front_spread |
| Iron Condors | iron_condor, reverse_iron_condor |
| Iron Butterflies | iron_butterfly, reverse_iron_butterfly |
| Condors | long_call_condor, short_call_condor, long_put_condor, short_put_condor |
| Covered & Collar | covered_call, protective_put, collar, cash_secured_put (supports actual stock data via yfinance) |
| Calendar Spreads | long_call_calendar, short_call_calendar, long_put_calendar, short_put_calendar |
| Diagonal Spreads | long_call_diagonal, short_call_diagonal, long_put_diagonal, short_put_diagonal |
Documentation
- Getting Started - Installation and first backtest
- Strategies - All 40 strategies explained
- Parameters - Configuration options reference
- Entry Signals - Technical analysis signal filters
- Data Management - Standalone data CLI and caching
- Examples - Common use cases and recipes
- API Reference - Complete function documentation
Star History
Disclaimer
Optopsy is intended for research and educational purposes only. Backtest results are based on historical data and simplified assumptions — they do not account for all real-world factors such as liquidity constraints, execution slippage, assignment risk, or changing market conditions. Past performance is not indicative of future results. Always perform your own due diligence before making any trading decisions.
License
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.
Metadata
Release files for optopsy 2.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| optopsy-2.4.1.tar.gz | 1.8 MB | With provenance | Details for optopsy-2.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| optopsy-2.4.1-py3-none-any.whl | Python 3 | none | any | Details for optopsy-2.4.1-py3-none-any.whl |
Total release size: 2.1 MB
Release files / optopsy-2.4.1.tar.gz
| Download URL | optopsy-2.4.1.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14f7b281d67f5da1f6135bc4bccedb742a6806bf8f7f0569db3b501b20384a7f
|
|
BLAKE2b-256 checksum How to use checksums |
8eab1865eb8ea3bbf38b8d14fa6311bb057fc389d6de2ca4de097c8f3f719b4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / optopsy-2.4.1-py3-none-any.whl
| Download URL | optopsy-2.4.1-py3-none-any.whl |
|---|---|
| Size | 331.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6cf9acdc438f1ab8108197d00230173c452ca9ef94303f347994ea49c5bb4f68
|
|
BLAKE2b-256 checksum How to use checksums |
99c27998994766150dee87f42e37f16c0e3b62eed8acb1c1d8bc846425dcfb38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for optopsy 2.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for optopsy-2.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.