diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..7c2eb9f --- /dev/null +++ b/.coveragerc @@ -0,0 +1,4 @@ +[run] +source = src/optpricing +omit = + src/optpricing/dashboard/pages/* diff --git a/.gitignore b/.gitignore index 706ccdb..6d3b51d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ htmlcov/ site/ # Ignore my local notes file -todo.txt todo/ notes/ +text_drafts/ +todo.txt diff --git a/README.md b/README.md index fe3fd75..209f50c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# optpricing +# OptPricing: A Quantitative Finance Library for Derivative Pricing and Analysis [![Tests](https://img.shields.io/github/actions/workflow/status/diljit22/quantfin/ci.yml?branch=main&label=tests)](https://github.com/diljit22/quantfin/actions/workflows/ci.yml) [![Coverage](https://codecov.io/gh/diljit22/quantfin/branch/main/graph/badge.svg)](https://codecov.io/gh/diljit22/quantfin) @@ -8,54 +8,161 @@ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -**A Python library for pricing and calibrating financial options.** +`optpricing` is a Python library for pricing, calibrating, and analyzing financial derivatives. It is built with a focus on architectural clarity, model breadth, and practical usability through a robust API, command-line interface, and an interactive dashboard. -## Introduction +Diljit Singh +linkedin.com/in/singhdiljit/ -Welcome to **optpricing**, a comprehensive Python toolkit for pricing and calibrating financial derivatives. This library was originally designed for me to learn about the more nuanced methods of quantitative finance and has since grown into a robust framework for analysis. +--- + +## Core Features + +* **Model Library**: Implements a comprehensive set of models, including: + * **Stochastic Volatility**: Heston, SABR + * **Jump-Diffusion**: Merton, Bates, Kou, SABR with Jumps + * **Pure Levy Processes**: Variance Gamma (VG), Normal Inverse Gaussian (NIG), CGMY, Hyperbolic + * **Interest Rate Models**: Vasicek, Cox-Ingersoll-Ross (CIR), Put-Call Parity Implied Rate + * **Local Volatility**: Dupire's Equation -optpricing is structured around four core pillars: +* **Pricing Engines**: Provides a suite of numerical methods, allowing for technique comparison and validation: + * Analytic closed-form solutions + * Numerical integration and FFT-based pricing via characteristic functions + * Finite difference (PDE) solver using a Crank-Nicolson scheme + * Binomial and trinomial tree methods (CRR, TOPM, Leisen-Reimer) for European and American options + * High-performance Monte Carlo engine for European and American options, accelerated with `numba`, featuring variance reduction techniques (e.g., antithetic variates, control variates, importance sampling) -- **Atoms**: Fundamental data types (`Option`, `Stock`, `Rate`) that ensure consistency and clarity of inputs across the library. -- **Models**: A broad library ranging from classical Black-Scholes-Merton to advanced stochastic volatility (Heston, SABR) and jump/Levy processes. -- **Techniques**: Multiple pricing engines—closed-form formulas, FFT, numerical integration, PDE solvers, lattice methods, and Monte Carlo (`numba`-accelerated with variance reduction methods baked in). -- **Workflows**: High-level orchestrators that automate end-to-end tasks like daily calibration and out-of-sample backtesting, all accessible via a CLI or an interactive dashboard. +* **Interfaces**: + * **Programmatic API**: Use the package as a Python library to build custom financial models in your scripts. Define options, stocks, rates, and models programmatically to compute prices and other metrics. + * **Command-Line Interface (CLI)**: A robust CLI for live pricing, data management, model calibration, and historical backtesting. + * **Interactive Dashboard (UI)**: A Streamlit application for visual analysis of option chains, implied volatility surfaces, and model calibrations. + +* **Workflow Automation**: High-level classes that orchestrate complex tasks like daily calibration runs and out-of-sample performance evaluation. --- ## Quick Start -Get started in minutes using the command-line interface. +`optpricing` is designed for a straightforward installation using `pip` and is compatible with Python 3.10 and higher. + +### 1. Install the Library ```bash -# 1. Install the library with all features, including the dashboard -pip install "optpricing" +pip install optpricing +``` -# 2. Download historical data for a ticker (used by some models) +### 2. Download Historical Data + +Some models require historical data (e.g., for calibration). Download data for a ticker like SPY: + +```bash optpricing data download --ticker SPY +``` + +For more details, see the [Getting Started Guide]((guide/getting_started.md)). + +### 3. Use the CLI + +Price an option directly from the terminal. The command below fetches the live option chain for AAPL, retrieves the current dividend rate, calculates the implied risk-free rate from at-the-money contracts, and prices the contract with Heston’s model using its default pricing technique (FFT): + +```bash +optpricing price --ticker AAPL --strike 630 --maturity 2025-12-19 --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5" +``` + +To price the same contract as an American Option use: + +```bash +optpricing price -t AAPL -k 210 -T 2025-12-19 --style american --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5" +``` + +For more details, see the [CLI Guide]((guide/CLI.md)). + +### 4. Launch the Dashboard -# 3. Launch the interactive dashboard to visualize the results +Visualize option chains and model outputs, interact with a pricing calculator featuring 15 models and 10 techniques. + +```bash optpricing dashboard +``` + +For more details, see the [Dashboard Guide]((guide/dashboard.md)). + +### 5. Use the Programmatic API + +The most powerful way to use the package is via the API, which provides customization of nearly every aspect of pricing: + +```python +from optpricing import Option, OptionType, Rate, Stock, ZeroCouponBond +from optpricing.models import BSMModel, CIRModel, VasicekModel +from optpricing.techniques import ClosedFormTechnique + +# Define an option, underlying and rate +option = Option(strike=105, maturity=1.0, option_type=OptionType.CALL) +stock = Stock(spot=100, dividend=0.01) +rate = Rate(rate=0.05) + +# Choose a model and technique +bsm_model = BSMModel(params={"sigma": 0.20}) +cf_technique = ClosedFormTechnique() + +result = cf_technique.price(option, stock, bsm_model, rate) +print(f"The option price is: {result.price:.4f}") + +delta = cf_technique.delta(option, stock, bsm_model, rate) +gamma = cf_technique.gamma(option, stock, bsm_model, rate) +vega = cf_technique.vega(option, stock, bsm_model, rate) + +print(f"Delta: {delta:.4f}") +print(f"Gamma: {gamma:.4f}") +print(f"Vega: {vega:.4f}") + +target_price = 7.50 +iv = cf_technique.implied_volatility( + option, stock, bsm_model, rate, target_price=target_price +) +print(f"Implied volatility for price ${target_price:.2f}: {iv:.4%}") + + +# Zero Coupon Bond +bond = ZeroCouponBond(maturity=1.0) +r0_stock = Stock(spot=0.05) # initial short rate +dummy_rate = Rate(rate=0.0) # ignored by rate models + +vasicek = VasicekModel(params={"kappa": 0.86, "theta": 0.09, "sigma": 0.02}) +cir = CIRModel(params={"kappa": 0.86, "theta": 0.09, "sigma": 0.02}) + +p_vasi = cf_technique.price(bond, r0_stock, vasicek, dummy_rate).price +p_cir = cf_technique.price(bond, r0_stock, cir, dummy_rate).price + +print(f"Vasicek ZCB Price: {p_vasi:.4f}") +print(f"CIR ZCB Price: {p_cir:.4f}") ``` -## Documentation & Links +For more details, see the [API Guide]((guide/API.md)). + +--- + +## Documentation + +The full documentation includes installation instructions, user guides, examples, and a complete API reference. -For a detailed tutorial, full API reference, and more examples, please see the official documentation. +* **[View the Official Documentation](https://diljit22.github.io/quantfin/)** -- **Getting Started**: - [Installation Guide](https://diljit22.github.io/quantfin/guide/installation/) · - [Walkthrough](https://diljit22.github.io/quantfin/guide/getting_started/) +### Guides -- **Documentation**: - [API Reference](https://diljit22.github.io/quantfin) +* [Introduction](guide/introduction.md) +* [Installation](guide/installation.md) +* [Getting Started](guide/getting_started.md) +* [CLI](guide/CLI.md) +* [Dashboard](guide/dashboard.md) +* [API](guide/API.md) +* [Examples](guide/examples.md) +* [API Reference](reference/index.md) -- **Interactive Dashboard**: - [Launch the UI](https://diljit22.github.io/quantfin/guide/dashboard/) +## Contributing -- **About Me**: - [LinkedIn](https://www.linkedin.com/in/singhdiljit/) +Contributions are welcome; see [CONTRIBUTING](/CONTRIBUTING.md) for details. -## Contributing & License +## License -See [CONTRIBUTING](/CONTRIBUTING.md) and [LICENSE](LICENSE). +This project is licensed under the MIT License. See [LICENSE](LICENSE) for details. diff --git a/codecov.yml b/codecov.yml index 4d1d10a..fa7f577 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,3 +3,5 @@ coverage: status: project: enabled: false +ignore: + - "src/optpricing/dashboard/pages/*" diff --git a/docs/guide/API.md b/docs/guide/API.md new file mode 100644 index 0000000..2c94850 --- /dev/null +++ b/docs/guide/API.md @@ -0,0 +1,127 @@ +# Guide: Programmatic API + +The `optpricing` Python API provides a powerful, object-oriented framework for building custom financial analysis scripts and workflows. Its modular design allows you to mix and match models, techniques, and data to suit your specific research needs. + +This guide covers the fundamental components and provides examples for common use cases. + +--- + +## Core Concepts: Atoms, Models, and Techniques + +All programmatic workflows are built on three core components: + +1. **Atoms**: Immutable data classes like `Option`, `Stock`, and `Rate` that represent the basic inputs. +2. **Models**: Classes representing financial theories, such as `BSMModel` or `HestonModel` (and many others). +3. **Techniques**: Classes representing numerical algorithms, such as `ClosedFormTechnique` or `MonteCarloTechnique` (and many others). + +You instantiate these components and pass them to a technique's `price` method to get a result. + +## Example 1: Pricing a Standard European Option + +This example demonstrates the most common use case: pricing a European call option using the Black-Scholes-Merton model's analytic formula. + +```python +from optpricing import Option, OptionType, Rate, Stock +from optpricing.models import BSMModel +from optpricing.techniques import ClosedFormTechnique + +# 1. Define the core Atoms +option = Option(strike=105, maturity=1.0, option_type=OptionType.CALL) +stock = Stock(spot=100.0, dividend=0.01) +rate = Rate(rate=0.05) + +# 2. Instantiate the Model and Technique +bsm_model = BSMModel(params={"sigma": 0.20}) +cf_technique = ClosedFormTechnique() + +# 3. Calculate the price and Greeks +result = cf_technique.price(option, stock, bsm_model, rate) +delta = cf_technique.delta(option, stock, bsm_model, rate) +gamma = cf_technique.gamma(option, stock, bsm_model, rate) + +print(f"The option price is: {result.price:.4f}") +print(f"Delta: {delta:.4f}") +print(f"Gamma: {gamma:.4f}") +``` + +## Example 2: Pricing an American Option with Monte Carlo + +The API's flexibility allows you to easily switch to more complex scenarios. Here, we price an American option using the Heston model with the Longstaff-Schwartz Monte Carlo method. + +```python +from optpricing.models import HestonModel +from optpricing.techniques import AmericanMonteCarloTechnique + +# 1. Define an American option Atom +american_option = Option(strike=105, maturity=1.0, option_type=OptionType.PUT) + +# 2. Instantiate a more complex model and the appropriate technique +heston_model = HestonModel(params={ + "v0": 0.04, + "kappa": 2.0, + "theta": 0.05, + "rho": -0.7, + "vol_of_vol": 0.5 +}) +lsmc_technique = AmericanMonteCarloTechnique(n_paths=20000, n_steps=100) + +# 3. Calculate the price +# Note: The 'v0' parameter is passed as a keyword argument for the simulation +result = lsmc_technique.price( + american_option, + stock, + heston_model, + rate, + v0=heston_model.params['v0'] +) +print(f"The American option price is: {result.price:.4f}") +``` + +## Example 3: Calculating Implied Volatility + +The library includes mixins for common tasks like calculating implied volatility. This functionality is available on most technique objects. + +```python +# Using the components from Example 1 +target_price = 7.50 + +iv = cf_technique.implied_volatility( + option, + stock, + bsm_model, + rate, + target_price=target_price +) + +print(f"Implied volatility for a target price of ${target_price:.2f}: {iv:.4%}") +``` + +## Example 4: Pricing an Interest Rate Product + +The framework is not limited to equity options. It can be used to price other derivatives, such as Zero-Coupon Bonds using short-rate models. + +```python +from optpricing.atoms import ZeroCouponBond +from optpricing.models import VasicekModel + +# 1. Define a ZeroCouponBond Atom +bond = ZeroCouponBond(maturity=5.0, face_value=1000.0) + +# 2. For rate models, the 'stock.spot' is re-interpreted as the initial short rate r0 +r0_stock = Stock(spot=0.03) +# The 'rate' atom is ignored by rate models but required by the technique signature +dummy_rate = Rate(rate=0.0) + +# 3. Instantiate the Vasicek model +vasicek_model = VasicekModel(params={"kappa": 0.86, "theta": 0.05, "sigma": 0.02}) + +# 4. Price using the ClosedFormTechnique +price_result = cf_technique.price(bond, r0_stock, vasicek_model, dummy_rate) +print(f"Price of 5-Year ZCB under Vasicek model: ${price_result.price:.2f}") +``` + +## Advanced Usage: Extending the Library + +The library's true power lies in its extensibility. By inheriting from `BaseModel` and `BaseTechnique`, you can easily add your own custom models and pricing algorithms, which will automatically integrate with the existing framework. + +For a complete and detailed list of all available classes, methods, and functions, please consult the full **[API Reference](../reference/index.md)**. diff --git a/docs/guide/CLI.md b/docs/guide/CLI.md new file mode 100644 index 0000000..0cedbf6 --- /dev/null +++ b/docs/guide/CLI.md @@ -0,0 +1,150 @@ +# Guide: Command-Line Interface (CLI) + +The `optpricing` CLI is a powerful tool for performing complex financial analysis directly from your terminal. It provides access to pricing, data management, calibration, and backtesting workflows without requiring any Python scripting. + +## Main Commands + +These are the top-level commands available directly after `optpricing`. + +### `price` + +Prices a single option using live market data. This command automatically fetches the underlying spot price, estimates the dividend yield, and calculates an implied risk-free rate from the live option chain before pricing the specified contract. + +**Usage:** +`optpricing price [OPTIONS]` + +**Key Options:** + +- `--ticker, -t TEXT`: Stock ticker (e.g., 'AAPL'). **[required]** +- `--strike, -k FLOAT`: Strike price. **[required]** +- `--maturity, -T TEXT`: Maturity date in YYYY-MM-DD format. **[required]** +- `--type TEXT`: 'call' or 'put'. [default: call] +- `--style TEXT`: 'european' or 'american'. [default: european] +- `--model, -m TEXT`: Model to use (e.g., 'BSM', 'Heston'). [default: BSM] +- `--param TEXT`: Set a model parameter (e.g., `sigma=0.2`). Can be used multiple times. + +**Example:** + +```bash +# Price an American put on TSLA using the Heston model +optpricing price -t TSLA -k 290 -T 2026-01-16 --style american --model Heston +``` + +### `calibrate` + +Calibrates model parameters to saved market data. This workflow loads a market snapshot, filters for liquid options, and uses an optimization routine to find the model parameters that best fit the observed market prices. + +**Usage:** +`optpricing calibrate [OPTIONS]` + +**Key Options:** + +- `--ticker, -t TEXT`: Ticker for the snapshot to use. **[required]** +- `--model, -m TEXT`: Model to calibrate ('BSM' or 'Merton'). Can be used multiple times. **[required]** +- `--date, -d TEXT`: Snapshot date (YYYY-MM-DD). Defaults to the latest available. + +**Example:** + +```bash +# Calibrate the BSM and Merton models to a specific historical snapshot +optpricing calibrate -t SPY -m BSM -m Merton --date 2025-07-08 +``` + +### `backtest` + +Runs a historical out-of-sample backtest for a model. The workflow iterates through all available historical data, calibrates the model on day `D`, and evaluates its pricing accuracy on the unseen data from day `D+1`. + +**Usage:** +`optpricing backtest [OPTIONS]` + +**Key Options:** + +- `--ticker, -t TEXT`: Ticker to backtest. **[required]** +- `--model, -m TEXT`: Model to backtest. **[required]** +- `--verbose, -v`: Enable detailed logging output. + +**Example:** + +```bash +optpricing backtest -t SPY -m BSM -v +``` + +### `dashboard` + +Launches the interactive Streamlit dashboard. + +**Usage:** +`optpricing dashboard` + +--- + +## Sub-Command Groups + +### `data` + +Tools for downloading and managing market data. + +**Usage:** +`optpricing data [COMMAND]` + +**Commands:** + +- `download`: Downloads and saves historical log returns for one or more tickers. + + ```bash + optpricing data download --ticker AAPL --period 5y + ``` + +- `snapshot`: Fetches and saves a live market data snapshot of the full option chain. + + ```bash + optpricing data snapshot --ticker TSLA + ``` + +- `dividends`: Fetches and displays live forward dividend yields. + + ```bash + optpricing data dividends --ticker JPM + ``` + +### `demo` + +Runs benchmark scripts from the `examples/` directory (requires a local clone of the repository). + +**Usage:** +`optpricing demo [COMMAND]` + +**Commands:** + +- `european`: Runs the European options benchmark across all models. + + ```bash + optpricing demo european --model Heston + ``` + +- `american`: Runs the American options benchmark. + + ```bash + optpricing demo american + ``` + +- `rates`: Runs the interest rate models benchmark. + + ```bash + optpricing demo rates + ``` + +### `tools` + +Miscellaneous financial utility tools. + +**Usage:** +`optpricing tools [COMMAND]` + +**Commands:** + +- `implied-rate`: Calculates the implied risk-free rate from a live call-put pair using put-call parity. + + ```bash + optpricing tools implied-rate --ticker SPY --strike 630 --maturity 2025-12-19 + ``` diff --git a/docs/guide/dashboard.md b/docs/guide/dashboard.md index 3d4f00d..e0beec2 100644 --- a/docs/guide/dashboard.md +++ b/docs/guide/dashboard.md @@ -1,45 +1,53 @@ -# Using the Interactive Dashboard +# Guide: The Interactive Dashboard -The `optpricing` library includes an interactive dashboard built with Streamlit, -providing a visual interface for the library's core features. +The `optpricing` dashboard provides a rich, interactive user interface for visual analysis and pricing. It is built with Streamlit and is the easiest way to explore the library's features without writing code. ## Launching the Dashboard -To use the dashboard, you must first install the library with the `[app]` extra dependencies: - -```bash -pip install optpricing[app] -``` - -Once installed, you can launch the application from your terminal with a single command: +To start the application, simply run the following command in your terminal: ```bash optpricing dashboard ``` -This will open the application in a new browser tab. +This will launch the dashboard in a new browser tab. The sidebar on the left is the main navigation hub, allowing you to select a ticker, a data snapshot date (including live data), and a model to analyze. ## Dashboard Pages -The dashboard is organized into several pages, accessible from the sidebar on the left. +The dashboard is organized into several specialized pages: + +### 1. Pricer & Greeks + +This is an on-demand pricing tool. It allows you to manually set every parameter—from the option's strike and maturity to the specific parameters of the selected financial model. It's an ideal environment for: + +- Building intuition about how different parameters affect option prices and Greeks. +- Performing sensitivity analysis. +- Comparing the output of different numerical techniques for the same model. + +### 2. Calibration & IV + +This page is the front-end for the model calibration workflow. Here you can: -### Calibration +- Select one or more models (e.g., BSM, Merton) to calibrate against a chosen market data snapshot. +- Visualize the results of the calibration, including the final Root Mean-Squared Error (RMSE). +- Analyze the resulting **Implied Volatility (IV) surface** of the calibrated model against the market's IV surface. +- View **volatility smiles** and **error heatmaps** to diagnose mispricings and understand model fit. -This is the main page for model calibration. It allows you to select a ticker and one or more models, run the calibration workflow, and see a detailed analysis of the results. +### 3. Market Analytics -![alt text](../images/calibration.png) +This page is an exploratory tool for option chain data. It allows you to load a live or historical snapshot and visualize key metrics for a chosen expiry date, including: -### Pricer and Greeks +- Total **Volume** and **Open Interest** for calls vs. puts. +- An Open Interest "pyramid" showing concentrations across different strike prices. +- The statistical distribution of Implied Volatility across the chain. -This page is an interactive pricing tool that allows you to explore the behavior of different models and techniques in real-time. You can adjust all market and model parameters to see their effect on the option price and its Greeks. -![alt text](../images/bates.png) +### 4. Model Fitting -### Financial Tools +This page contains tools for quantitative research, allowing you to: -This page provides access to several utility functions from the library for more specific analyses. -Historical Jump Fitter: Select a ticker to estimate jump-diffusion parameters directly from its historical returns data. -![alt text](../images/fit_jump.png) +- Generate a **Quantile-Quantile (QQ) plot** to visually assess if a stock's historical returns conform to a normal distribution (a key assumption of the BSM model). +- Fit jump parameters for a Merton-style process directly from historical returns using the method of moments. -Term Structure Pricer: Price a zero-coupon bond using interest rate models like Vasicek or CIR. +### 5. Term Structure -![alt text](../images/zcb.png) +This page is dedicated to interest rate models. It allows you to price Zero-Coupon Bonds and visualize the resulting yield curve generated by the Vasicek or CIR short-rate models. diff --git a/docs/guide/examples.md b/docs/guide/examples.md new file mode 100644 index 0000000..83756a6 --- /dev/null +++ b/docs/guide/examples.md @@ -0,0 +1,66 @@ +# Guide: Examples & Benchmarks + +The `optpricing` repository includes a set of pre-built benchmark scripts in the `examples/` directory. These scripts are designed to showcase the library's capabilities, compare the performance and accuracy of different numerical techniques, and serve as a starting point for your own custom research. + +**Note:** To run these examples, you must have a local clone of the repository. See the [Developer Installation](installation.md#developer-installation) instructions for details. + +## Running Benchmarks from the CLI + +The easiest way to run these benchmarks is through the `demo` command group in the CLI. + +### European Options Benchmark + +This is the most comprehensive benchmark, designed to compare a wide array of pricing techniques across the full suite of European option models. For each model, it generates a detailed table comparing: + +- Price +- All primary Greeks (Delta, Gamma, Vega, Theta, Rho) +- Implied Volatility +- Calculation time for each metric + +It also calculates the put-call parity error for each technique, serving as a powerful validation of the implementation's correctness. + +**To run the full benchmark suite:** + +```bash +optpricing demo european +``` + +**To run the benchmark for a single model (e.g., Heston):** + +```bash +optpricing demo european --model Heston +``` + +This benchmark is an excellent tool for understanding the trade-offs between speed and accuracy for different numerical methods. + +### American Options Benchmark + +This benchmark focuses specifically on techniques suitable for pricing American-style options, which allow for early exercise. It compares the results of: + +- **Longstaff-Schwartz Monte Carlo**: A flexible, simulation-based approach. +- **Lattice/Tree Methods**: Including CRR, Leisen-Reimer, and Trinomial trees. + +The script prices a standard American put option across all supported models and presents a comparison of the calculated price and performance. + +**To run the American options benchmark:** + +```bash +optpricing demo american +``` + +### Interest Rate Models Benchmark + +This example demonstrates the use of the library for pricing fixed-income derivatives. It prices a Zero-Coupon Bond using two canonical short-rate models: + +- **Vasicek Model** +- **Cox-Ingersoll-Ross (CIR) Model** + +It showcases the use of the `ClosedFormTechnique` for models where an analytical solution for bond prices exists. + +**To run the interest rate models benchmark:** + +```bash +optpricing demo rates +``` + +These scripts provide a robust demonstration of the library's features and serve as a template for constructing more complex, custom analyses using the `optpricing` API. diff --git a/docs/guide/getting_started.md b/docs/guide/getting_started.md index d95bbda..abb3d63 100644 --- a/docs/guide/getting_started.md +++ b/docs/guide/getting_started.md @@ -1,218 +1,133 @@ # Getting Started: A Walkthrough -This guide is a hands-on tutorial that will walk you through the library's core features, -from pricing a single option to running a full model calibration, using the command-line -interface (CLI). +This guide walks you through a typical use case, from pricing a single option with the Python API to running a full calibration workflow with the command-line interface (CLI). --- -## 1. Run the Built-In Demo +## 1. Pricing a European Option with the Python API -The quickest way to see optpricing in action is with the included benchmark script. +The core components of `optpricing` are designed to be intuitive and composable. Let’s price a standard European call option and calculate its Greeks. -**Prerequisite**: install the library if you haven’t already: +First, define the core **Atoms**: the option contract, the underlying stock, and the risk-free rate. -```bash -pip install optpricing -``` - -Then execute: +```python +from optpricing import Option, OptionType, Rate, Stock -```bash -optpricing demo +# Define the core components +option = Option(strike=105, maturity=1.0, option_type=OptionType.CALL) +stock = Stock(spot=100.0, dividend=0.01) +rate = Rate(rate=0.05) ``` -This will price a standard option across multiple models and techniques and print a -formatted comparison table. - ---- - -## 2. Pricing an Option Programmatically - -First, import and configure the objects you need: +Next, select a **Model** and a pricing **Technique**. Here, we’ll use the Black-Scholes-Merton model and its analytic closed-form solution. ```python -from optpricing.atoms import Option, Stock, Rate, OptionType, ZeroCouponBond -from optpricing.models import BSMModel, VasicekModel, CIRModel +from optpricing.models import BSMModel from optpricing.techniques import ClosedFormTechnique -# 1. Define an option, underlying and rate -option = Option(strike=105, maturity=1.0, option_type=OptionType.CALL) -stock = Stock(spot=100, dividend=0.01) -rate = Rate(rate=0.05) - -# 2. Choose a model and technique -bsm_model = BSMModel(params={"sigma": 0.20}) -cf_technique = ClosedFormTechnique() -``` - -### 2.1 Compute the Price +# Choose a model and technique +bsm_model = BSMModel(params={"sigma": 0.20}) +cf_technique = ClosedFormTechnique() -```python +# Calculate the price result = cf_technique.price(option, stock, bsm_model, rate) print(f"The option price is: {result.price:.4f}") ->>> The option price is: 7.4917 -``` - -### 2.2 Compute the Greeks -```python +# Calculate Greeks delta = cf_technique.delta(option, stock, bsm_model, rate) gamma = cf_technique.gamma(option, stock, bsm_model, rate) -vega = cf_technique.vega(option, stock, bsm_model, rate) +vega = cf_technique.vega(option, stock, bsm_model, rate) print(f"Delta: {delta:.4f}") print(f"Gamma: {gamma:.4f}") print(f"Vega: {vega:.4f}") - ->>> Delta: 0.5172 ->>> Gamma: 0.0197 ->>> Vega: 39.4353 -``` - -### 2.3 Find Implied Volatility - -```python -target_price = 7.50 -iv = cf_technique.implied_volatility( - option, stock, bsm_model, rate, target_price=target_price -) -print(f"Implied volatility for price ${target_price:.2f}: {iv:.4%}") ->>> Implied volatility for price $7.50: 20.0211% ``` --- -## 3. Pricing Interest‐Rate Instruments +## 2. Pricing an American Option with the Python API -optpricing reuses the same pricing interfaces for interest‐rate models: +The API supports American options using models like Heston with Monte Carlo techniques, optimized with `numba` for performance. ```python -# Zero‐coupon bond maturing in 1 year -bond = ZeroCouponBond(maturity=1.0) -r0_stock = Stock(spot=0.05) # initial short rate -dummy_rate = Rate(rate=0.0) # ignored by rate models - -vasicek = VasicekModel(params={"kappa":0.86, "theta":0.09, "sigma":0.02}) -cir = CIRModel(params={"kappa":0.86, "theta":0.09, "sigma":0.02}) +from optpricing.models import HestonModel +from optpricing.techniques import AmericanMonteCarloTechnique -p_vasi = cf_technique.price(bond, r0_stock, vasicek, dummy_rate).price -p_cir = cf_technique.price(bond, r0_stock, cir, dummy_rate).price +# Define components +option = Option(strike=105, maturity=1.0, option_type=OptionType.CALL, style="american") +stock = Stock(spot=100.0, dividend=0.01) +rate = Rate(rate=0.05) -print(f"Vasicek ZCB Price: {p_vasi:.4f}") -print(f"CIR ZCB Price: {p_cir:.4f}") +# Choose a model and technique +heston_model = HestonModel(params={"v0": 0.04, "kappa": 2.0, "theta": 0.05, "rho": -0.7, "vol_of_vol": 0.5}) +mc_technique = AmericanMonteCarloTechnique() ->>> Vasicek ZCB Price: 0.9388 ->>> CIR ZCB Price: 0.9388 +# Calculate the price +result = mc_technique.price(option, stock, heston_model, rate) +print(f"The American option price is: {result.price:.4f}") ``` --- -## 4. Live Pricing and Analysis via CLI +## 3. Using the Command-Line Interface (CLI) -### 4.1 Price an Option +The CLI provides a powerful way to access the library’s features without writing Python code. -```bash -optpricing price \ - --ticker SPY \ - --strike 500 \ - --maturity 2025-12-19 \ - --type call \ - --model Heston \ - --param "v0=0.04" \ - --param "kappa=2.0" \ - --param "theta=0.05" \ - --param "rho=-0.7" \ - --param "vol_of_vol=0.5" -``` - -### 4.2 Implied Rate from Put-Call Parity +### Pricing an Option -The tools implied-rate command fetches live prices for a call-put pair and calculates the risk-free rate implied by put-call parity. +Price a European or American option directly from the terminal. The command below fetches the live option chain for AAPL, retrieves the current dividend rate, calculates the implied risk-free rate from at-the-money contracts, and prices the contract with Heston’s model using its default technique (FFT): ```bash -optpricing tools implied-rate --ticker SPY --strike 500 --maturity 2025-12-19 +optpricing price --ticker AAPL --strike 210 --maturity 2025-12-19 --type call --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5" ``` ---- - -## 5. Model Calibration with the CLI - -Download historical returns (for initial guesses and jump paramaters): +For an American option: ```bash -optpricing data download --ticker SPY +optpricing price --ticker AAPL --strike 210 --maturity 2025-12-19 --type call --style american --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5" ``` -Download a snapshot of the market-data +### Downloading Data + +Download historical returns or a live option chain snapshot for calibration or backtesting: ```bash -# For the 25 benchmark stocks use --all -optpricing data snapshot --all +# Download historical log-returns +optpricing data download --ticker SPY --period 10y -# If just a particular ticker use e.g. -optpricing data snapshot --ticker SPY --ticker AAPL +# Save a snapshot of the live option chain +optpricing data snapshot --ticker SPY ``` -A simple calibration for the Merton Jump model. The workflow will find the latest market data -for SPY and solve for the implied volatility that best fits the front-month options. +Data is saved to the `data/` directory for use in other workflows. + +### Calibrating a Model -The `--verbose` flag provides detailed logs from the workflow. +Calibrate a model to fit observed market prices using a saved market snapshot: ```bash -optpricing calibrate --ticker SPY --model Merton --verbose +# Calibrate the Heston model to the latest snapshot for SPY +optpricing calibrate --ticker SPY --model Heston --verbose ``` -The final calibrated parameters are printed to the console and saved to a JSON file in -the `artifacts/calibrated_params/` directory. - ---- - -## 6. Managing Data - -* Download specific tickers: - - ```bash - optpricing data download --ticker AAPL --ticker TSLA - ``` - -* Download all defaults (from `config.yaml`): - - ```bash - optpricing data download --all - ``` - -* Snapshot the live option chain: - - ```bash - optpricing data snapshot --ticker NVDA - ``` +This command runs the calibration workflow, prints the results, and saves optimized parameters to a `.json` file in the `artifacts/` directory. --- -## 7. Running Tests +## 4. Launching the Dashboard -If you have installed dev dependencies: +Visualize option chains and model outputs with an interactive Streamlit dashboard supporting 15 models and 10 techniques: ```bash -pip install -e .[dev] -pytest +optpricing optpricing/dashboard/Home.py ``` --- -## 8. Launching the Dashboard - -Make sure you have the `[app]` extras installed: +## What’s Next? -```bash -pip install optpricing[app] -``` - -Then run: - -```bash -optpricing dashboard -``` +Explore the full capabilities of `optpricing` with these guides: -This will open the Streamlit application in your browser for interactive exploration. +* [Dashboard Guide](https://diljit22.github.io/quantfin/guide/dashboard.md): A visual tour of the interactive UI. +* [Examples Guide](https://diljit22.github.io/quantfin/guide/examples.md): Advanced benchmarks and use cases. +* [API Guide](https://diljit22.github.io/quantfin/guide/API.md): Detailed API documentation for custom workflows. diff --git a/docs/guide/installation.md b/docs/guide/installation.md index 42f1f81..2cebed4 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -1,33 +1,61 @@ # Installation -The optpricing library is published on the Python Package Index (PyPI) and can be easily installed using `pip`. A Python version of 3.10 or higher is required. +`optpricing` is designed for a straightforward installation using `pip` and is compatible with Python 3.10 and higher. -## Standard Installation +## User Installation -For most use cases, including running the command-line interface for calibration and backtesting, you can install the core library with the following command: +Install the latest stable release from PyPI to get: + +- The core Python API +- The `optpricing` CLI +- The interactive dashboard ```bash pip install optpricing ``` -This will install the library and all its core dependencies, such as numpy, scipy, and typer. +Confirm the installation by checking the package version: -## Full Installation (with Dashboard) +```bash +import optpricing +print(optpricing.__version__) # Prints the installed version +``` -The library includes an optional interactive dashboard built with Streamlit, which provides a visual way to interact with the pricing and calibration tools. To install the core library along with the dependencies needed to run the dashboard, use the [app] extra: +Launch the CLI or dashboard: ```bash -pip install optpricing[app] +optpricing --help # View CLI commands +optpricing/dashboard # Launch the dashboard ``` -This is the recommended installation if you plan to use the visual tools. +For more details, visit the [Getting Started guide](guide/getting_started.md) ## Developer Installation -If you wish to contribute to the development of optpricing, or if you want to make local modifications to the source code, you should clone the repository and install it in "editable" mode. +To contribute, run tests, or execute benchmarks, follow these steps inside a virtual environment: ```bash +# 1. Clone the repo git clone https://github.com/diljit22/quantfin.git -cd optpricing -pip install -e .[app,dev] +cd quantfin + +# 2. Create & activate a venv (Linux/macOS) +python -m venv .venv +source .venv/bin/activate # On Windows, use: .venv\Scripts\activate + +# 3. Install editable with dev-extras +pip install --upgrade pip +pip install -e ".[dev]" ``` + +### Running Benchmarks and Tests + +- The benchmark scripts are located in the `examples/` directory and require a local clone. + +- Run the test suite with: + + ```bash + pytest tests/ --cov=src/optpricing --cov-report=term-missing + ``` + + A live pulse is available at . diff --git a/docs/guide/introduction.md b/docs/guide/introduction.md index 131e8d1..51d34d6 100644 --- a/docs/guide/introduction.md +++ b/docs/guide/introduction.md @@ -1,35 +1,31 @@ # Introduction -Welcome to the optpricing library! This documentation is your comprehensive guide to understanding and using all the features this library has to offer. +Welcome to `optpricing`, a Python toolkit for pricing and calibrating financial derivatives. This library was created to implement and understand the mathematical and computational foundations of quantitative finance, growing into a robust, extensible framework. -## What is optpricing? +## Guiding Principles -optpricing is a Python library designed to provide a toolkit for quantitative finance, with a primary focus on the pricing and analysis of financial derivatives. +The library is organized around four core concepts; understanding these will help you navigate the codebase and documentation. -The library is organized around a few core concepts; understanding these will help you navigate the codebase and documentation. +1. **Atoms**: Immutable data structures for core financial concepts like `Option`, `Stock`, and `Rate`. They provide a consistent foundation for every calculation. This ensures clarity of inputs across the entire library. -- **Atoms**: These are the fundamental, immutable data structures representing core financial concepts like `Option`, `Stock`, and `Rate`. By using these "atoms," we ensure that data is passed through the system in a consistent and predictable way. +2. **Models**: An extensible module of financial models, including classical option pricing models, advanced stochastic volatility models, jump-diffusion processes, and interest rate models. In addition to pricing options, some models support valuation of implied rates, volatility-focused analysis, and put-call parity. Each model is a self-contained representation of a specific financial theory. -- **Models**: This is a collection of classes representing financial models. It includes everything from the standard Black-Scholes-Merton to advanced models with stochastic volatility (Heston, SABR) and jumps (Merton, Bates, Kou). Each model is a self-contained representation of a specific financial theory. +3. **Techniques**: These are the numerical algorithms used for pricing models, with bespoke Greek calculations or fallback to numerical differentiation. The separation of model (the "what") from technique (the "how") is a core design feature. The library includes: -- **Techniques**: These are the numerical or analytical algorithms used for pricing, such as Monte Carlo simulation, Fast Fourier Transform (FFT), or finite difference methods (PDEs). This design choice decouples the "what" (the model) from the "how" (the pricing algorithm), allowing you to, for example, price a Heston model using either FFT or Monte Carlo. + * Analytic closed-form solutions where available + * Pricing via the Fourier transform of the characteristic function (FFT) + * Numerical integration + * Finite difference solvers for the model’s partial differential equation (PDE) + * Binomial and trinomial lattice methods for European and American options + * A high-performance Monte Carlo engine for European and American options, accelerated with `numba` and featuring variance reduction techniques (e.g., antithetic variates, control variates, importance sampling) + * Vectorized calibration for batch pricing of option chains -- **Workflows**: These are high-level orchestrators that combine data, models, and techniques to perform complex, real-world tasks like daily model calibration or historical backtesting. They are the engines that power the command-line interface and the dashboard. +4. **Workflows & Tooling**: High-level orchestrators that combine data, models, and techniques to perform complex, real-world tasks like daily model calibration or historical backtesting. These power the command-line interface and the Streamlit dashboard. -## Our Philosophy +## Who Is This For? -The library was designed with the following principles in mind: +This library is designed for anyone interested in the intersection of finance, mathematics, and software engineering. In particular, the object-oriented design, centered around the `BaseModel` and `BaseTechnique` abstract classes, makes it straightforward to add new models or pricing methods. Benchmarks facilitate performance comparisons with existing models. -- **Speed**: For computationally intensive tasks like Monte Carlo simulation, we use `numba` to JIT-compile the core numerical kernels, resulting in performance that rivals compiled languages like C or Fortran. +--- -- **Accuracy**: Standard, well-vetted numerical algorithms are used for pricing, calibration, and root-finding, providing a reliable foundation for your analysis. - -- **Extensibility**: The object-oriented design, centered around the `BaseModel` and `BaseTechnique` abstract classes, makes it straightforward for you or other developers to add new models or pricing methods without disrupting the existing structure. - -- **Usability**: A powerful command-line interface (CLI) and an interactive Streamlit dashboard are provided for common tasks, making the library accessible to users who may not want to write Python code for every analysis. - -Ready to get started? Head over to: - -- [Getting Started](getting_started.md) -- [API Reference](../reference/atoms/index.md) -- [Interactive Dashboard](dashboard.md) +If you are ready to get started head to the [Installation guide](installation.md). diff --git a/docs/index.md b/docs/index.md index 31b54bf..22ca38c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,19 +1,152 @@ -# Welcome to optpricing +# OptPricing: A Quantitative Finance Library for Derivative Pricing and Analysis -optpricing is a Python library for pricing and calibrating financial derivatives. +`optpricing` is a Python library for pricing, calibrating, and analyzing financial derivatives. It is built with a focus on architectural clarity, model breadth, and practical usability through a robust API, command-line interface, and an interactive dashboard. -It features a rich CLI, as well as an interactive dashboard; +Diljit Singh +linkedin.com/in/singhdiljit/ + +--- + +## Core Features + +* **Model Library**: Implements a comprehensive set of models, including: + * **Stochastic Volatility**: Heston, SABR + * **Jump-Diffusion**: Merton, Bates, Kou, SABR with Jumps + * **Pure Levy Processes**: Variance Gamma (VG), Normal Inverse Gaussian (NIG), CGMY, Hyperbolic + * **Interest Rate Models**: Vasicek, Cox-Ingersoll-Ross (CIR), Put-Call Parity Implied Rate + * **Local Volatility**: Dupire's Equation + +* **Pricing Engines**: Provides a suite of numerical methods, allowing for technique comparison and validation: + * Analytic closed-form solutions + * Numerical integration and FFT-based pricing via characteristic functions + * Finite difference (PDE) solver using a Crank-Nicolson scheme + * Binomial and trinomial tree methods (CRR, TOPM, Leisen-Reimer) for European and American options + * High-performance Monte Carlo engine for European and American options, accelerated with `numba`, featuring variance reduction techniques (e.g., antithetic variates, control variates, importance sampling) + +* **Interfaces**: + * **Programmatic API**: Use the package as a Python library to build custom financial models in your scripts. Define options, stocks, rates, and models programmatically to compute prices and other metrics. + * **Command-Line Interface (CLI)**: A robust CLI for live pricing, data management, model calibration, and historical backtesting. + * **Interactive Dashboard (UI)**: A Streamlit application for visual analysis of option chains, implied volatility surfaces, and model calibrations. + +* **Workflow Automation**: High-level classes that orchestrate complex tasks like daily calibration runs and out-of-sample performance evaluation. + +--- + +## Quick Start + +`optpricing` is designed for a straightforward installation using `pip` and is compatible with Python 3.10 and higher. + +### 1. Install the Library + +```bash +pip install optpricing +``` + +### 2. Download Historical Data + +Some models require historical data (e.g., for calibration). Download data for a ticker like SPY: + +```bash +optpricing data download --ticker SPY +``` + +For more details, see the [Getting Started Guide]((guide/getting_started.md)). + +### 3. Use the CLI + +Price an option directly from the terminal. The command below fetches the live option chain for AAPL, retrieves the current dividend rate, calculates the implied risk-free rate from at-the-money contracts, and prices the contract with Heston’s model using its default pricing technique (FFT): + +```bash +optpricing price --ticker AAPL --strike 630 --maturity 2025-12-19 --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5" +``` + +To price the same contract as an American Option use: + +```bash +optpricing price -t AAPL -k 210 -T 2025-12-19 --style american --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5" +``` + +For more details, see the [CLI Guide]((guide/CLI.md)). + +### 4. Launch the Dashboard + +Visualize option chains and model outputs, interact with a pricing calculator featuring 15 models and 10 techniques. ```bash optpricing dashboard ``` -This will open a Streamlit application in your browser where you can perform calibrations, price options, and visualize results without writing any code. +For more details, see the [Dashboard Guide]((guide/dashboard.md)). + +### 5. Use the Programmatic API + +The most powerful way to use the package is via the API, which provides customization of nearly every aspect of pricing: + +```python +from optpricing import Option, OptionType, Rate, Stock, ZeroCouponBond +from optpricing.models import BSMModel, CIRModel, VasicekModel +from optpricing.techniques import ClosedFormTechnique + +# Define an option, underlying and rate +option = Option(strike=105, maturity=1.0, option_type=OptionType.CALL) +stock = Stock(spot=100, dividend=0.01) +rate = Rate(rate=0.05) + +# Choose a model and technique +bsm_model = BSMModel(params={"sigma": 0.20}) +cf_technique = ClosedFormTechnique() + +result = cf_technique.price(option, stock, bsm_model, rate) +print(f"The option price is: {result.price:.4f}") + -![optpricing Calibration Dashboard](images/calibration.png) +delta = cf_technique.delta(option, stock, bsm_model, rate) +gamma = cf_technique.gamma(option, stock, bsm_model, rate) +vega = cf_technique.vega(option, stock, bsm_model, rate) + +print(f"Delta: {delta:.4f}") +print(f"Gamma: {gamma:.4f}") +print(f"Vega: {vega:.4f}") + +target_price = 7.50 +iv = cf_technique.implied_volatility( + option, stock, bsm_model, rate, target_price=target_price +) +print(f"Implied volatility for price ${target_price:.2f}: {iv:.4%}") + + +# Zero Coupon Bond +bond = ZeroCouponBond(maturity=1.0) +r0_stock = Stock(spot=0.05) # initial short rate +dummy_rate = Rate(rate=0.0) # ignored by rate models + +vasicek = VasicekModel(params={"kappa": 0.86, "theta": 0.09, "sigma": 0.02}) +cir = CIRModel(params={"kappa": 0.86, "theta": 0.09, "sigma": 0.02}) + +p_vasi = cf_technique.price(bond, r0_stock, vasicek, dummy_rate).price +p_cir = cf_technique.price(bond, r0_stock, cir, dummy_rate).price + +print(f"Vasicek ZCB Price: {p_vasi:.4f}") +print(f"CIR ZCB Price: {p_cir:.4f}") +``` + +For more details, see the [API Guide]((guide/API.md)). --- -- [Getting Started](guide/getting_started.md) -- [API Reference](reference/atoms/index.md) -- [Interactive Dashboard](guide/dashboard.md) +## Documentation + +The full documentation includes installation instructions, user guides, examples, and a complete API reference. + +* **[View the Official Documentation](https://diljit22.github.io/quantfin/)** + +### Guides + +* [Introduction](guide/introduction.md) +* [Installation](guide/installation.md) +* [Getting Started](guide/getting_started.md) +* [CLI](guide/CLI.md) +* [Dashboard](guide/dashboard.md) +* [API](guide/API.md) +* [Examples](guide/examples.md) +* [API Reference](reference/index.md) diff --git a/docs/reference/atoms/bond.md b/docs/reference/atoms/bond.md deleted file mode 100644 index 4c684a4..0000000 --- a/docs/reference/atoms/bond.md +++ /dev/null @@ -1,3 +0,0 @@ -# ZeroCouponBond - -::: src.optpricing.atoms.bond.ZeroCouponBond diff --git a/docs/reference/atoms/index.md b/docs/reference/atoms/index.md index fa298b4..66dd7e9 100644 --- a/docs/reference/atoms/index.md +++ b/docs/reference/atoms/index.md @@ -1,8 +1,7 @@ -# Atoms Package +# Atoms -The `atoms` package provides the fundamental data structures used throughout the `optpricing` library. These classes are immutable containers that represent core financial concepts. +The `atoms` package provides the fundamental data structures used throughout +the optpricing library, representing core financial concepts like options, +stocks, and interest rates. -- **Stock**: Represents the underlying asset. -- **Option**: Represents a vanilla option contract, including its type and style. -- **Rate**: Represents the risk-free interest rate structure. -- **Bond**: Represents a simple zero-coupon bond. +::: optpricing.atoms diff --git a/docs/reference/atoms/option.md b/docs/reference/atoms/option.md deleted file mode 100644 index 23ebcbd..0000000 --- a/docs/reference/atoms/option.md +++ /dev/null @@ -1,11 +0,0 @@ -# Option - -::: src.optpricing.atoms.option.Option - -## OptionType - -::: src.optpricing.atoms.option.OptionType - -## ExerciseStyle - -::: src.optpricing.atoms.option.ExerciseStyle diff --git a/docs/reference/atoms/rate.md b/docs/reference/atoms/rate.md deleted file mode 100644 index bc57ba7..0000000 --- a/docs/reference/atoms/rate.md +++ /dev/null @@ -1,3 +0,0 @@ -# Rate - -::: src.optpricing.atoms.rate.Rate diff --git a/docs/reference/atoms/stock.md b/docs/reference/atoms/stock.md deleted file mode 100644 index 978f8ab..0000000 --- a/docs/reference/atoms/stock.md +++ /dev/null @@ -1,3 +0,0 @@ -# Stock - -::: src.optpricing.atoms.stock.Stock diff --git a/docs/reference/calibration/calibrator.md b/docs/reference/calibration/calibrator.md deleted file mode 100644 index 0311067..0000000 --- a/docs/reference/calibration/calibrator.md +++ /dev/null @@ -1,3 +0,0 @@ -# Calibrator - -::: src.optpricing.calibration.calibrator.Calibrator diff --git a/docs/reference/calibration/fit_jump_parameters.md b/docs/reference/calibration/fit_jump_parameters.md deleted file mode 100644 index c225f1c..0000000 --- a/docs/reference/calibration/fit_jump_parameters.md +++ /dev/null @@ -1,3 +0,0 @@ -# Fit Jump Parameters - -::: src.optpricing.calibration.fit_jump_parameters.fit_jump_params_from_history diff --git a/docs/reference/calibration/fit_market_params.md b/docs/reference/calibration/fit_market_params.md deleted file mode 100644 index 546e3ab..0000000 --- a/docs/reference/calibration/fit_market_params.md +++ /dev/null @@ -1,11 +0,0 @@ -# Fit Market Parameters - -This module provides utilities to fit market-implied parameters from option prices. - -### Fit Rate and Dividend - -::: src.optpricing.calibration.fit_market_params.fit_rate_and_dividend - -### Find ATM Options - -::: src.optpricing.calibration.fit_market_params.find_atm_options diff --git a/docs/reference/calibration/index.md b/docs/reference/calibration/index.md index 07024cc..b9c253d 100644 --- a/docs/reference/calibration/index.md +++ b/docs/reference/calibration/index.md @@ -1,9 +1,7 @@ -# Calibration Package +# Calibration -The `calibration` package provides a comprehensive suite of tools for fitting financial models to market data, estimating parameters from historical data, and calculating implied volatility surfaces. +The `calibration` package provides tools for fitting financial models to +market data, estimating parameters from historical data, and calculating +implied volatility surfaces. -- **Calibrator**: The main class for orchestrating the optimization process to fit model parameters to market option prices. -- **VolatilitySurface**: A class to compute and manage implied volatility surfaces from both market and model-generated prices. -- **Parameter Fitters**: Utility functions to estimate specific parameters, such as `fit_rate_and_dividend` from put-call parity or `fit_jump_params_from_history` from historical returns. -- **Technique Selector**: A helper function to automatically select the most efficient pricing technique for a given model. -- **IV Solvers**: High-performance, vectorized solvers for calculating implied volatility. +::: optpricing.calibration diff --git a/docs/reference/calibration/iv_surface.md b/docs/reference/calibration/iv_surface.md deleted file mode 100644 index 2139938..0000000 --- a/docs/reference/calibration/iv_surface.md +++ /dev/null @@ -1,3 +0,0 @@ -# Volatility Surface - -::: src.optpricing.calibration.iv_surface.VolatilitySurface diff --git a/docs/reference/calibration/technique_selector.md b/docs/reference/calibration/technique_selector.md deleted file mode 100644 index d303cb0..0000000 --- a/docs/reference/calibration/technique_selector.md +++ /dev/null @@ -1,3 +0,0 @@ -# Technique Selector - -::: src.optpricing.calibration.technique_selector.select_fastest_technique diff --git a/docs/reference/calibration/vectorized_bsm_iv.md b/docs/reference/calibration/vectorized_bsm_iv.md deleted file mode 100644 index 8d90088..0000000 --- a/docs/reference/calibration/vectorized_bsm_iv.md +++ /dev/null @@ -1,3 +0,0 @@ -# Vectorized BSM IV Solver - -::: src.optpricing.calibration.vectorized_bsm_iv.BSMIVSolver diff --git a/docs/reference/calibration/vectorized_integration_iv.md b/docs/reference/calibration/vectorized_integration_iv.md deleted file mode 100644 index 753f006..0000000 --- a/docs/reference/calibration/vectorized_integration_iv.md +++ /dev/null @@ -1,3 +0,0 @@ -# Vectorized Integration IV Solver - -::: src.optpricing.calibration.vectorized_integration_iv.VectorizedIntegrationIVSolver diff --git a/docs/reference/calibration/vectorized_pricer.md b/docs/reference/calibration/vectorized_pricer.md deleted file mode 100644 index 4b1af5c..0000000 --- a/docs/reference/calibration/vectorized_pricer.md +++ /dev/null @@ -1,3 +0,0 @@ -# Vectorized Pricer - -::: src.optpricing.calibration.vectorized_pricer.price_options_vectorized diff --git a/docs/reference/cli/backtest.md b/docs/reference/cli/backtest.md deleted file mode 100644 index 56eb0e5..0000000 --- a/docs/reference/cli/backtest.md +++ /dev/null @@ -1,5 +0,0 @@ -# Backtest Command - -This page details the `backtest` command. - -::: optpricing.cli.commands.backtest diff --git a/docs/reference/cli/calibrate.md b/docs/reference/cli/calibrate.md deleted file mode 100644 index 895435d..0000000 --- a/docs/reference/cli/calibrate.md +++ /dev/null @@ -1,5 +0,0 @@ -# Calibrate Command - -This page details the `calibrate` command. - -::: optpricing.cli.commands.calibrate diff --git a/docs/reference/cli/dashboard.md b/docs/reference/cli/dashboard.md deleted file mode 100644 index 74df090..0000000 --- a/docs/reference/cli/dashboard.md +++ /dev/null @@ -1,3 +0,0 @@ -# Dashboard - -::: optpricing.cli.commands.dashboard diff --git a/docs/reference/cli/data.md b/docs/reference/cli/data.md deleted file mode 100644 index daf2aa8..0000000 --- a/docs/reference/cli/data.md +++ /dev/null @@ -1,5 +0,0 @@ -# Data Commands - -This page details the commands available under `optpricing data`. - -::: optpricing.cli.commands.data diff --git a/docs/reference/cli/demo.md b/docs/reference/cli/demo.md deleted file mode 100644 index 904cd22..0000000 --- a/docs/reference/cli/demo.md +++ /dev/null @@ -1,6 +0,0 @@ -# Calibrate Command - -This page details the `demo` command for devs to sample -each model along with every supported technique. - -::: optpricing.cli.commands.demo diff --git a/docs/reference/cli/index.md b/docs/reference/cli/index.md index a868450..01d60a0 100644 --- a/docs/reference/cli/index.md +++ b/docs/reference/cli/index.md @@ -1,17 +1,8 @@ # Command-Line Interface (CLI) -The `optpricing` library provides a powerful command-line interface for running common tasks like data downloading, model calibration, and backtesting. +This `CLI` package contains the main entry point and command structure for +the optpricing command-line interface. -The main entry point is the `optpricing` command. You can see all available commands by running: - -```bash -optpricing --help -``` - -## Main Application - -The main `app` object serves as the entry point for all commands. - -::: optpricing.cli.main.app - :prog: optpricing - :show_ help: true +::: optpricing.cli.commands.backtest +::: optpricing.cli.commands.calibrate +::: optpricing.cli.commands.price diff --git a/docs/reference/cli/price.md b/docs/reference/cli/price.md deleted file mode 100644 index 6c1b420..0000000 --- a/docs/reference/cli/price.md +++ /dev/null @@ -1,5 +0,0 @@ -# Price Command - -This page details the `price` command. - -::: optpricing.cli.commands.price diff --git a/docs/reference/cli/tools.md b/docs/reference/cli/tools.md deleted file mode 100644 index 4d9ce2e..0000000 --- a/docs/reference/cli/tools.md +++ /dev/null @@ -1,5 +0,0 @@ -# Tools Commands - -This page details the commands available under `optpricing tools`. - -::: optpricing.cli.commands.tools diff --git a/docs/reference/dashboard/Home.md b/docs/reference/dashboard/Home.md deleted file mode 100644 index 86d8382..0000000 --- a/docs/reference/dashboard/Home.md +++ /dev/null @@ -1,3 +0,0 @@ -# Main App - -::: src.optpricing.dashboard.Home diff --git a/docs/reference/dashboard/index.md b/docs/reference/dashboard/index.md index 808db0b..d3a7d13 100644 --- a/docs/reference/dashboard/index.md +++ b/docs/reference/dashboard/index.md @@ -1,14 +1,6 @@ # Dashboard -- [Main App](Home.md) -- [Plotting Functions](plots.md) -- [Backend Service](service.md) -- [UI Widgets](widgets.md) +The `dashboard` package contains all components for the Streamlit dashboard UI, +including the main service layer, plotting functions, and UI widgets. -## Pages - -- [Pricer & Greeks](pages/1_Pricer_and_Greeks.md) -- [Calibration & IV](pages/2_Calibration_and_IV.md) -- [Market Analytics](pages/3_Market_Analytics.md) -- [Historical](pages/4_Model_Fitting.md) -- [Term Structure](pages/5_Term_Structure.md) +::: optpricing.dashboard.Home diff --git a/docs/reference/dashboard/pages/1_Pricer_and_Greeks.md b/docs/reference/dashboard/pages/1_Pricer_and_Greeks.md deleted file mode 100644 index ed1fb6c..0000000 --- a/docs/reference/dashboard/pages/1_Pricer_and_Greeks.md +++ /dev/null @@ -1,3 +0,0 @@ -# Pricer & Greeks - -::: optpricing.dashboard.pages.1_Pricer_and_Greeks diff --git a/docs/reference/dashboard/pages/2_Calibration_and_IV.md b/docs/reference/dashboard/pages/2_Calibration_and_IV.md deleted file mode 100644 index 80abcf2..0000000 --- a/docs/reference/dashboard/pages/2_Calibration_and_IV.md +++ /dev/null @@ -1,3 +0,0 @@ -# Calibration & IV - -::: optpricing.dashboard.pages.2_Calibration_and_IV diff --git a/docs/reference/dashboard/pages/3_Market_Analytics.md b/docs/reference/dashboard/pages/3_Market_Analytics.md deleted file mode 100644 index 646c337..0000000 --- a/docs/reference/dashboard/pages/3_Market_Analytics.md +++ /dev/null @@ -1,3 +0,0 @@ -# Market Analytics - -::: optpricing.dashboard.pages.3_Market_Analytics diff --git a/docs/reference/dashboard/pages/4_Model_Fitting.md b/docs/reference/dashboard/pages/4_Model_Fitting.md deleted file mode 100644 index 50db743..0000000 --- a/docs/reference/dashboard/pages/4_Model_Fitting.md +++ /dev/null @@ -1,3 +0,0 @@ -# Historical - -::: optpricing.dashboard.pages.4_Model_Fitting diff --git a/docs/reference/dashboard/pages/5_Term_Structure.md b/docs/reference/dashboard/pages/5_Term_Structure.md deleted file mode 100644 index b4c1c18..0000000 --- a/docs/reference/dashboard/pages/5_Term_Structure.md +++ /dev/null @@ -1,3 +0,0 @@ -# Term Structure - -::: optpricing.dashboard.pages.5_Term_Structure diff --git a/docs/reference/dashboard/plots.md b/docs/reference/dashboard/plots.md deleted file mode 100644 index fcaeef0..0000000 --- a/docs/reference/dashboard/plots.md +++ /dev/null @@ -1,11 +0,0 @@ -# Plotting Functions - -This module contains functions for generating visualizations used in the dashboard. - -### Volatility Smiles - -::: src.optpricing.dashboard.plots.plot_smiles_by_expiry - -### 3D Volatility Surface - -::: src.optpricing.dashboard.plots.plot_iv_surface_3d diff --git a/docs/reference/dashboard/service.md b/docs/reference/dashboard/service.md deleted file mode 100644 index 5b463e8..0000000 --- a/docs/reference/dashboard/service.md +++ /dev/null @@ -1,5 +0,0 @@ -# Backend Service - -This file contains the core service layer that drives the dashboard application. - -::: src.optpricing.dashboard.service.DashboardService diff --git a/docs/reference/dashboard/widgets.md b/docs/reference/dashboard/widgets.md deleted file mode 100644 index 03d155b..0000000 --- a/docs/reference/dashboard/widgets.md +++ /dev/null @@ -1,7 +0,0 @@ -# UI Widgets - -This module contains reusable Streamlit components for the dashboard. - -### Parity Analysis Widget - -::: src.optpricing.dashboard.widgets diff --git a/docs/reference/data/historical_manager.md b/docs/reference/data/historical_manager.md deleted file mode 100644 index d12cc24..0000000 --- a/docs/reference/data/historical_manager.md +++ /dev/null @@ -1,3 +0,0 @@ -# Historical Data Manager - -::: src.optpricing.data.historical_manager diff --git a/docs/reference/data/index.md b/docs/reference/data/index.md index f78c12c..87093c4 100644 --- a/docs/reference/data/index.md +++ b/docs/reference/data/index.md @@ -1,6 +1,6 @@ -# Data Package +# Data -The `data` package provides a unified interface for all data input/output operations. It handles fetching data from external APIs and loading/saving data to the local filesystem. +The `data` package provides a clean, unified interface for fetching, loading, +and saving all market and historical data required by the optpricing library. -- **Historical Manager**: Functions for downloading and managing historical time-series data, such as daily log returns. -- **Market Data Manager**: Functions for fetching, saving, and loading snapshots of option chain market data. \ No newline at end of file +::: optpricing.data diff --git a/docs/reference/data/market_data_manager.md b/docs/reference/data/market_data_manager.md deleted file mode 100644 index f183d94..0000000 --- a/docs/reference/data/market_data_manager.md +++ /dev/null @@ -1,3 +0,0 @@ -# Market Data Manager - -::: src.optpricing.data.market_data_manager diff --git a/docs/reference/index.md b/docs/reference/index.md new file mode 100644 index 0000000..b2222d9 --- /dev/null +++ b/docs/reference/index.md @@ -0,0 +1,77 @@ +# API Reference + +Welcome to the API Reference for **optpricing**. +Click any category below to explore its modules, classes, functions, and more. + +--- + +## Atoms + +Core **data structures** for options, stocks, rates, bonds, etc. +Immutable types that underpin every model and technique. + +- [Atoms Reference](atoms/index.md) + +--- + +## Calibration + +Tools to **fit model parameters** to market data (RMSE minimization, IV surfaces, jump fitting). + +- [Calibration Reference](calibration/index.md) + +--- + +## CLI + +The **command-line interface** entrypoint (`optpricing`), with commands for pricing, data, calibration, backtests, demos, and dashboard. + +- [CLI Reference](cli/index.md) + +--- + +## Dashboard + +Streamlit-based **interactive UI** for pricing, calibration, market analytics, and model workflows. + +- [Dashboard Reference](dashboard/index.md) + +--- + +## Data + +Managers for **live** & **historical** market data: downloading, snapshots, dividends, etc. + +- [Data Reference](data/index.md) + +--- + +## Models + +Black-Scholes, Heston, SABR, Merton-jump, and many **stochastic** and **Levy** models. + +- [Models Reference](models/index.md) + +--- + +## Parity + +Put-call parity utilities and **implied-rate** models. + +- [Parity Reference](parity/index.md) + +--- + +## Techniques + +Pricing engines: closed-form, FFT, PDE, lattices, Monte Carlo (with Greek calculation mixins). + +- [Techniques Reference](techniques/index.md) + +--- + +## Workflows + +High-level orchestrators for **daily calibration**, **backtesting**, and other batch processes. + +- [Workflows Reference](workflows/index.md) diff --git a/docs/reference/models/base/base_model.md b/docs/reference/models/base/base_model.md deleted file mode 100644 index 770047a..0000000 --- a/docs/reference/models/base/base_model.md +++ /dev/null @@ -1,3 +0,0 @@ -# BaseModel - -::: src.optpricing.models.base.base_model.BaseModel diff --git a/docs/reference/models/base/index.md b/docs/reference/models/base/index.md deleted file mode 100644 index 7e8b5fb..0000000 --- a/docs/reference/models/base/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Base Model Package - -The `base` package provides the foundational components for all financial models in the library. It ensures that all models adhere to a common interface and provides reusable tools for parameter validation. - -- **BaseModel**: An abstract base class that defines the required structure and methods for all pricing models. -- **ParamValidator**: A utility class with static methods for common parameter validation checks. \ No newline at end of file diff --git a/docs/reference/models/base/validators.md b/docs/reference/models/base/validators.md deleted file mode 100644 index 6b46bc7..0000000 --- a/docs/reference/models/base/validators.md +++ /dev/null @@ -1,3 +0,0 @@ -# ParamValidator - -::: src.optpricing.models.base.validators.ParamValidator diff --git a/docs/reference/models/bates.md b/docs/reference/models/bates.md deleted file mode 100644 index fc0f0a6..0000000 --- a/docs/reference/models/bates.md +++ /dev/null @@ -1,3 +0,0 @@ -# Bates Model - -::: src.optpricing.models.bates.BatesModel diff --git a/docs/reference/models/blacks_approx.md b/docs/reference/models/blacks_approx.md deleted file mode 100644 index 4cb36ec..0000000 --- a/docs/reference/models/blacks_approx.md +++ /dev/null @@ -1,3 +0,0 @@ -# Black's Approximation Model - -::: src.optpricing.models.blacks_approx.BlacksApproxModel diff --git a/docs/reference/models/bsm.md b/docs/reference/models/bsm.md deleted file mode 100644 index 344c3b4..0000000 --- a/docs/reference/models/bsm.md +++ /dev/null @@ -1,3 +0,0 @@ -# Black-Scholes-Merton Model - -::: src.optpricing.models.bsm.BSMModel diff --git a/docs/reference/models/cev.md b/docs/reference/models/cev.md deleted file mode 100644 index 4e4853a..0000000 --- a/docs/reference/models/cev.md +++ /dev/null @@ -1,3 +0,0 @@ -# CEV Model - -::: src.optpricing.models.cev.CEVModel diff --git a/docs/reference/models/cgmy.md b/docs/reference/models/cgmy.md deleted file mode 100644 index 3f6db75..0000000 --- a/docs/reference/models/cgmy.md +++ /dev/null @@ -1,3 +0,0 @@ -# CGMY Model - -::: src.optpricing.models.cgmy.CGMYModel diff --git a/docs/reference/models/cir.md b/docs/reference/models/cir.md deleted file mode 100644 index d63bf08..0000000 --- a/docs/reference/models/cir.md +++ /dev/null @@ -1,3 +0,0 @@ -# Cox-Ingersoll-Ross (CIR) Model - -::: src.optpricing.models.cir.CIRModel diff --git a/docs/reference/models/dupire_local.md b/docs/reference/models/dupire_local.md deleted file mode 100644 index a7fa724..0000000 --- a/docs/reference/models/dupire_local.md +++ /dev/null @@ -1,3 +0,0 @@ -# Dupire Local Volatility Model - -::: src.optpricing.models.dupire_local.DupireLocalVolModel diff --git a/docs/reference/models/heston.md b/docs/reference/models/heston.md deleted file mode 100644 index 99143c8..0000000 --- a/docs/reference/models/heston.md +++ /dev/null @@ -1,3 +0,0 @@ -# Heston Model - -::: src.optpricing.models.heston.HestonModel diff --git a/docs/reference/models/hyperbolic.md b/docs/reference/models/hyperbolic.md deleted file mode 100644 index 4f52c11..0000000 --- a/docs/reference/models/hyperbolic.md +++ /dev/null @@ -1,3 +0,0 @@ -# Hyperbolic Model - -::: src.optpricing.models.hyperbolic.HyperbolicModel diff --git a/docs/reference/models/index.md b/docs/reference/models/index.md index e4f0dc2..538f45a 100644 --- a/docs/reference/models/index.md +++ b/docs/reference/models/index.md @@ -1,12 +1,9 @@ -# Models Package +# Models -The `models` package contains all the financial pricing models available in the library. Each model is a concrete implementation of the `BaseModel` abstract class. +The `models` package contains all financial models for valuing options and rates. -The models can be broadly categorized: +It provides the abstract `BaseModel` and a suite of concrete implementations, +from the standard Black-Scholes-Merton to advanced stochastic volatility +and jump-diffusion models. -- **Standard Models**: Foundational models like Black-Scholes-Merton. -- **Stochastic Volatility**: Models where volatility is its own random process, such as Heston and SABR. -- **Jump-Diffusion**: Models that incorporate sudden jumps in the asset price, like Merton's Jump-Diffusion and Kou's Double-Exponential model. -- **Pure Levy**: Models based on Levy processes, such as Variance Gamma (VG), Normal Inverse Gaussian (NIG), and CGMY. - -For developers looking to implement new models, please see the **[Base Classes](./base/index.md)** documentation. \ No newline at end of file +::: optpricing.models diff --git a/docs/reference/models/kou.md b/docs/reference/models/kou.md deleted file mode 100644 index 6cb1434..0000000 --- a/docs/reference/models/kou.md +++ /dev/null @@ -1,3 +0,0 @@ -# Kou Model - -::: src.optpricing.models.kou.KouModel diff --git a/docs/reference/models/merton_jump.md b/docs/reference/models/merton_jump.md deleted file mode 100644 index ebdb5d2..0000000 --- a/docs/reference/models/merton_jump.md +++ /dev/null @@ -1,3 +0,0 @@ -# Merton Jump-Diffusion Model - -::: src.optpricing.models.merton_jump.MertonJumpModel diff --git a/docs/reference/models/nig.md b/docs/reference/models/nig.md deleted file mode 100644 index c5f36c4..0000000 --- a/docs/reference/models/nig.md +++ /dev/null @@ -1,3 +0,0 @@ -# Normal Inverse Gaussian (NIG) Model - -::: src.optpricing.models.nig.NIGModel diff --git a/docs/reference/models/perpetual_put.md b/docs/reference/models/perpetual_put.md deleted file mode 100644 index 9f089fd..0000000 --- a/docs/reference/models/perpetual_put.md +++ /dev/null @@ -1,3 +0,0 @@ -# Perpetual Put Model - -::: src.optpricing.models.perpetual_put.PerpetualPutModel diff --git a/docs/reference/models/sabr.md b/docs/reference/models/sabr.md deleted file mode 100644 index 009f62e..0000000 --- a/docs/reference/models/sabr.md +++ /dev/null @@ -1,3 +0,0 @@ -# SABR Model - -::: src.optpricing.models.sabr.SABRModel diff --git a/docs/reference/models/sabr_jump.md b/docs/reference/models/sabr_jump.md deleted file mode 100644 index 5f53ee4..0000000 --- a/docs/reference/models/sabr_jump.md +++ /dev/null @@ -1,3 +0,0 @@ -# SABR with Jumps Model - -::: src.optpricing.models.sabr_jump.SABRJumpModel diff --git a/docs/reference/models/vasicek.md b/docs/reference/models/vasicek.md deleted file mode 100644 index a93814c..0000000 --- a/docs/reference/models/vasicek.md +++ /dev/null @@ -1,3 +0,0 @@ -# Vasicek Model - -::: src.optpricing.models.vasicek.VasicekModel diff --git a/docs/reference/models/vg.md b/docs/reference/models/vg.md deleted file mode 100644 index 321725f..0000000 --- a/docs/reference/models/vg.md +++ /dev/null @@ -1,3 +0,0 @@ -# Variance Gamma (VG) Model - -::: src.optpricing.models.vg.VarianceGammaModel diff --git a/docs/reference/parity/implied_rate.md b/docs/reference/parity/implied_rate.md deleted file mode 100644 index 45e0421..0000000 --- a/docs/reference/parity/implied_rate.md +++ /dev/null @@ -1,3 +0,0 @@ -# Implied Rate Model - -::: src.optpricing.parity.implied_rate.ImpliedRateModel diff --git a/docs/reference/parity/index.md b/docs/reference/parity/index.md index 5e4358f..df66894 100644 --- a/docs/reference/parity/index.md +++ b/docs/reference/parity/index.md @@ -1,6 +1,5 @@ -# Parity Package +# Parity -The `parity` package provides models and utilities based on the principles of put-call parity. +The `parity` package provides models and utilities based on put-call parity. -- **Parity Model**: A utility to calculate the price of a complementary option (e.g., a put from a call) based on the parity relationship. -- **Implied Rate Model**: A model to solve for the risk-free interest rate that is implied by the market prices of a put-call pair. \ No newline at end of file +::: optpricing.parity diff --git a/docs/reference/parity/parity_model.md b/docs/reference/parity/parity_model.md deleted file mode 100644 index be3f479..0000000 --- a/docs/reference/parity/parity_model.md +++ /dev/null @@ -1,3 +0,0 @@ -# Parity Model - -::: src.optpricing.parity.parity_model.ParityModel diff --git a/docs/reference/techniques/american_monte_carlo.md b/docs/reference/techniques/american_monte_carlo.md deleted file mode 100644 index 526c24b..0000000 --- a/docs/reference/techniques/american_monte_carlo.md +++ /dev/null @@ -1,3 +0,0 @@ -# Monte Carlo Technique (American) - -::: src.optpricing.techniques.american_monte_carlo.AmericanMonteCarloTechnique diff --git a/docs/reference/techniques/base/base_technique.md b/docs/reference/techniques/base/base_technique.md deleted file mode 100644 index 1f45296..0000000 --- a/docs/reference/techniques/base/base_technique.md +++ /dev/null @@ -1,3 +0,0 @@ -# BaseTechnique - -::: src.optpricing.techniques.base.base_technique.BaseTechnique diff --git a/docs/reference/techniques/base/greek_mixin.md b/docs/reference/techniques/base/greek_mixin.md deleted file mode 100644 index 0e1e303..0000000 --- a/docs/reference/techniques/base/greek_mixin.md +++ /dev/null @@ -1,3 +0,0 @@ -# GreekMixin - -::: src.optpricing.techniques.base.greek_mixin.GreekMixin diff --git a/docs/reference/techniques/base/index.md b/docs/reference/techniques/base/index.md deleted file mode 100644 index 6c0346a..0000000 --- a/docs/reference/techniques/base/index.md +++ /dev/null @@ -1,10 +0,0 @@ -# Base Technique Package - -This package contains the foundational abstract classes and helper mixins for all pricing techniques. - -- **BaseTechnique**: The abstract base class that all pricing techniques must inherit from. -- **LatticeTechnique**: A specialized abstract base class for all tree-based methods, providing common logic for Greek calculations. -- **GreekMixin**: Provides default numerical implementations for option Greeks (Delta, Gamma, Vega, Theta, Rho). -- **IVMixin**: Provides a default implementation for calculating implied volatility. -- **PricingResult**: A simple data container for returning pricing results. -- **RandomUtils**: Utilities for generating correlated random numbers for Monte Carlo simulations. \ No newline at end of file diff --git a/docs/reference/techniques/base/iv_mixin.md b/docs/reference/techniques/base/iv_mixin.md deleted file mode 100644 index 3b36682..0000000 --- a/docs/reference/techniques/base/iv_mixin.md +++ /dev/null @@ -1,3 +0,0 @@ -# IVMixin - -::: src.optpricing.techniques.base.iv_mixin.IVMixin diff --git a/docs/reference/techniques/base/lattice_technique.md b/docs/reference/techniques/base/lattice_technique.md deleted file mode 100644 index 457f25e..0000000 --- a/docs/reference/techniques/base/lattice_technique.md +++ /dev/null @@ -1,3 +0,0 @@ -# LatticeTechnique - -::: src.optpricing.techniques.base.lattice_technique.LatticeTechnique diff --git a/docs/reference/techniques/base/pricing_result.md b/docs/reference/techniques/base/pricing_result.md deleted file mode 100644 index c1efc22..0000000 --- a/docs/reference/techniques/base/pricing_result.md +++ /dev/null @@ -1,3 +0,0 @@ -# PricingResult - -::: src.optpricing.techniques.base.pricing_result.PricingResult diff --git a/docs/reference/techniques/base/random_utils.md b/docs/reference/techniques/base/random_utils.md deleted file mode 100644 index 31acb09..0000000 --- a/docs/reference/techniques/base/random_utils.md +++ /dev/null @@ -1,3 +0,0 @@ -# RandomUtils - -::: src.optpricing.techniques.base.random_utils diff --git a/docs/reference/techniques/closed_form.md b/docs/reference/techniques/closed_form.md deleted file mode 100644 index 93c39c8..0000000 --- a/docs/reference/techniques/closed_form.md +++ /dev/null @@ -1,3 +0,0 @@ -# Closed-Form Technique - -::: src.optpricing.techniques.closed_form.ClosedFormTechnique diff --git a/docs/reference/techniques/crr.md b/docs/reference/techniques/crr.md deleted file mode 100644 index 203bb32..0000000 --- a/docs/reference/techniques/crr.md +++ /dev/null @@ -1,3 +0,0 @@ -# CRR (Cox-Ross-Rubinstein) Technique - -::: src.optpricing.techniques.crr.CRRTechnique diff --git a/docs/reference/techniques/fft.md b/docs/reference/techniques/fft.md deleted file mode 100644 index cfeef83..0000000 --- a/docs/reference/techniques/fft.md +++ /dev/null @@ -1,3 +0,0 @@ -# FFT (Fast Fourier Transform) Technique - -::: src.optpricing.techniques.fft.FFTTechnique diff --git a/docs/reference/techniques/index.md b/docs/reference/techniques/index.md index affb05c..718c831 100644 --- a/docs/reference/techniques/index.md +++ b/docs/reference/techniques/index.md @@ -1,13 +1,6 @@ -# Techniques Package +# Techniques -The `techniques` package provides the various numerical and analytical methods used to price options and calculate their sensitivities (Greeks). +The `techniques` package provides the various numerical and analytical +methods for pricing options. -Each technique is a concrete implementation of the `BaseTechnique` class and is designed to work with one or more financial models from the `models` package. - -- **Analytical Methods**: `ClosedFormTechnique` for models with exact solutions. -- **Transform Methods**: `FFTTechnique` and `IntegrationTechnique` for models with a known characteristic function. -- **Tree-Based Methods**: `CRRTechnique`, `LeisenReimerTechnique`, and `TOPMTechnique` for lattice-based pricing. -- **Simulation Methods**: `MonteCarloTechnique` for path-based simulation. -- **Numerical PDE Solvers**: `PDETechnique` for solving the pricing partial differential equation. - -For developers, the foundational components are defined in the **[Base Technique](./base/index.md)** section, and select numerical implementations are in the **[Kernels](./kernels/index.md)** section. \ No newline at end of file +::: optpricing.techniques diff --git a/docs/reference/techniques/integration.md b/docs/reference/techniques/integration.md deleted file mode 100644 index 3330da1..0000000 --- a/docs/reference/techniques/integration.md +++ /dev/null @@ -1,3 +0,0 @@ -# Integration Technique - -::: src.optpricing.techniques.integration.IntegrationTechnique diff --git a/docs/reference/techniques/kernels/american_mc_kernels.md b/docs/reference/techniques/kernels/american_mc_kernels.md deleted file mode 100644 index dd0c6cb..0000000 --- a/docs/reference/techniques/kernels/american_mc_kernels.md +++ /dev/null @@ -1,5 +0,0 @@ -# Longstaff-Schwartz Algorithm (Paths) - -This module contains JIT-compiled (`numba`) kernels for simulating the SDE paths of different financial models. - -::: src.optpricing.techniques.kernels.american_mc_kernels diff --git a/docs/reference/techniques/kernels/index.md b/docs/reference/techniques/kernels/index.md deleted file mode 100644 index 9728ba0..0000000 --- a/docs/reference/techniques/kernels/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Kernels Package - -This package contains the low-level, high-performance numerical implementations that power the pricing techniques. These functions are designed to be pure and operate on primitive data types, making them ideal for JIT-compilation with `numba`. - -- **Lattice Kernels**: The core tree-building and backward-induction logic for binomial and trinomial models. -- **MC Kernels**: JIT-compiled functions for simulating the stochastic differential equations (SDEs) of various models. \ No newline at end of file diff --git a/docs/reference/techniques/kernels/lattice_kernels.md b/docs/reference/techniques/kernels/lattice_kernels.md deleted file mode 100644 index 83a667d..0000000 --- a/docs/reference/techniques/kernels/lattice_kernels.md +++ /dev/null @@ -1,5 +0,0 @@ -# Lattice Kernels - -This module contains the implementations for various lattice-based option pricing algorithms. - -::: src.optpricing.techniques.kernels.lattice_kernels diff --git a/docs/reference/techniques/kernels/mc_kernels.md b/docs/reference/techniques/kernels/mc_kernels.md deleted file mode 100644 index ce70347..0000000 --- a/docs/reference/techniques/kernels/mc_kernels.md +++ /dev/null @@ -1,5 +0,0 @@ -# Monte Carlo Kernels - -This module contains JIT-compiled (`numba`) kernels for simulating the SDE paths of different financial models. - -::: src.optpricing.techniques.kernels.mc_kernels diff --git a/docs/reference/techniques/kernels/path_kernels.md b/docs/reference/techniques/kernels/path_kernels.md deleted file mode 100644 index cfcdd0b..0000000 --- a/docs/reference/techniques/kernels/path_kernels.md +++ /dev/null @@ -1,5 +0,0 @@ -# Monte Carlo Kernels (Paths) - -This module contains JIT-compiled (`numba`) kernels for simulating the SDE paths of different financial models. - -::: src.optpricing.techniques.kernels.path_kernels diff --git a/docs/reference/techniques/leisen_reimer.md b/docs/reference/techniques/leisen_reimer.md deleted file mode 100644 index 692f200..0000000 --- a/docs/reference/techniques/leisen_reimer.md +++ /dev/null @@ -1,3 +0,0 @@ -# Leisen-Reimer Technique - -::: src.optpricing.techniques.leisen_reimer.LeisenReimerTechnique diff --git a/docs/reference/techniques/monte_carlo.md b/docs/reference/techniques/monte_carlo.md deleted file mode 100644 index f0400fa..0000000 --- a/docs/reference/techniques/monte_carlo.md +++ /dev/null @@ -1,3 +0,0 @@ -# Monte Carlo Technique - -::: src.optpricing.techniques.monte_carlo.MonteCarloTechnique diff --git a/docs/reference/techniques/pde.md b/docs/reference/techniques/pde.md deleted file mode 100644 index 4de774d..0000000 --- a/docs/reference/techniques/pde.md +++ /dev/null @@ -1,3 +0,0 @@ -# PDE (Finite Difference) Technique - -::: src.optpricing.techniques.pde.PDETechnique diff --git a/docs/reference/techniques/topm.md b/docs/reference/techniques/topm.md deleted file mode 100644 index 84f770b..0000000 --- a/docs/reference/techniques/topm.md +++ /dev/null @@ -1,3 +0,0 @@ -# TOPM (Trinomial Option Pricing Model) Technique - -::: src.optpricing.techniques.topm.TOPMTechnique diff --git a/docs/reference/workflows/backtest_workflow.md b/docs/reference/workflows/backtest_workflow.md deleted file mode 100644 index bb54edc..0000000 --- a/docs/reference/workflows/backtest_workflow.md +++ /dev/null @@ -1,3 +0,0 @@ -# Backtest Workflow - -::: src.optpricing.workflows.backtest_workflow.BacktestWorkflow diff --git a/docs/reference/workflows/daily_workflow.md b/docs/reference/workflows/daily_workflow.md deleted file mode 100644 index c77e249..0000000 --- a/docs/reference/workflows/daily_workflow.md +++ /dev/null @@ -1,3 +0,0 @@ -# Daily Workflow - -::: src.optpricing.workflows.daily_workflow.DailyWorkflow diff --git a/docs/reference/workflows/index.md b/docs/reference/workflows/index.md index 4769c1f..625f5c9 100644 --- a/docs/reference/workflows/index.md +++ b/docs/reference/workflows/index.md @@ -1,10 +1,6 @@ -# Workflows Package +# Workflows -The `workflows` package provides high-level classes that orchestrate complex, multi-step processes. These are the primary engines for running calibrations and backtests. +The `workflows` package provides high-level classes that orchestrate +multi-step processes like daily model calibration and historical backtesting. -The workflows are designed to be driven by a user interface, such as the command-line interface or the Streamlit dashboard. - -- **DailyWorkflow**: Encapsulates the logic for calibrating a model on a single day's market data. -- **BacktestWorkflow**: Manages the process of running a `DailyWorkflow` over a series of historical dates to evaluate a model's out-of-sample performance. - -This package also contains a `configs` sub-package, which holds the specific "recipes" (initial parameters, bounds, etc.) for calibrating each supported financial model. \ No newline at end of file +::: optpricing.workflows diff --git a/mkdocs.yml b/mkdocs.yml index 9952043..4a89211 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -36,6 +36,8 @@ plugins: - mkdocstrings: handlers: python: + paths: + - src options: docstring_style: numpy show_signature_annotations: true @@ -68,102 +70,17 @@ nav: - Introduction: guide/introduction.md - Installation: guide/installation.md - Getting Started: guide/getting_started.md + - API: guide/API.md + - CLI: guide/CLI.md - Dashboard: guide/dashboard.md + - Examples: guide/examples.md - API Reference: - - Atoms: - - reference/atoms/index.md - - Bond: reference/atoms/bond.md - - Option: reference/atoms/option.md - - Rate: reference/atoms/rate.md - - Stock: reference/atoms/stock.md - - Calibration: - - reference/calibration/index.md - - Calibrator: reference/calibration/calibrator.md - - Jump Parameter Fitting: reference/calibration/fit_jump_parameters.md - - Market Parameter Fitting: reference/calibration/fit_market_params.md - - IV Surface: reference/calibration/iv_surface.md - - Technique Selector: reference/calibration/technique_selector.md - - Vectorized BSM IV: reference/calibration/vectorized_bsm_iv.md - - Vectorized Integration IV: reference/calibration/vectorized_integration_iv.md - - Vectorized Pricer: reference/calibration/vectorized_pricer.md - - CLI: - - reference/cli/index.md - - Backtest: reference/cli/backtest.md - - Calibrate: reference/cli/calibrate.md - - Dashboard: reference/cli/dashboard.md - - Data: reference/cli/data.md - - Demo: reference/cli/demo.md - - Price: reference/cli/price.md - - Tools: reference/cli/tools.md - - Dashboard: - - reference/dashboard/index.md - - Main App (Home.py): reference/dashboard/Home.md - - Plotting Functions: reference/dashboard/plots.md - - Backend Service: reference/dashboard/service.md - - UI Widgets: reference/dashboard/widgets.md - - Pages: - - Pricer & Greeks: reference/dashboard/pages/1_Pricer_and_Greeks.md - - Calibration & IV: reference/dashboard/pages/2_Calibration_and_IV.md - - Market Analytics: reference/dashboard/pages/3_Market_Analytics.md - - Historical: reference/dashboard/pages/4_Model_Fitting.md - - Term Structure: reference/dashboard/pages/5_Term_Structure.md - - Data: - - reference/data/index.md - - Historical Manager: reference/data/historical_manager.md - - Market Data Manager: reference/data/market_data_manager.md - - Models: - - reference/models/index.md - - Base Classes: - - reference/models/base/index.md - - BaseModel: reference/models/base/base_model.md - - ParamValidator: reference/models/base/validators.md - - Bates: reference/models/bates.md - - Black's Approximation: reference/models/blacks_approx.md - - Black-Scholes-Merton: reference/models/bsm.md - - CEV (Constant Elasticity of Variance): reference/models/cev.md - - CGMY: reference/models/cgmy.md - - CIR (Cox-Ingersoll-Ross): reference/models/cir.md - - Dupire Local: reference/models/dupire_local.md - - Heston: reference/models/heston.md - - Hyperbolic: reference/models/hyperbolic.md - - Kou: reference/models/kou.md - - Merton Jump Diffusion: reference/models/merton_jump.md - - NIG (Normal Inverse Gaussian): reference/models/nig.md - - Perpetual Put: reference/models/perpetual_put.md - - SABR: reference/models/sabr.md - - SABR Jump: reference/models/sabr_jump.md - - Vasicek: reference/models/vasicek.md - - VG (Variance Gamma): reference/models/vg.md - - Parity: - - reference/parity/index.md - - Implied Rate: reference/parity/implied_rate.md - - Parity Model: reference/parity/parity_model.md - - Techniques: - - reference/techniques/index.md - - Base Technique: - - reference/techniques/base/index.md - - Base Technique: reference/techniques/base/base_technique.md - - GreekMixin: reference/techniques/base/greek_mixin.md - - IVMixin: reference/techniques/base/iv_mixin.md - - Lattice Technique: reference/techniques/base/lattice_technique.md - - PricingResult: reference/techniques/base/pricing_result.md - - RandomUtils: reference/techniques/base/random_utils.md - - Kernels: - - reference/techniques/kernels/index.md - - Longstaff-Schwartz: reference/techniques/kernels/american_mc_kernels.md - - Lattice Kernels: reference/techniques/kernels/lattice_kernels.md - - MC Kernels: reference/techniques/kernels/mc_kernels.md - - Path Kernels: reference/techniques/kernels/path_kernels.md - - Closed Form: reference/techniques/closed_form.md - - CRR (Cox-Ross-Rubinstein): reference/techniques/crr.md - - FFT (Fast Fourier Transform): reference/techniques/fft.md - - Integration: reference/techniques/integration.md - - Leisen-Reimer: reference/techniques/leisen_reimer.md - - Monte Carlo (European): reference/techniques/monte_carlo.md - - Monte Carlo (American): reference/techniques/american_monte_carlo.md - - PDE (Finite Difference): reference/techniques/pde.md - - TOPM (Trinomial Option Pricing Model): reference/techniques/topm.md - - Workflows: - - reference/workflows/index.md - - Daily Workflow: reference/workflows/daily_workflow.md - - Backtest Workflow: reference/workflows/backtest_workflow.md + - Atoms: reference/atoms/index.md + - Calibration: reference/calibration/index.md + - CLI: reference/cli/index.md + - Dashboard: reference/dashboard/index.md + - Data: reference/data/index.md + - Models: reference/models/index.md + - Parity: reference/parity/index.md + - Techniques: reference/techniques/index.md + - Workflows: reference/workflows/index.md diff --git a/pyproject.toml b/pyproject.toml index 782f853..c7c06ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,5 +93,5 @@ skip-magic-trailing-comma = false [tool.pytest.ini_options] minversion = "6.0" -addopts = "-ra -q --cov=src/optpricing --cov-report=term-missing" +addopts = "-ra -q --cov=src/optpricing --cov-report=term-missing --cov-config=.coveragerc" testpaths = ["tests"] diff --git a/src/optpricing/cli/__init__.py b/src/optpricing/cli/__init__.py index ada1f05..0798552 100644 --- a/src/optpricing/cli/__init__.py +++ b/src/optpricing/cli/__init__.py @@ -1,8 +1,8 @@ from __future__ import annotations __doc__ = """ -This package contains the main entry point and command structure for the -optpricing command-line interface. +This `CLI` package contains the main entry point and command structure for +the optpricing command-line interface. """ from .main import app diff --git a/src/optpricing/dashboard/__init__.py b/src/optpricing/dashboard/__init__.py index 413851b..d6e3a2b 100644 --- a/src/optpricing/dashboard/__init__.py +++ b/src/optpricing/dashboard/__init__.py @@ -1,7 +1,7 @@ from __future__ import annotations __doc__ = """ -This package contains all components for the Streamlit dashboard UI, +The `dashboard` package contains all components for the Streamlit dashboard UI, including the main service layer, plotting functions, and UI widgets. """ diff --git a/src/optpricing/models/__init__.py b/src/optpricing/models/__init__.py index ac7e44a..ec4e975 100644 --- a/src/optpricing/models/__init__.py +++ b/src/optpricing/models/__init__.py @@ -1,7 +1,7 @@ from __future__ import annotations __doc__ = """ -The `models` package contains all financial models for option pricing. +The `models` package contains all financial models for valuing options and rates. It provides the abstract `BaseModel` and a suite of concrete implementations, from the standard Black-Scholes-Merton to advanced stochastic volatility