1. Per-tick Premium
Let:
I = IMPACT_NOTIONAL
c = floor(underlier_price)
(current price)
Bids: levels ( p i b , q i b ) (p_i^b, q_i^b) ( p i b , q i b ) sorted descending by price
Asks: levels ( p j a , q j a ) (p_j^a, q_j^a) ( p j a , q j a ) sorted ascending by price
Available notional on one level:
c a p ( p , q ) = p ⋅ q \mathrm{cap}(p,q) \;=\; p \cdot q cap ( p , q ) = p ⋅ q
Target notional (same for both sides):
N = min ( I , ∑ i p i ( b ) q i ( b ) , ∑ j p j ( a ) q j ( a ) ) N \;=\; \min\!\left( I,\; \sum_i p_i^{(b)} q_i^{(b)},\; \sum_j p_j^{(a)} q_j^{(a)} \right) N = min ( I , i ∑ p i ( b ) q i ( b ) , j ∑ p j ( a ) q j ( a ) )
Impact Bid Price
Greedily fill from highest bids down. Let the notional taken from bid level i
be:
x i = min ( N − ∑ k < i x k , p i ( b ) q i ( b ) ) x_i \;=\; \min\!\left( N - \sum_{k<i} x_k,\; p_i^{(b)} q_i^{(b)} \right) x i = min ( N − k < i ∑ x k , p i ( b ) q i ( b ) )
Base quantity from level i
:
Q i = x i p i ( b ) Q_i \;=\; \frac{x_i}{p_i^{(b)}} Q i = p i ( b ) x i
Total base quantity and impact bid price:
Q ( b ) = ∑ i Q i , P bid = N ⋅ S Q ( b ) = N ∑ i x i p i ( b ) Q^{(b)} \;=\; \sum_i Q_i, \qquad
P_{\text{bid}} \;=\; \frac{N \cdot S}{Q^{(b)}} \;=\; \frac{N}{\sum_i \frac{x_i}{p_i^{(b)}}} Q ( b ) = i ∑ Q i , P bid = Q ( b ) N ⋅ S = ∑ i p i ( b ) x i N
Impact Ask Price
Greedily fill from lowest asks up. Let the notional taken from ask level j
be:
y j = min ( N − ∑ k < j y k , p j ( a ) q j ( a ) ) y_j \;=\; \min\!\left( N - \sum_{k<j} y_k,\; p_j^{(a)} q_j^{(a)} \right) y j = min N − k < j ∑ y k , p j ( a ) q j ( a )
Base quantity from level j
:
Q j = y j p j ( a ) Q_j \;=\; \frac{y_j}{p_j^{(a)}} Q j = p j ( a ) y j
Total base quantity and impact ask price:
Q ( a ) = ∑ j Q j , P ask = N Q ( a ) = N ∑ j y j p j ( a ) Q^{(a)} \;=\; \sum_j Q_j, \qquad
P_{\text{ask}} \;=\; \frac{N}{Q^{(a)}} \;=\; \frac{N}{\sum_j \frac{y_j}{p_j^{(a)}}} Q ( a ) = j ∑ Q j , P ask = Q ( a ) N = ∑ j p j ( a ) y j N
P_bid
and P_ask
are notional-weighted harmonic means of the consumed price
levels under the greedy fill.
Premium (scaled integer)
Let the positive/negative parts be z_+
and z_-
.
z + = max ( z , 0 ) , z − = min ( z , 0 ) . z_+ = \max(z, 0), \qquad z_- = \min(z, 0). z + = max ( z , 0 ) , z − = min ( z , 0 ) .
The per-tick premium is:
p r e m i u m = ( c − P bid ) − + ( c − P ask ) + c . \mathrm{premium} = \frac{(c - P_{\text{bid}})_{-} + (c - P_{\text{ask}})_{+}}{c}. premium = c ( c − P bid ) − + ( c − P ask ) + .
If c < P_bid
, premium is negative .
If c > P_ask
, premium is positive .
Inside [P_bid, P_ask]
, premium ≈ 0.
2. Funding Rate for a Window
For premiums in the current window, ordered oldest → newest:
{ p 1 , p 2 , … , p n } \{\, p_1, p_2, \dots, p_n \,\} { p 1 , p 2 , … , p n }
Linearly time-weighted average:
f = 2 n ( n + 1 ) ∑ k = 1 n k p k f \;=\; \frac{2}{n(n+1)} \sum_{k=1}^{n} k\,p_k f = n ( n + 1 ) 2 k = 1 ∑ n k p k
Clamp (Dead Zone)
Let (C = \mathrm \cdot S). Apply a symmetric clamp around zero:
r a t e = s g n ( f ) max ( ∣ f ∣ − C , 0 ) \mathrm{rate}
\;=\;
\mathrm{sgn}(f)\,\max\!\big(\,|f| - C,\ 0\,\big) rate = sgn ( f ) max ( ∣ f ∣ − C , 0 )
If (|f| \le C), the funding rate is 0 .
Otherwise, only the excess beyond (C) remains (with the sign of (f)).
3. Applied Funding Amount
At window close, the funding applied per unit quantity is:
n o t i o n a l _ p e r _ q t y = ⌊ r a t e × u n d e r l i e r _ p r i c e ⌋ \mathrm{notional\_per\_qty}
\;=\;
\left\lfloor
\mathrm{rate} \times \mathrm{underlier\_price}
\right\rfloor notional_per_qty = ⌊ rate × underlier_price ⌋
Summary
Compute impact bid/ask prices from greedy fills (notional-weighted harmonic means).
Compute a per-tick premium from spot vs. impact prices.
Aggregate premiums with a linearly time-weighted average over the window.
Apply a symmetric clamp (dead zone) around zero.
Multiply by spot to get funding amount per contract at application.