Skip to main content

Option Risk Explain

Option Risk Explain: equity-options portfolio P&L attribution, with synthetic selloff results showing -$44,471 observed P&L, -$63,018 Delta and +$11,288 Vega

Explain an equity-option portfolio's daily P&L from opening Greeks, model revaluation and changes in market marks. Inspect the factor contributions, reconcile the difference and identify contracts that need review.

Open interactive GitHub Pages demo Installation instructions P&L methodology and scope Example scenario results

Python 3.10+ · Python API / CLI / browser · Local CSV analysis · No Streamlit dependency

See the desk move

The interactive report opens with a five-position SPY/AAPL book. Choose Equity market selloff to inspect a shock where SPY falls 5.5%, AAPL falls 6.0% and implied volatility rises by 5–6 percentage points.

EQUITY MARKET SELLOFF                       05–06 OCT 2026
─────────────────────────────────────────────────────────
Observed portfolio P&L                           -$44,471
  Delta                                          -$63,018
  Vega                                           +$11,288
Positions                                              5
Exceptions                                             3
P&L reconciliation error                           $0.00

All inputs are synthetic. The attribution is calculated with the same option_lab engine used for custom portfolios. Greeks, full model repricing, market/model basis and individual contract flags are available in the report.

Interactive browser workbench with scenario selector, portfolio P&L, risk-factor contribution chart and exception review

Example portfolio

Scenario Observed P&L Exceptions
Daily desk review −$1,152 2
Equity market selloff −$44,471 3
Volatility repricing +$13,735 0
Valuation exception +$1,146 3

Switching the browser dropdown updates the report from a precomputed scenario record. No account, file upload or backend is required for these four examples.

Open the interactive GitHub Pages demo ↗

Local setup

Install from the source repository:

git clone https://github.com/garroshub/OptionRiskExplain.git
cd OptionRiskExplain
python -m pip install -e .
python -m option_lab serve

Open http://127.0.0.1:8765/. The local server also accepts two CSV snapshots under Custom portfolio analysis, with JSON and CSV export.

The Python API can run without a browser:

from pathlib import Path
from option_lab import explain_csv

report = explain_csv(
    Path("examples/positions_2026-10-05.csv").read_text(),
    Path("examples/positions_2026-10-06.csv").read_text(),
    exception_threshold=500,
)

print(report["totals"]["observed_pnl"])
print(report["totals"]["reconciliation_error"])
print(report["exceptions"])

CLI example with file exports:

python -m option_lab explain --start examples/positions_2026-10-05.csv --end examples/positions_2026-10-06.csv --threshold 500 --output report.json --csv-output contract-pnl.csv

The optional Yahoo Finance adapter is installed with pip install -e ".[market]". Market data is available through option-risk-explain quote SPY, option-risk-explain expirations SPY and the local option-chain browser. Yahoo quotes are not used as a historical institutional mark feed.

P&L calculation

Option P&L workflow: two input snapshots, opening Greek attribution and BSM repricing, then reconciled P&L and contract-level exceptions

For an unchanged position, with signed contract quantity Q, multiplier M and end-of-day mark P:

Observed P&L = Q × M × (P_end − P_start)

Greek explain:
  Delta0 × ΔSpot + 0.5 × Gamma0 × ΔSpot²
  + Vega0 × ΔIV + Theta0 × elapsed_days
  + Rho0 × ΔRate + isolated dividend-yield effect
  (all multiplied by Q × M)

Approximation residual = Full BSM repricing − Greek explain
Market/model basis     = Observed P&L − Full BSM repricing

Observed P&L = Greek explain + Approximation residual + Market/model basis

Vega and Rho use percentage-point changes; Theta uses calendar days. The two residuals are displayed separately. A market/model basis change can reflect differences in model assumptions, valuation marks or timestamps.

Exception checks cover approximation/basis amounts above a user-supplied USD threshold, crossed bid/ask quotes and marks outside the provided spread.

Working with your own positions

Custom reports require two snapshots with identical contract identities, signed quantities and multipliers. Required CSV fields:

Data CSV fields
Contract underlying, option_type, expiry, strike
Position quantity, multiplier
Market inputs as_of, spot, mark, volatility, rate, dividend_yield
Optional controls bid, ask, source

Dates use YYYY-MM-DD. Volatility, rates and dividend yields are annual decimal values (e.g. 0.25 for 25%). The opening and closing CSVs are included.

Generate the four browser cases with:

python -m scripts.make_risk_fixtures
python -m scripts.generate_scenarios

Model scope and tests

The engine uses European Black–Scholes–Merton pricing, continuous dividends and ACT/365 maturity. It assumes unchanged USD-denominated positions. Trades, fees, funding, early exercise, settlement, FX and corporate actions are excluded. It is a research and workflow prototype, not a validated bank risk system or regulatory FRTB P&L Attribution Test.

python -m unittest discover -s tests -p "test_*.py" -v
node --test tests/pricing.test.mjs
python -m build --wheel --no-isolation
python tests/wheel_smoke.py

The tests cover prices and Greeks, signed-position P&L reconciliation, input validation, scenario consistency, HTTP endpoints, and Chrome desktop/mobile interactions. The installable distribution is option-risk-explain. The Python module remains option_lab, and the original option-lab CLI remains available.


Interactive demo · Source code · Method

Metadata

Release files for option-risk-explain 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for option-risk-explain 0.2.0
File Size Uploaded
option_risk_explain-0.2.0.tar.gz 53.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for option-risk-explain 0.2.0
File Interpreter ABI Platform
option_risk_explain-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 106.1 kB

Release files / option_risk_explain-0.2.0.tar.gz

Download URL option_risk_explain-0.2.0.tar.gz
Size 53.3 kB
Tags Source
SHA-256 checksum
How to use checksums
265458fc204f274458ab550b8c29149ef7668d7f44c09866bcf0ff17c48e2c45
BLAKE2b-256 checksum
How to use checksums
bb81982012d6c21472359fad7c7722c25f25ccba57d48f41162b8d33eb04f098
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 8, 2026.

Transparency log

Release files / option_risk_explain-0.2.0-py3-none-any.whl

Download URL option_risk_explain-0.2.0-py3-none-any.whl
Size 52.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60d6f69ac8d2f352757f436cb41377c4f7fdd1d711625640fd7e815e59c416a2
BLAKE2b-256 checksum
How to use checksums
0d96d23d53c774a6248268e1e95907887542fed3f420210c448fb92ff85c4bab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page