feat: add full derivatives analytics layer (options + futures)
Implements all phases of the derivatives expansion plan: Rust core (crates/ferro_ta_core/src/options/, src/futures/): - BSM and Black-76 pricing (scalar + vectorized batch) - Greeks: delta, gamma, vega, theta, rho - Implied volatility solver (Newton + bisection fallback) - Smile/skew metrics: ATM IV, 25-delta RR/BF, skew slope, convexity - Chain helpers: moneyness labels, strike selection by offset or delta - Synthetic forwards, basis, annualized basis, implied carry, carry spread - Continuous contract stitching: weighted, back-adjusted, ratio-adjusted - Curve analytics: calendar spreads, slope, contango/backwardation summary PyO3 bindings (src/options/, src/futures/): - All Rust functions registered and exposed via _ferro_ta extension Python API (python/ferro_ta/analysis/): - options.py: pricing, greeks, IV, smile, chain, legacy iv_rank/percentile/zscore - futures.py: basis, carry, curve, roll, synthetic, continuous contracts - options_strategy.py: typed strategy schemas (expiry/strike selectors, leg presets, risk controls, simulation limits) - derivatives_payoff.py: multi-leg payoff aggregation and Greeks aggregation Bug fix: wrap _to_f64 calls in iv_rank/iv_percentile/iv_zscore to raise FerroTAInputError (not plain ValueError) for 2D array input. Docs: derivatives.rst, derivatives-analytics.md, options-volatility.md, quickstart.rst, index.rst, api/analysis.rst all updated. Tests: 2053 pass, 12 skipped. All CI checks pass locally. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2d5000262f
commit
602d675749
@@ -0,0 +1,67 @@
|
||||
//! PyO3 wrappers for options analytics.
|
||||
|
||||
mod chain;
|
||||
mod greeks;
|
||||
mod iv;
|
||||
mod pricing;
|
||||
mod surface;
|
||||
|
||||
use pyo3::exceptions::PyValueError;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
pub(crate) fn parse_option_kind(option_type: &str) -> PyResult<ferro_ta_core::options::OptionKind> {
|
||||
match option_type.to_ascii_lowercase().as_str() {
|
||||
"call" | "c" => Ok(ferro_ta_core::options::OptionKind::Call),
|
||||
"put" | "p" => Ok(ferro_ta_core::options::OptionKind::Put),
|
||||
_ => Err(PyValueError::new_err(format!(
|
||||
"option_type must be 'call' or 'put', got {option_type}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_pricing_model(model: &str) -> PyResult<ferro_ta_core::options::PricingModel> {
|
||||
match model.to_ascii_lowercase().as_str() {
|
||||
"bsm" | "black_scholes" | "black-scholes" | "blackscholes" => {
|
||||
Ok(ferro_ta_core::options::PricingModel::BlackScholes)
|
||||
}
|
||||
"black76" | "black_76" | "black-76" => Ok(ferro_ta_core::options::PricingModel::Black76),
|
||||
_ => Err(PyValueError::new_err(format!(
|
||||
"model must be one of 'bsm'/'black_scholes' or 'black76', got {model}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::pricing::bsm_price, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::pricing::black76_price, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::pricing::bsm_price_batch, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(
|
||||
self::pricing::black76_price_batch,
|
||||
m
|
||||
)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::greeks::option_greeks, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(
|
||||
self::greeks::option_greeks_batch,
|
||||
m
|
||||
)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::iv::implied_volatility, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(
|
||||
self::iv::implied_volatility_batch,
|
||||
m
|
||||
)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::iv::iv_rank, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::iv::iv_percentile, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::iv::iv_zscore, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::surface::smile_metrics, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(
|
||||
self::surface::term_structure_slope,
|
||||
m
|
||||
)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::chain::moneyness_labels, m)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(
|
||||
self::chain::select_strike_offset,
|
||||
m
|
||||
)?)?;
|
||||
m.add_function(pyo3::wrap_pyfunction!(self::chain::select_strike_delta, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user