Quant
Black-Scholes option prices and Greeks, bond pricing and yield, and day-count math as SQL functions, backed by QuantLib
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/quant/index.md to help me query Quant with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
See what you can query
Example output · captured
- Connector release
- v0.6.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
WITH quotes(strike, price) AS (VALUES (90, 14.50), (100, 8.20), (110, 3.90)), smile AS (SELECT strike, quant.main.implied_vol(price, 100, strike, 0.05, 0.5, 'call') AS iv FROM quotes) SELECT strike, ROUND(iv, 4) AS iv, ROUND(quant.main.bs_delta(100, strike, 0.05, iv, 0.5, 'call'), 4) AS delta
FROM smile
ORDER BY strike
| strike | iv | delta |
|---|---|---|
| 90 | 0.2531 | 0.7933 |
| 100 | 0.2478 | 0.5911 |
| 110 | 0.2378 | 0.3692 |
Quick start
Choose where to run Quant, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'quant' AS quant (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-quant-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'quant' AS quant (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-quant:0.6.0'
);
3. Run a query
WITH quotes(strike, price) AS (VALUES (90, 14.50), (100, 8.20), (110, 3.90)), smile AS (SELECT strike, quant.main.implied_vol(price, 100, strike, 0.05, 0.5, 'call') AS iv FROM quotes) SELECT strike, ROUND(iv, 4) AS iv, ROUND(quant.main.bs_delta(100, strike, 0.05, iv, 0.5, 'call'), 4) AS delta
FROM smile
ORDER BY strike
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'quant' AS quant
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
WITH quotes(strike, price) AS (VALUES (90, 14.50), (100, 8.20), (110, 3.90)), smile AS (SELECT strike, quant.main.implied_vol(price, 100, strike, 0.05, 0.5, 'call') AS iv FROM quotes) SELECT strike, ROUND(iv, 4) AS iv, ROUND(quant.main.bs_delta(100, strike, 0.05, iv, 0.5, 'call'), 4) AS delta
FROM smile
ORDER BY strike
Query Farm operates Quant for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use quant as the catalog alias for the query below.
4. Run a query
WITH quotes(strike, price) AS (VALUES (90, 14.50), (100, 8.20), (110, 3.90)), smile AS (SELECT strike, quant.main.implied_vol(price, 100, strike, 0.05, 0.5, 'call') AS iv FROM quotes) SELECT strike, ROUND(iv, 4) AS iv, ROUND(quant.main.bs_delta(100, strike, 0.05, iv, 0.5, 'call'), 4) AS delta
FROM smile
ORDER BY strike
Technical details
- Verified connector release
- v0.6.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'quant' AS quant (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-quant-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'quant' AS quant (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-quant:0.6.0'
);
Overview
Option pricing + Greeks, bond pricing/yield, day-count and carry math for SQL (QuantLib)

Price options, compute Black-Scholes Greeks, value fixed-rate bonds, and do day-count and discounting math directly in DuckDB SQL — no spreadsheets, no external pricing service, no round-trips to Python. The quant catalog turns industry-standard quantitative-finance calculations into ordinary SQL functions you can call inline in any query.
This extension is for analysts, quants, risk teams, and data engineers who keep their market data in DuckDB and want option pricing, implied volatility, bond analytics, and rate-risk math to live right next to the data. Because the calculations are exposed as scalar functions, you can value a whole portfolio in a single SELECT, filter on a computed risk measure in a WHERE clause, or join model output back onto your positions — all with the speed of DuckDB's vectorized engine over Apache Arrow.
Key concepts
- Per-row vs. constant arguments. Market inputs (spot, strike, rate, volatility, price, coupon, yield, dates) are per-row columns, while the option kind, the bond coupon frequency, and the day-count convention are constant (literal) arguments fixed at planning time. That split lets you value an entire table of positions in one pass.
- Analytic and deterministic. Option values use the closed-form Black-Scholes model (no dividend yield — carry equals the risk-free rate); bond analytics use a fixed-rate bond priced on a pinned evaluation date. Results are reproducible run to run.
- NULL vs. error. Any NULL input yields a NULL result, but a genuinely invalid non-NULL input (a non-positive time to maturity, a negative volatility, an unknown convention) raises a clear error rather than silently returning a wrong number.
When to reach for it
Use quant whenever you need theoretical option premia and their risk sensitivities, want to convert between bond prices and yields or measure interest-rate risk, or need consistent day-count and present-value math alongside your data — without exporting to a separate analytics stack. Because every calculation is a deterministic, closed-form function, results are reproducible and cheap enough to run across a whole portfolio in a single query.
Backed by QuantLib
Under the hood the math is backed by QuantLib, the widely used open-source library for quantitative finance, which provides the analytic option pricing, the fixed-rate bond pricing and yield solvers, and the day-count conventions this worker exposes. See the QuantLib source code on GitHub, the official documentation, and the Python bindings reference for the underlying models and conventions.
Catalog
Everything quant exposes once attached — read straight from the worker's
released build.
main 1 table · 21 functions
Option/Greeks, bond, and day-count functions: the quant catalog's single schema
Schema examples (14)
Black-Scholes fair value of an at-the-money 1-year European call.
SELECT quant.main.bs_price(100, 100, 0.05, 0.2, 1, 'call') AS call_price;
Delta (hedge ratio) of that same at-the-money call.
SELECT quant.main.bs_delta(100, 100, 0.05, 0.2, 1, 'call') AS delta;
Recover the implied volatility (~0.20) from a quoted call price.
SELECT quant.main.implied_vol(10.45, 100, 100, 0.05, 1, 'call') AS iv;
Clean price of a 10-year 5% semiannual par bond (prices to 100).
SELECT quant.main.bond_price(100, 0.05, 0.05, 10, 2) AS clean_price;
10 more examples
Invert a par price back to the bond's yield to maturity (~0.05).
SELECT quant.main.bond_yield(100, 100, 0.05, 10, 2) AS ytm;
Day-count year fraction of a half-year span under ACT/360 (181/360).
SELECT quant.main.year_fraction(DATE '2026-01-01', DATE '2026-07-01', 'ACT/360') AS yf;
One-year continuously-compounded discount factor at 5% (~0.9512).
SELECT quant.main.discount_factor(0.05, 1) AS df;
List the supported day-count convention names, alphabetically.
SELECT name FROM quant.main.day_count_conventions() ORDER BY name;
Gold cash-and-carry: futures carry over the 3-month T-bill rate.
SELECT ROUND(quant.main.implied_carry_rate(4000, 4050, 0.25) - quant.main.tbill_rate(0.0412, 91), 4) AS excess_carry;
Short perp at the 1 bp/8h funding floor, hedged with a long future.
SELECT ROUND(quant.main.funding_rate_annual(0.0001, 8) - quant.main.implied_carry_rate(4000, 4050, 0.25), 4) AS net_carry;
Back out implied vol for three quoted 6-month calls, then compute each strike's delta at its own implied vol (implied_vol feeding bs_delta); the vol skews down as strike rises.
WITH quotes(strike, price) AS (VALUES (90, 14.50), (100, 8.20), (110, 3.90)), smile AS (SELECT strike, quant.main.implied_vol(price, 100, strike, 0.05, 0.5, 'call') AS iv FROM quotes) SELECT strike, ROUND(iv, 4) AS iv, ROUND(quant.main.bs_delta(100, strike, 0.05, iv, 0.5, 'call'), 4) AS delta
FROM smile
ORDER BY strike;
| strike | iv | delta |
|---|---|---|
| 90 | 0.2531 | 0.7933 |
| 100 | 0.2478 | 0.5911 |
| 110 | 0.2378 | 0.3692 |
Value a small call book dated 2026-06-15: each expiry date becomes an ACT/365 time to maturity via year_fraction, which feeds bs_price and bs_delta summed by position size.
WITH book(qty, strike, expiry) AS (VALUES (10, 100, DATE '2026-09-18'), (-10, 110, DATE '2026-09-18'), (5, 100, DATE '2026-12-18')), priced AS (SELECT qty, strike, quant.main.year_fraction(DATE '2026-06-15', expiry, 'ACT/365') AS ttm FROM book) SELECT ROUND(SUM(qty * quant.main.bs_price(100, strike, 0.05, 0.2, ttm, 'call')), 4) AS book_value, ROUND(SUM(qty * quant.main.bs_delta(100, strike, 0.05, 0.2, ttm, 'call')), 4) AS book_delta
FROM priced;
Shock a 10-year 5% semiannual par bond up 100bp: the full bond_price reprice (-7.44) versus the duration-only (-7.80) and duration-plus-convexity (-7.43) estimates.
WITH base AS (SELECT quant.main.bond_price(100, 0.05, 0.05, 10, 2) AS p0, quant.main.bond_duration(100, 0.05, 0.05, 10, 2) AS dur, quant.main.bond_convexity(100, 0.05, 0.05, 10, 2) AS cvx) SELECT ROUND(quant.main.bond_price(100, 0.05, 0.06, 10, 2) - p0, 4) AS actual_change, ROUND(-p0 * dur * 0.01, 4) AS duration_estimate, ROUND(p0 * (-dur * 0.01 + 0.5 * cvx * 0.0001), 4) AS duration_convexity_estimate
FROM base;
Present value of a 2-year 5% semiannual coupon schedule settled 2026-06-15, discounting each cash flow at 4.5% continuous over its ACT/365 year_fraction (~100.84).
SELECT ROUND(SUM(quant.main.present_value(CASE WHEN n = 4 THEN 102.5 ELSE 2.5 END, 0.045, quant.main.year_fraction(DATE '2026-06-15', CAST(DATE '2026-06-15' + to_months(6 * n) AS DATE), 'ACT/365'))), 4) AS pv
FROM range(1, 5) AS t(n);
day_count_conventions
The day-count convention strings year_fraction() accepts, one per row
List the supported day-count convention names, alphabetically.
SELECT name FROM quant.main.day_count_conventions ORDER BY name;
Count how many day-count conventions are supported.
SELECT count(*) AS n FROM quant.main.day_count_conventions;
Show only the actual/actual-family conventions.
SELECT name
FROM quant.main.day_count_conventions
WHERE name LIKE 'ACT%'
ORDER BY name;
2 more examples
SELECT name FROM quant.main.day_count_conventions() ORDER BY name;
SELECT count(*) AS n FROM quant.main.day_count_conventions();
bond_convexity (face DOUBLE, coupon_rate DOUBLE, yield_rate DOUBLE, years DOUBLE, freq BIGINT)
Convexity of a fixed-rate bond at a given yield
Convexity of a 10-year 5% semiannual par bond; near 73.65 and positive.
SELECT quant.main.bond_convexity(100, 0.05, 0.05, 10, 2) AS convexity;
Shock a 10-year 5% semiannual par bond up 100bp: the full bond_price reprice (-7.44) versus the duration-only (-7.80) and duration-plus-convexity (-7.43) estimates.
WITH base AS (SELECT quant.main.bond_price(100, 0.05, 0.05, 10, 2) AS p0, quant.main.bond_duration(100, 0.05, 0.05, 10, 2) AS dur, quant.main.bond_convexity(100, 0.05, 0.05, 10, 2) AS cvx) SELECT ROUND(quant.main.bond_price(100, 0.05, 0.06, 10, 2) - p0, 4) AS actual_change, ROUND(-p0 * dur * 0.01, 4) AS duration_estimate, ROUND(p0 * (-dur * 0.01 + 0.5 * cvx * 0.0001), 4) AS duration_convexity_estimate
FROM base;
bond_duration (face DOUBLE, coupon_rate DOUBLE, yield_rate DOUBLE, years DOUBLE, freq BIGINT)
Modified duration of a fixed-rate bond at a given yield
Modified duration (years) of a 10-year 5% semiannual par bond; near 7.8.
SELECT quant.main.bond_duration(100, 0.05, 0.05, 10, 2) AS modified_duration;
Estimate the price drop from a 100 bp yield rise: -duration * 0.01 * price.
SELECT -quant.main.bond_duration(100, 0.05, 0.05, 10, 2) * 0.01 * 100 AS approx_price_change;
bond_price (face DOUBLE, coupon_rate DOUBLE, yield_rate DOUBLE, years DOUBLE, freq BIGINT)
Clean price of a fixed-rate bond at a given yield (par bond prices to face)
Clean price of a 10-year 5% semiannual par bond (coupon == yield) is 100.
SELECT quant.main.bond_price(100, 0.05, 0.05, 10, 2) AS clean_price;
When yield exceeds the coupon the bond trades at a discount (price < face).
SELECT quant.main.bond_price(100, 0.05, 0.07, 10, 2) AS discount_price;
bond_yield (price DOUBLE, face DOUBLE, coupon_rate DOUBLE, years DOUBLE, freq BIGINT)
Yield to maturity implied by a clean bond price (inverse of bond_price)
Yield to maturity of a 10-year 5% semiannual bond quoted at par (100) is ~0.05.
SELECT quant.main.bond_yield(100, 100, 0.05, 10, 2) AS ytm;
A price below par implies a yield above the 5% coupon.
SELECT quant.main.bond_yield(95, 100, 0.05, 10, 2) AS ytm;
box_spread_rate (box_price DOUBLE, low_strike DOUBLE, high_strike DOUBLE, ttm DOUBLE)
Annual rate implied by a European box spread: ln((high-low)/box_price)/ttm
A 1000-wide SPX box costing 989 with 3 months left lends at ~4.42%/yr.
SELECT ROUND(quant.main.box_spread_rate(989, 5000, 6000, 0.25), 4) AS box_rate;
Price the box from its four legs, then take its rate.
SELECT ROUND(quant.main.box_spread_rate(c_lo - c_hi + p_hi - p_lo, 5000, 6000, 0.25), 4) AS box_rate
FROM (VALUES (1050.0, 210.0, 160.0, 11.0)) l(c_lo, c_hi, p_hi, p_lo);
bs_delta (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR)
Black-Scholes delta d(value)/d(spot) of a European option
Delta (hedge ratio) of an at-the-money 1-year European call; near 0.64.
SELECT quant.main.bs_delta(100, 100, 0.05, 0.2, 1, 'call') AS call_delta;
Delta of the matching European put is negative (call delta minus 1).
SELECT quant.main.bs_delta(100, 100, 0.05, 0.2, 1, 'put') AS put_delta;
bs_gamma (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR)
Black-Scholes gamma d2(value)/d(spot)2 of a European option
Gamma of an at-the-money 1-year European call (identical for the put).
SELECT quant.main.bs_gamma(100, 100, 0.05, 0.2, 1, 'call') AS gamma;
bs_price (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR)
Black-Scholes price of a European option ('call'|'put')
Black-Scholes fair value of an at-the-money 1-year European call.
SELECT quant.main.bs_price(100, 100, 0.05, 0.2, 1, 'call') AS call_price;
Price the matching European put (same spot, strike, rate, vol, maturity).
SELECT quant.main.bs_price(100, 100, 0.05, 0.2, 1, 'put') AS put_price;
Value a small call book dated 2026-06-15: each expiry date becomes an ACT/365 time to maturity via year_fraction, which feeds bs_price and bs_delta summed by position size.
WITH book(qty, strike, expiry) AS (VALUES (10, 100, DATE '2026-09-18'), (-10, 110, DATE '2026-09-18'), (5, 100, DATE '2026-12-18')), priced AS (SELECT qty, strike, quant.main.year_fraction(DATE '2026-06-15', expiry, 'ACT/365') AS ttm FROM book) SELECT ROUND(SUM(qty * quant.main.bs_price(100, strike, 0.05, 0.2, ttm, 'call')), 4) AS book_value, ROUND(SUM(qty * quant.main.bs_delta(100, strike, 0.05, 0.2, ttm, 'call')), 4) AS book_delta
FROM priced;
bs_rho (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR)
Black-Scholes rho d(value)/d(rate), per 1.00 of the rate
Rho (per 1.00 rate) of an at-the-money 1-year European call; positive.
SELECT quant.main.bs_rho(100, 100, 0.05, 0.2, 1, 'call') AS call_rho;
The matching European put has negative rho.
SELECT quant.main.bs_rho(100, 100, 0.05, 0.2, 1, 'put') AS put_rho;
bs_theta (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR)
Black-Scholes theta d(value)/d(t), per year
Theta (per year) of an at-the-money 1-year European call; negative.
SELECT quant.main.bs_theta(100, 100, 0.05, 0.2, 1, 'call') AS theta;
Convert to per-calendar-day time decay by dividing by 365.
SELECT quant.main.bs_theta(100, 100, 0.05, 0.2, 1, 'call') / 365 AS theta_per_day;
bs_vega (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR)
Black-Scholes vega d(value)/d(vol), per 1.00 of volatility
Vega (per 1.00 vol) of an at-the-money 1-year European call; near 37.52.
SELECT quant.main.bs_vega(100, 100, 0.05, 0.2, 1, 'call') AS vega;
Convert to the desk 'per 1% vol' convention by dividing by 100.
SELECT quant.main.bs_vega(100, 100, 0.05, 0.2, 1, 'call') / 100 AS vega_per_pct;
calendar_spread_rate (near_price DOUBLE, far_price DOUBLE, near_ttm DOUBLE, far_ttm DOUBLE)
Annual rate implied between two futures expiries: ln(far/near)/(far_ttm-near_ttm)
Gold 3-month future at 4050 and 6-month at 4110 imply ~5.88%/yr between them.
SELECT ROUND(quant.main.calendar_spread_rate(4050, 4110, 0.25, 0.5), 4) AS fwd_rate;
Every leg of a futures curve, using LEAD over expiries.
SELECT ttm,
ROUND(quant.main.calendar_spread_rate(px, nx_px, ttm, nx_ttm), 4) AS leg_rate
FROM (SELECT ttm, px, LEAD(px) OVER (ORDER BY ttm) AS nx_px, LEAD(ttm) OVER (ORDER BY ttm) AS nx_ttm FROM (VALUES (0.1, 4020.0), (0.25, 4050.0), (0.5, 4110.0)) c(ttm, px))
WHERE nx_px IS NOT NULL
ORDER BY ttm;
continuous_to_simple (rate DOUBLE, ttm DOUBLE)
Convert a continuous annual rate to a simple rate over ttm years: (exp(rate*ttm)-1)/ttm
5% continuous over six months is ~5.06% simple.
SELECT ROUND(quant.main.continuous_to_simple(0.05, 0.5), 4) AS simple;
Dollar carry on $100,000 held 3 months at the gold futures carry rate.
SELECT ROUND(100000 * quant.main.continuous_to_simple(quant.main.implied_carry_rate(4000, 4050, 0.25), 0.25) * 0.25, 2) AS dollars;
discount_factor (rate DOUBLE, ttm DOUBLE)
Continuously-compounded discount factor exp(-rate * ttm)
One-year continuously-compounded discount factor at 5% is exp(-0.05) (~0.9512).
SELECT quant.main.discount_factor(0.05, 1) AS df;
Two-year discount factor at 5% is exp(-0.10) (~0.9048).
SELECT quant.main.discount_factor(0.05, 2) AS df;
funding_rate_annual (rate DOUBLE, interval_hours DOUBLE)
Continuous annual rate equivalent to a perpetual-futures funding rate
The common 1 bp per 8 hours funding floor is ~10.95%/yr.
SELECT ROUND(quant.main.funding_rate_annual(0.0001, 8), 4) AS annual;
A short perp hedged with a long future: funding minus futures carry.
SELECT ROUND(quant.main.funding_rate_annual(0.0001, 8) - quant.main.implied_carry_rate(4000, 4050, 0.25), 4) AS net_carry;
implied_carry_rate (spot DOUBLE, forward DOUBLE, ttm DOUBLE)
Annual cost of carry implied by a spot and a futures price: ln(forward/spot)/ttm
Gold at 4000 spot with the 3-month future at 4050 implies ~4.97%/yr of carry.
SELECT ROUND(quant.main.implied_carry_rate(4000, 4050, 0.25), 4) AS carry;
Carry over a 3-month T-bill: what a cash-and-carry earns above cash.
SELECT ROUND(quant.main.implied_carry_rate(4000, 4050, 0.25) - quant.main.tbill_rate(0.0412, 91), 4) AS excess;
implied_vol (price DOUBLE, spot DOUBLE, strike DOUBLE, rate DOUBLE, ttm DOUBLE, opt_type VARCHAR)
Black-Scholes implied volatility reproducing an option price (raises if not invertible)
Recover the ~0.20 implied volatility from a Black-Scholes call price.
SELECT quant.main.implied_vol(10.45, 100, 100, 0.05, 1, 'call') AS iv;
Round-trip: price a call, then invert that price back to its vol.
SELECT quant.main.implied_vol(quant.main.bs_price(100, 100, 0.05, 0.2, 1, 'call'), 100, 100, 0.05, 1, 'call') AS iv;
Back out implied vol for three quoted 6-month calls, then compute each strike's delta at its own implied vol (implied_vol feeding bs_delta); the vol skews down as strike rises.
WITH quotes(strike, price) AS (VALUES (90, 14.50), (100, 8.20), (110, 3.90)), smile AS (SELECT strike, quant.main.implied_vol(price, 100, strike, 0.05, 0.5, 'call') AS iv FROM quotes) SELECT strike, ROUND(iv, 4) AS iv, ROUND(quant.main.bs_delta(100, strike, 0.05, iv, 0.5, 'call'), 4) AS delta
FROM smile
ORDER BY strike;
| strike | iv | delta |
|---|---|---|
| 90 | 0.2531 | 0.7933 |
| 100 | 0.2478 | 0.5911 |
| 110 | 0.2378 | 0.3692 |
present_value (amount DOUBLE, rate DOUBLE, ttm DOUBLE)
Present value amount * exp(-rate * ttm) (continuous compounding)
Present value of 100 due in one year, discounted continuously at 5% (~95.12).
SELECT quant.main.present_value(100, 0.05, 1) AS pv;
Present value of 1000 due in two years at 5% is 1000 * exp(-0.10) (~904.84).
SELECT quant.main.present_value(1000, 0.05, 2) AS pv;
Present value of a 2-year 5% semiannual coupon schedule settled 2026-06-15, discounting each cash flow at 4.5% continuous over its ACT/365 year_fraction (~100.84).
SELECT ROUND(SUM(quant.main.present_value(CASE WHEN n = 4 THEN 102.5 ELSE 2.5 END, 0.045, quant.main.year_fraction(DATE '2026-06-15', CAST(DATE '2026-06-15' + to_months(6 * n) AS DATE), 'ACT/365'))), 4) AS pv
FROM range(1, 5) AS t(n);
simple_to_continuous (rate DOUBLE, ttm DOUBLE)
Convert a simple annual rate over ttm years to continuous: ln(1+rate*ttm)/ttm
5% simple over six months is ~4.94% continuous.
SELECT ROUND(quant.main.simple_to_continuous(0.05, 0.5), 4) AS cont;
Round trip through continuous_to_simple returns the input.
SELECT ROUND(quant.main.continuous_to_simple(quant.main.simple_to_continuous(0.05, 0.5), 0.5), 6) AS back;
tbill_rate (discount_rate DOUBLE, days DOUBLE)
Continuous annual rate of a T-bill quoted on the bank-discount basis (ACT/360)
A 91-day bill quoted at a 4.12% discount is ~4.20%/yr continuous.
SELECT ROUND(quant.main.tbill_rate(0.0412, 91), 4) AS bill_rate;
Bill-equivalent rates for a few quotes and tenors.
SELECT days, ROUND(quant.main.tbill_rate(d, days), 4) AS rate
FROM (VALUES (0.0412, 28), (0.0412, 91), (0.0400, 182)) q(d, days)
ORDER BY days;
year_fraction (start DATE, end DATE, convention VARCHAR)
Year fraction between two dates under a day-count convention ('ACT/360', 'ACT/365', '30/360', 'ACT/ACT'). Unknown convention raises.
Year fraction of a Jan-1 to Jul-1 span under ACT/360 is 181/360 (~0.5028).
SELECT quant.main.year_fraction(DATE '2026-01-01', DATE '2026-07-01', 'ACT/360') AS yf;
The same span under 30/360 is exactly 0.5 (six 30-day months).
SELECT quant.main.year_fraction(DATE '2026-01-01', DATE '2026-07-01', '30/360') AS yf;
SELECT quant.main.bs_price(100, 100, 0.05, 0.2, 1, 'call') AS price;
4 more examples
SELECT quant.main.implied_vol(10.45, 100, 100, 0.05, 1, 'call') AS iv;
SELECT quant.main.bond_price(100, 0.05, 0.05, 10, 2) AS clean_price;
SELECT name FROM quant.main.day_count_conventions() ORDER BY name;
WITH base AS (SELECT quant.main.bond_price(100, 0.05, 0.05, 10, 2) AS p0, quant.main.bond_duration(100, 0.05, 0.05, 10, 2) AS dur, quant.main.bond_convexity(100, 0.05, 0.05, 10, 2) AS cvx) SELECT ROUND(quant.main.bond_price(100, 0.05, 0.06, 10, 2) - p0, 4) AS actual_change, ROUND(-p0 * dur * 0.01, 4) AS duration_estimate, ROUND(p0 * (-dur * 0.01 + 0.5 * cvx * 0.0001), 4) AS duration_convexity_estimate
FROM base;
Try these queries
Black-Scholes fair value of an at-the-money 1-year European call.
SELECT quant.main.bs_price(100, 100, 0.05, 0.2, 1, 'call') AS call_price
Uses bs_price
Delta (hedge ratio) of that same at-the-money call.
SELECT quant.main.bs_delta(100, 100, 0.05, 0.2, 1, 'call') AS delta
Uses bs_delta
Recover the implied volatility (~0.20) from a quoted call price.
SELECT quant.main.implied_vol(10.45, 100, 100, 0.05, 1, 'call') AS iv
Uses implied_vol
Clean price of a 10-year 5% semiannual par bond (prices to 100).
SELECT quant.main.bond_price(100, 0.05, 0.05, 10, 2) AS clean_price
Uses bond_price
Invert a par price back to the bond's yield to maturity (~0.05).
SELECT quant.main.bond_yield(100, 100, 0.05, 10, 2) AS ytm
Uses bond_yield
Day-count year fraction of a half-year span under ACT/360 (181/360).
SELECT quant.main.year_fraction(DATE '2026-01-01', DATE '2026-07-01', 'ACT/360') AS yf
Uses year_fraction
45 more examples in the Catalog, each listed under the table or function it uses.
Questions it can answer
Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.
- What is the Black-Scholes delta of a 1-year at-the-money European call (spot 100, strike 100, rate 0.05, volatility 0.20)? Round to 4 decimal places.
- What is the Black-Scholes gamma of a 1-year at-the-money European call (spot 100, strike 100, rate 0.05, volatility 0.20)? Round to 4 decimal places.
- What is the Black-Scholes theta (per year) of a 1-year at-the-money European call (spot 100, strike 100, rate 0.05, volatility 0.20)? Round to 2 decimal places.
- What is the ACT/360 day-count year fraction between 2026-01-01 and 2026-07-01? Round to 4 decimal places.
- Compute the continuously-compounded discount factor for a rate of 0.05 over 2 years. Round to 6 decimal places.
- What is the present value today of 1000 units of currency received in 2 years, discounted continuously at an annual rate of 0.05? Round to 4 decimal places.
Quant is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Tastytrade
Markets & finance
Query your tastytrade brokerage accounts and market data from SQL, read-only
CCXT
Markets & finance
Candles, quotes, order books, trades and perpetual funding from 100+ crypto exchanges
Perps
Markets & finance
Funding, marks, books and carry for US-regulated perps, benchmarked against offshore venues