Pricing API¶
Price calculations and estimations.
Mark Price¶
mark_price¶
mark_price ¶
Return a mark price using mid from the orderbook or fallback to index price.
Mid Price¶
mid_price¶
mid_price ¶
Return mid price from an orderbook snapshot.
VWAP¶
vwap¶
vwap ¶
VWAP calculation.
vwap ¶
Calculate Volume-Weighted Average Price.
VWAP is the average price weighted by volume, commonly used as a trading benchmark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Iterable[Tuple[Price, Quantity]]
|
Iterable of (price, quantity) tuples |
required |
Returns:
| Type | Description |
|---|---|
Price
|
Volume-weighted average price |
Raises:
| Type | Description |
|---|---|
ValueError
|
If total quantity is zero |
Example
from decimal import Decimal trades = [ ... (Decimal("100"), Decimal("10")), # 10 @ $100 ... (Decimal("102"), Decimal("20")), # 20 @ $102 ... (Decimal("99"), Decimal("5")), # 5 @ $99 ... ] price = vwap(trades) float(price) 101.0
VWAP is weighted toward larger trades¶
(10100 + 20102 + 5*99) / 35 = 101.0¶
Slippage¶
estimate_slippage¶
estimate_slippage ¶
estimate_slippage(
orderbook: OrderBook,
side: OrderSide,
quantity: Quantity,
impact_bps: Decimal | None = None,
) -> Price
Estimate volume-weighted execution price for a market order. Optionally add a linear market impact in basis points on the notional.
Rate Annualization¶
annualize_rate¶
annualize_rate ¶
Approximate annualized funding given a per-period rate.