Spaces:
Sleeping
Sleeping
Martin Burke
Expand knowledge base: add jump-diffusion, SABR, LMM, credit copula, convertible models + 6 product types and 3 sample term sheets
107ed70 Download termsheet_agent/classify.py from mb-quant-ai/termsheet-risk-agent: direct link, hf CLI and curl.
- Browser
- Download file 2.69 kB
-
https://huggingface.co/spaces/mb-quant-ai/termsheet-risk-agent/resolve/main/termsheet_agent/classify.py
- Command line
-
hf download hf://spaces/mb-quant-ai/termsheet-risk-agent/termsheet_agent/classify.py
-
curl -L -o classify.py https://huggingface.co/spaces/mb-quant-ai/termsheet-risk-agent/resolve/main/termsheet_agent/classify.py
2.69 kB
| """Classifier agent: ``TermSheet`` -> ``ProductClassification`` (product + pricing model).""" | |
| from __future__ import annotations | |
| from agents import Agent, Runner | |
| from .llm import get_model | |
| from .schemas import ProductClassification, TermSheet | |
| INSTRUCTIONS = """\ | |
| You are a quantitative analyst who decides which pricing model a structured product requires. | |
| Given the extracted term-sheet economics, determine: | |
| - product_family: the standard name (e.g. "autocallable note", "knock-out barrier option", | |
| "range accrual note", "CMS spread note", "TARN"). | |
| - asset_class: equity, rates, FX, credit, or hybrid. | |
| - required_model: the pricing-model family that is *necessary* to capture the product's risk, | |
| choosing the SIMPLEST model that is still adequate. Guidance: | |
| * Path-dependent equity payoffs with barriers / autocalls that are sensitive to the smile | |
| need at least local volatility; forward-skew-sensitive products (e.g. cliquets, some | |
| autocallables) need stochastic or local-stochastic volatility. | |
| * Single-callable / Bermudan rates products typically need a one-factor short-rate model | |
| (LGM / Hull-White); spread or multi-curve products need a multi-factor rates model. | |
| * Multi-underlying payoffs need a model carrying correlation. | |
| * Forward-starting / cliquet / ratchet payoffs are forward-skew sensitive — use stochastic or | |
| local-stochastic volatility. | |
| * Products with material gap/jump risk or a steep short-dated smile (short-dated barriers, | |
| FX one-touch / digitals) may need a jump-diffusion / Lévy model, or SABR for the FX/rates smile. | |
| * Path-dependent, multi-callable RATES exotics (callable range accruals, snowballs, rates TARNs) | |
| need a LIBOR market model (libor_market_model); single-callable rates products stay with LGM/Hull-White. | |
| * Credit-linked notes and basket / first-to-default products need a reduced-form intensity model | |
| with a default copula (credit_intensity_copula). | |
| * Convertible bonds need a coupled equity-credit model (convertible_bond). | |
| - alternative_models: other defensible choices. | |
| - rationale: 2-4 sentences justifying the mapping, referencing the specific product features. | |
| - confidence: 0-1. | |
| """ | |
| def build_classifier() -> Agent: | |
| return Agent( | |
| name="Classifier", | |
| instructions=INSTRUCTIONS, | |
| model=get_model(), | |
| output_type=ProductClassification, | |
| ) | |
| async def classify_product(term_sheet: TermSheet) -> ProductClassification: | |
| payload = term_sheet.model_dump_json(indent=2) | |
| result = await Runner.run( | |
| build_classifier(), | |
| input=f"Term-sheet economics (JSON):\n{payload}", | |
| ) | |
| return result.final_output | |