Skip to content

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
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
Result
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.

setup.sql
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;

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'
);

3. Run a query

query.sql
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
More example queries →
Technical details
Verified connector release
v0.6.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
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'
);

Overview

Option pricing + Greeks, bond pricing/yield, day-count and carry math for SQL (QuantLib)

Catalog

Everything quant exposes once attached — read straight from the worker's released build.

quant 1 schema
main 1 table · 21 functions

Option/Greeks, bond, and day-count functions: the quant catalog's single schema

Schema examples (14)
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;
Result
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);
Tables
day_count_conventions 5 examples1 col

The day-count convention strings year_fraction() accepts, one per row

Columns
namenot null VARCHAR
A day-count convention string year_fraction() accepts.
ConstraintsPRIMARY KEY (name)
Examples (5)

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();
Link
Scalar functions
bond_convexity (face DOUBLE, coupon_rate DOUBLE, yield_rate DOUBLE, years DOUBLE, freq BIGINT) 2 examples

Convexity of a fixed-rate bond at a given yield

Arguments
face DOUBLE
Face (par) value of the bond (> 0).
coupon_rate DOUBLE
Annual coupon rate, e.g. 0.05 for 5%.
yield_rate DOUBLE
Annual yield to maturity, e.g. 0.05 for 5%.
years DOUBLE
Whole years to maturity (> 0).
freq BIGINT
Coupon frequency per year (payments per year).
ReturnsDOUBLE
Examples (2)

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;
Link
bond_duration (face DOUBLE, coupon_rate DOUBLE, yield_rate DOUBLE, years DOUBLE, freq BIGINT) 2 examples

Modified duration of a fixed-rate bond at a given yield

Arguments
face DOUBLE
Face (par) value of the bond (> 0).
coupon_rate DOUBLE
Annual coupon rate, e.g. 0.05 for 5%.
yield_rate DOUBLE
Annual yield to maturity, e.g. 0.05 for 5%.
years DOUBLE
Whole years to maturity (> 0).
freq BIGINT
Coupon frequency per year (payments per year).
ReturnsDOUBLE
Examples (2)

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;
Link
bond_price (face DOUBLE, coupon_rate DOUBLE, yield_rate DOUBLE, years DOUBLE, freq BIGINT) 2 examples

Clean price of a fixed-rate bond at a given yield (par bond prices to face)

Arguments
face DOUBLE
Face (par) value of the bond (> 0).
coupon_rate DOUBLE
Annual coupon rate, e.g. 0.05 for 5%.
yield_rate DOUBLE
Annual yield to maturity, e.g. 0.05 for 5%.
years DOUBLE
Whole years to maturity (> 0).
freq BIGINT
Coupon frequency per year (payments per year).
ReturnsDOUBLE
Examples (2)

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;
Link
bond_yield (price DOUBLE, face DOUBLE, coupon_rate DOUBLE, years DOUBLE, freq BIGINT) 2 examples

Yield to maturity implied by a clean bond price (inverse of bond_price)

Arguments
price DOUBLE
Observed clean price (> 0).
face DOUBLE
Face (par) value of the bond (> 0).
coupon_rate DOUBLE
Annual coupon rate, e.g. 0.05 for 5%.
years DOUBLE
Whole years to maturity (> 0).
freq BIGINT
Coupon frequency per year (payments per year).
ReturnsDOUBLE
Examples (2)

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;
Link
box_spread_rate (box_price DOUBLE, low_strike DOUBLE, high_strike DOUBLE, ttm DOUBLE) 2 examples

Annual rate implied by a European box spread: ln((high-low)/box_price)/ttm

Arguments
box_price DOUBLE
Net cost of the four-leg box, in strike units (> 0).
low_strike DOUBLE
Lower strike (> 0).
high_strike DOUBLE
Upper strike (> low_strike).
ttm DOUBLE
Time to maturity in years (> 0), e.g. days / 365.
ReturnsDOUBLE
Examples (2)

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);
Link
bs_delta (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR) 2 examples

Black-Scholes delta d(value)/d(spot) of a European option

