DuckDB Finance Quant SQL Extension

Agent Guide

Use this page when an automated agent needs to answer questions, write SQL, or modify the DuckDB Finance extension. It is a routing guide, not a substitute for the function reference.

Fast Routing

User intent Start here Then verify with
Install or load the extension Installation make smoke DUCKDB_ROOT=/path/to/duckdb
Learn the first queries Getting Started Run the SQL snippets against a loaded extension
Choose a function for a task Function Cookbook Function Reference
Build a desk-style workflow Finance SQL Playbooks examples/playbooks.sql
Explain units or model boundaries Best Practices and Quant Developer Guide Relevant gold tests
Check compatibility behavior Compatibility scripts/check_gs_quant_surface.py
Change code or docs Development Guide make check DUCKDB_ROOT=/path/to/duckdb

Working Rules

  1. Prefer core fin_* functions before compatibility helpers.
  2. Keep all rates, returns, and volatilities in decimal units unless a function says it takes basis points.
  3. Treat currency fields as labels unless the function explicitly performs FX pricing or conversion.
  4. Do not infer market data, curves, calendars, or official risk units. Ask the caller or make the assumption explicit in SQL.
  5. Use the function reference for signatures and return shapes, then run the query. Do not rely on memory for exact overloads.
  6. For source builds, use the Makefile targets. They load the local unsigned extension correctly.

Function Lookup Pattern

When asked for a function, search in this order:

rg -n 'fin_bsm_|fin_var|fin_calendar' docs/function_reference.md
rg -n 'fin_bsm_|fin_var|fin_calendar' test/sql/gold_tests.sql
rg -n 'fin_bsm_|fin_var|fin_calendar' src

Use the reference for the user-facing contract, gold tests for executable examples, and source only when behavior or edge cases are unclear.

SQL Answer Pattern

A useful answer should include:

Example:

SELECT
  fin_bsm_price('call', 100.0, 100.0, 1.0, 0.05, 0.20) AS price,
  fin_bsm_delta('call', 100.0, 100.0, 1.0, 0.05, 0.20) AS delta,
  fin_bsm_vega('call', 100.0, 100.0, 1.0, 0.05, 0.20) AS vega;

Assumptions: ttm is a year fraction, rate is decimal annualized, volatility is decimal annualized, and the result is per unit notional.

Change Checklist

When editing functions or docs: