1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Implied volatility calculation from OrderBook data.
//!
//! This module provides functionality to calculate implied volatility (IV)
//! from option prices extracted from the order book using Black-Scholes
//! model inversion via Newton-Raphson numerical method.
//!
//! # Overview
//!
//! Implied Volatility (IV) is the option's "price" translated into different units.
//! The price of an option in USD and the IV in % are the same information in different units.
//!
//! # Price Extraction
//!
//! For a specific strike and expiry, the orderbook provides:
//! - Best bid (e.g., $4.50)
//! - Best ask (e.g., $4.70)
//!
//! The "market price" is typically the mid-price: `(bid + ask) / 2 = $4.60`
//!
//! # Black-Scholes Inversion
//!
//! Since there's no analytical solution to invert Black-Scholes, we use
//! Newton-Raphson root finding which converges quickly (3-5 iterations)
//! because vega (∂price/∂σ) is always positive.
//!
//! # Example
//!
//! ```ignore
//! use orderbook_rs::implied_volatility::{IVParams, OptionType, PriceSource};
//!
//! let params = IVParams {
//! spot: 3000.0,
//! strike: 3000.0,
//! time_to_expiry: 30.0 / 365.0,
//! risk_free_rate: 0.0,
//! option_type: OptionType::Call,
//! };
//!
//! let result = book.implied_volatility(¶ms, PriceSource::MidPrice)?;
//! println!("IV: {:.2}%", result.iv * 100.0);
//! ```
pub use BlackScholes;
pub use IVError;
pub use IVConfig;
pub use ;
pub use ;