Metadata-Version: 2.4
Name: QuantMission
Version: 0.0.1a2
Summary: Mission-Grade Analytics, engineered for Quants.
Author-email: QuantMission <contact@quantmission.com>
License: MIT
Project-URL: Homepage, https://www.quantmission.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Education
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: yfinance
Requires-Dist: pandas
Requires-Dist: requests
Requires-Dist: xlwings
Requires-Dist: xlrd
Dynamic: license-file

# QuantMission

[![PyPI version](https://img.shields.io/pypi/v/QuantMission.svg)](https://pypi.org/project/QuantMission/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)

**Mission-Grade Analytics, engineered for Quants.**

QuantMission is an open-core quantitative platform engineered specifically for the Brazilian market. This library serves as the official client and local analytics engine, purpose-built to handle the unique mechanics of Brazilian finance.

*Note: This package is currently in Alpha. It serves as an early release while the engine analytics is under development.*

## Key Features

*   **Automated Yield Curve Parsing:** Automatically downloads, extracts, and parses the daily official `TaxaSwap.txt` (DI x Pré) directly from the B3 exchange to calculate precise forward rates.
*   **Anbima Holiday Integration:** Auto-fetches and caches the official Anbima national holiday calendar to calculate exact business days (`dias úteis`) to maturity.
*   **Bulletproof Volatility Engine:** Calculates standard Yang-Zhang volatility via `yfinance`, featuring a built-in, silent fallback to raw Yahoo Finance REST APIs to bypass library outages and missing data.
*   **Comprehensive Greeks & Valuation:** Calculates Black-Scholes theoretical pricing, Intrinsic Value, Time Value, and first/second-order Greeks (Delta, Gamma, Theta, Vega, Rho).
*   **Excel Ready:** Built from the ground up to integrate seamlessly with `xlwings` for instantaneous spreadsheet-based quant workflows.

## Installation

Install the package directly from PyPI:

```bash
pip install QuantMission
```
## Quick Start (Python)

By convention, import quantmission as qms. The calculator abstracts away the complexity of data fetching. Simply initialize it with a B3 ticker, and it will handle the backend routing, holiday caching, and curve interpolation automatically.

```
import datetime
import pandas as pd
import quantmission as qms

# 1. Initialize the engine for a specific B3 asset
stock = 'VALE3'
spot = 75.69
strike = 75.00
expiry_date = datetime.date(2026, 8, 21)
n_days = 63  # Lookback window for Yang-Zhang volatility

calc = qms.B3OptionsCalculator(stock)

# 2. Run the calculation engine
data = calc.calculate_greeks(
    spot=spot,
    strike=strike,
    expiry_date=expiry_date,
    n_days=n_days 
)

# 3. Format and inspect all general parameters
general_params = {
    'Stock': stock,
    'Spot Price': spot,            
    'Strike Price': strike,          
    'Expiration': expiry_date, 
    'Volatility Source': data['vol_source'],
    'YZ Volatility': f"{data['yz_volatility'] * 100:.2f}%",
    'Annual Rate (DI x Pré)': f"{data['annual_rate'] * 100:.2f}%",
    'Maturity (Bus Days)': data['maturity_bus_days']
}
df_general = pd.DataFrame(list(general_params.items()), columns=['Parameter', 'Value']).set_index('Parameter')

# 4. Format side-by-side Call vs Put metrics
metrics = ['price', 'intrinsic', 'time_val', 'delta', 'gamma', 'theta', 'vega', 'rho']
metric_labels = ['Price', 'Intrinsic Value', 'Time Value', 'Delta', 'Gamma', 'Theta', 'Vega', 'Rho']

df_options = pd.DataFrame({
    'Metric': metric_labels,
    'Call': [data[f'call_{m}'] for m in metrics],
    'Put': [data[f'put_{m}'] for m in metrics]
}).set_index('Metric')

print("=== Market Parameters & Volatility ===")
print(df_general)

print("\n=== Call vs Put Metrics ===")
print(df_options)
```

## Excel UDF Setup (xlwings)

This package comes pre-configured with a User Defined Function (UDF) that allows you to spill the entire Greeks array directly into an Excel spreadsheet.

1. Ensure you have the xlwings add-in installed in Excel. (If not, run xlwings addin install in your terminal).

2. In the same folder as your Excel file, create a simple Python script (e.g., bridge.py) to expose the QuantMission UDF:

```
import xlwings as xw
from quantmission.core import B3options
```
3. Open your Excel workbook, navigate to the xlwings ribbon, and:

    * Set the Interpreter path to your Python executable (e.g., C:\Python311\python.exe).

    * Set the UDF Modules box to your script name (e.g., bridge).

4. Click Import Functions.

5. In any cell, type the formula and hit Enter to spill the array:
```
=B3options("PETR4", 38.50, DATE(2026,8,21), 38.00, 63)
```

## The QuantMission Vision (Roadmap)

quantmission is built around an Open-Core architecture:

* The Client (qms - MIT License): Free, open-source, local-first analytics client designed to handle transparent baseline calculations, local caching, and public data ingestion.

* Institutional-grade market data lakes.

* QuantMission Cloud API (Proprietary Engine): A subscription tier providing high-performance, server-side compute for complex derived intelligence.

## License

This project is open-sourced under the MIT License.

## Contact & Support

To learn more about our proprietary analytics server, reach out to contact@quantmission.com.
