Metadata-Version: 2.4
Name: polars-greeks
Version: 0.1.1
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Rust
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Operating System :: OS Independent
Requires-Dist: polars>=0.20.0
Requires-Dist: pytest>=6.0 ; extra == 'test'
Requires-Dist: numpy>=1.20.0 ; extra == 'test'
Provides-Extra: test
Summary: High-performance Black-Scholes options pricing and Greeks calculation plugin for Polars
Keywords: polars,options,black-scholes,greeks,finance,quantitative,rust
Author: derek.jiao
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/jiaojing/polars-greeks
Project-URL: Repository, https://github.com/jiaojing/polars-greeks
Project-URL: Issues, https://github.com/jiaojing/polars-greeks/issues

# polars-greeks

High-performance Black-Scholes options pricing and Greeks calculation plugin for Polars.

Built with Rust for maximum performance, providing both DataFrame batch processing and scalar calculation interfaces.

## Features

- 🚀 **High Performance**: Rust implementation with zero-copy data processing
- 📊 **Dual API**: DataFrame batch processing + scalar direct calculation  
- 🎯 **Complete Greeks**: Delta, Gamma, Theta, Vega, Rho, Vanna, Volga, Charm, Speed, Zomma
- 💾 **Memory Efficient**: Pre-allocated vectors, avoid unnecessary computations
- ✅ **Well Tested**: Comprehensive test suite with mathematical accuracy validation

## Quick Start

### Installation

```bash
pip install polars-greeks
```

### DataFrame Batch Processing

```python
import polars as pl
import polars_greeks as greeks

df = pl.DataFrame({
    "spot": [100.0, 105.0, 95.0],
    "strike": [100.0, 100.0, 100.0],
    "time_to_expiry": [0.25, 0.25, 0.25], 
    "volatility": [0.2, 0.2, 0.2],
    "is_call": [True, False, True]
})

result = df.select(
    greeks.df(
        pl.col("spot"),
        strike=pl.col("strike"),
        time_to_expiry=pl.col("time_to_expiry"),
        volatility=pl.col("volatility"),
        r=pl.lit(0.05),
        q=pl.lit(0.0),
        is_call=pl.col("is_call"),
        greeks=["delta", "vega", "gamma", "theta"]
    ).alias("greeks_result")
).select(
    pl.col("greeks_result").struct.field("delta").alias("delta"),
    pl.col("greeks_result").struct.field("vega").alias("vega"),
    pl.col("greeks_result").struct.field("gamma").alias("gamma"),
    pl.col("greeks_result").struct.field("theta").alias("theta")
)
```

### Scalar Direct Calculation

```python
import polars_greeks as greeks

result = greeks.scalar(
    spot=100.0,
    strike=100.0,
    time_to_expiry=0.25,
    volatility=0.2,
    r=0.05,
    q=0.0,
    is_call=True,
    greeks=["delta", "vega", "gamma"]
)

print(result)
# {'delta': 0.56, 'vega': 19.8, 'gamma': 0.019}
```

## Supported Greeks

- **delta**: Price sensitivity to underlying asset price changes
- **gamma**: Delta sensitivity to underlying asset price changes  
- **theta**: Price sensitivity to time decay
- **vega**: Price sensitivity to volatility changes
- **rho**: Price sensitivity to interest rate changes
- **vanna**: Delta sensitivity to volatility changes
- **volga**: Vega sensitivity to volatility changes  
- **charm**: Delta sensitivity to time decay
- **speed**: Gamma sensitivity to underlying asset price changes
- **zomma**: Gamma sensitivity to volatility changes

## Performance

- **Zero-copy processing**: Direct operations on Polars Series
- **Batch optimization**: Single pass calculation of multiple Greeks
- **Selective computation**: Only calculate requested Greeks
- **Memory efficient**: Pre-allocated vectors, no unnecessary allocations

Typical performance: **100K+ calculations per second** for multiple Greeks.

## Requirements

- Python ≥ 3.8
- Polars ≥ 0.20.0

## License

MIT
