1. Per-tick Premium

Let:
  • I = IMPACT_NOTIONAL
  • c = floor(underlier_price) (current price)
  • Bids: levels (pib,qib)(p_i^b, q_i^b) sorted descending by price
  • Asks: levels (pja,qja)(p_j^a, q_j^a) sorted ascending by price
Available notional on one level: cap(p,q)  =  pq\mathrm{cap}(p,q) \;=\; p \cdot q Target notional (same for both sides): N  =  min ⁣(I,  ipi(b)qi(b),  jpj(a)qj(a))N \;=\; \min\!\left( I,\; \sum_i p_i^{(b)} q_i^{(b)},\; \sum_j p_j^{(a)} q_j^{(a)} \right)

Impact Bid Price

Greedily fill from highest bids down. Let the notional taken from bid level i be: xi  =  min ⁣(Nk<ixk,  pi(b)qi(b))x_i \;=\; \min\!\left( N - \sum_{k<i} x_k,\; p_i^{(b)} q_i^{(b)} \right) Base quantity from level i: Qi  =  xipi(b)Q_i \;=\; \frac{x_i}{p_i^{(b)}} Total base quantity and impact bid price: Q(b)  =  iQi,Pbid  =  NSQ(b)  =  Nixipi(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)}}}

Impact Ask Price

Greedily fill from lowest asks up. Let the notional taken from ask level j be: yj  =  min ⁣(Nk<jyk,  pj(a)qj(a))y_j \;=\; \min\!\left( N - \sum_{k<j} y_k,\; p_j^{(a)} q_j^{(a)} \right) Base quantity from level j: Qj  =  yjpj(a)Q_j \;=\; \frac{y_j}{p_j^{(a)}} Total base quantity and impact ask price: Q(a)  =  jQj,Pask  =  NQ(a)  =  Njyjpj(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)}}}
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). The per-tick premium is: premium=(cPbid)+(cPask)+c.\mathrm{premium} = \frac{(c - P_{\text{bid}})_{-} + (c - P_{\text{ask}})_{+}}{c}.
  • 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: {p1,p2,,pn}\{\, p_1, p_2, \dots, p_n \,\} Linearly time-weighted average: f  =  2n(n+1)k=1nkpkf \;=\; \frac{2}{n(n+1)} \sum_{k=1}^{n} k\,p_k

Clamp (Dead Zone)

Let (C = \mathrm \cdot S). Apply a symmetric clamp around zero: rate  =  sgn(f)max ⁣(fC, 0)\mathrm{rate} \;=\; \mathrm{sgn}(f)\,\max\!\big(\,|f| - C,\ 0\,\big)
  • 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: notional_per_qty  =  rate×underlier_price\mathrm{notional\_per\_qty} \;=\; \left\lfloor \mathrm{rate} \times \mathrm{underlier\_price} \right\rfloor

Summary

  1. Compute impact bid/ask prices from greedy fills (notional-weighted harmonic means).
  2. Compute a per-tick premium from spot vs. impact prices.
  3. Aggregate premiums with a linearly time-weighted average over the window.
  4. Apply a symmetric clamp (dead zone) around zero.
  5. Multiply by spot to get funding amount per contract at application.