Arguments
spot DOUBLE
Underlying spot price (> 0).
strike DOUBLE
Option strike price (> 0).
rate DOUBLE
Continuously-compounded annualized risk-free rate.
vol DOUBLE
Annualized volatility (>= 0), e.g. 0.2 for 20%.
ttm DOUBLE
Time to maturity in years (> 0).
opt_type VARCHAR
Option type: 'call' or 'put'.
ReturnsDOUBLE
Examples (2)

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;
Link
bs_gamma (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR) 1 example

Black-Scholes gamma d2(value)/d(spot)2 of a European option

Arguments
spot DOUBLE
Underlying spot price (> 0).
strike DOUBLE
Option strike price (> 0).
rate DOUBLE
Continuously-compounded annualized risk-free rate.
vol DOUBLE
Annualized volatility (>= 0), e.g. 0.2 for 20%.
ttm DOUBLE
Time to maturity in years (> 0).
opt_type VARCHAR
Option type: 'call' or 'put'.
ReturnsDOUBLE
Example

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;
Link
bs_price (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR) 3 examples

Black-Scholes price of a European option ('call'|'put')

Arguments
spot DOUBLE
Underlying spot price (> 0).
strike DOUBLE
Option strike price (> 0).
rate DOUBLE
Continuously-compounded annualized risk-free rate.
vol DOUBLE
Annualized volatility (>= 0), e.g. 0.2 for 20%.
ttm DOUBLE
Time to maturity in years (> 0).
opt_type VARCHAR
Option type: 'call' or 'put'.
ReturnsDOUBLE
Examples (3)

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;
Link
bs_rho (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR) 2 examples

Black-Scholes rho d(value)/d(rate), per 1.00 of the rate

Arguments
spot DOUBLE
Underlying spot price (> 0).
strike DOUBLE
Option strike price (> 0).
rate DOUBLE
Continuously-compounded annualized risk-free rate.
vol DOUBLE
Annualized volatility (>= 0), e.g. 0.2 for 20%.
ttm DOUBLE
Time to maturity in years (> 0).
opt_type VARCHAR
Option type: 'call' or 'put'.
ReturnsDOUBLE
Examples (2)

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;
Link
bs_theta (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR) 2 examples

Black-Scholes theta d(value)/d(t), per year

Arguments
spot DOUBLE
Underlying spot price (> 0).
strike DOUBLE
Option strike price (> 0).
rate DOUBLE
Continuously-compounded annualized risk-free rate.
vol DOUBLE
Annualized volatility (>= 0), e.g. 0.2 for 20%.
ttm DOUBLE
Time to maturity in years (> 0).
opt_type VARCHAR
Option type: 'call' or 'put'.
ReturnsDOUBLE
Examples (2)

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;
Link
bs_vega (spot DOUBLE, strike DOUBLE, rate DOUBLE, vol DOUBLE, ttm DOUBLE, opt_type VARCHAR) 2 examples

Black-Scholes vega d(value)/d(vol), per 1.00 of volatility

Arguments
spot DOUBLE
Underlying spot price (> 0).
strike DOUBLE
Option strike price (> 0).
rate DOUBLE
Continuously-compounded annualized risk-free rate.
vol DOUBLE
Annualized volatility (>= 0), e.g. 0.2 for 20%.
ttm DOUBLE
Time to maturity in years (> 0).
opt_type VARCHAR
Option type: 'call' or 'put'.
ReturnsDOUBLE
Examples (2)

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;
Link
calendar_spread_rate (near_price DOUBLE, far_price DOUBLE, near_ttm DOUBLE, far_ttm DOUBLE) 2 examples

Annual rate implied between two futures expiries: ln(far/near)/(far_ttm-near_ttm)

Arguments
near_price DOUBLE
Price of the nearer futures expiry (> 0).
far_price DOUBLE
Price of the later futures expiry (> 0).
near_ttm DOUBLE
Years until the nearer expiry (>= 0).
far_ttm DOUBLE
Years until the later expiry (> near_ttm).
ReturnsDOUBLE
Examples (2)

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;
Link
continuous_to_simple (rate DOUBLE, ttm DOUBLE) 2 examples

Convert a continuous annual rate to a simple rate over ttm years: (exp(rate*ttm)-1)/ttm

Arguments
rate DOUBLE
Continuously compounded annual rate as a decimal.
ttm DOUBLE
Time to maturity in years (> 0), e.g. days / 365.
ReturnsDOUBLE
Examples (2)

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;
Link
discount_factor (rate DOUBLE, ttm DOUBLE) 2 examples

Continuously-compounded discount factor exp(-rate * ttm)

Arguments
rate DOUBLE
Continuously-compounded annualized risk-free rate.
ttm DOUBLE
Discounting horizon, expressed in years.
ReturnsDOUBLE
Examples (2)

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;
Link
funding_rate_annual (rate DOUBLE, interval_hours DOUBLE) 2 examples

Continuous annual rate equivalent to a perpetual-futures funding rate

Arguments
rate DOUBLE
Funding rate per interval as a decimal (> -1).
interval_hours DOUBLE
Hours between funding payments (> 0).
ReturnsDOUBLE
Examples (2)

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;
Link
implied_carry_rate (spot DOUBLE, forward DOUBLE, ttm DOUBLE) 2 examples

Annual cost of carry implied by a spot and a futures price: ln(forward/spot)/ttm

Arguments
spot DOUBLE
Spot price of the underlying (> 0).
forward DOUBLE
Forward or futures price (> 0).
ttm DOUBLE
Time to maturity in years (> 0), e.g. days / 365.
ReturnsDOUBLE
Examples (2)

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;
Link
implied_vol (price DOUBLE, spot DOUBLE, strike DOUBLE, rate DOUBLE, ttm DOUBLE, opt_type VARCHAR) 3 examples

Black-Scholes implied volatility reproducing an option price (raises if not invertible)

Arguments
price DOUBLE
Observed option price (>= 0).
spot DOUBLE
Underlying spot price (> 0).
strike DOUBLE
Option strike price (> 0).
rate DOUBLE
Continuously-compounded annualized risk-free rate.
ttm DOUBLE
Time to maturity in years (> 0).
opt_type VARCHAR
Option type: 'call' or 'put'.
ReturnsDOUBLE
Examples (3)

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;
Result
strike iv delta
90 0.2531 0.7933
100 0.2478 0.5911
110 0.2378 0.3692
Link
present_value (amount DOUBLE, rate DOUBLE, ttm DOUBLE) 3 examples

Present value amount * exp(-rate * ttm) (continuous compounding)

Arguments
amount DOUBLE
Future cash amount.
rate DOUBLE
Continuously-compounded annualized risk-free rate.
ttm DOUBLE
Discounting horizon, expressed in years.
ReturnsDOUBLE
Examples (3)

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);
Link
simple_to_continuous (rate DOUBLE, ttm DOUBLE) 2 examples

Convert a simple annual rate over ttm years to continuous: ln(1+rate*ttm)/ttm

Arguments
rate DOUBLE
Simple annual rate as a decimal.
ttm DOUBLE
Time to maturity in years (> 0), e.g. days / 365.
ReturnsDOUBLE
Examples (2)

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;
Link
tbill_rate (discount_rate DOUBLE, days DOUBLE) 2 examples

Continuous annual rate of a T-bill quoted on the bank-discount basis (ACT/360)

Arguments
discount_rate DOUBLE
Bank-discount yield as a decimal (0.0412 = 4.12%).
days DOUBLE
Days to maturity (> 0).
ReturnsDOUBLE
Examples (2)

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;
Link
year_fraction (start DATE, end DATE, convention VARCHAR) 7 examples

Year fraction between two dates under a day-count convention ('ACT/360', 'ACT/365', '30/360', 'ACT/ACT'). Unknown convention raises.

Arguments
start DATE
Start of the accrual period (inclusive).
end DATE
End of the accrual period; the span runs from start to here.
convention VARCHAR
Day-count convention string; see day_count_conventions().
ReturnsDOUBLE
Examples (7)

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;
Link

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.