# Funding and Pricing

**funding** **mark**

* `ImpactMid = (avgImpactBid(ImpactNotional) + avgImpactAsk(ImpactNotional)) / 2`
  * computed every `TickInterval`
    * set to `5` seconds
  * `avgImpactBid`, `avgImpactAsk` are average cost per contract when buying/selling `ImpactNotional` worth of contracts
    * `ImpactNotional` is in the base asset (usually USDB)
      * for large pairs set to `$10,000` to `$100,000`
      * for small pairs set to `$1,000` to `$10,000`
* `FundingMark = ema(ImpactMids, Weight)`
  * computed every `TickInterval`
  * `ema` is exponential moving average
    * `Weight` is the EMA weighting
      * set to `2 / 7`
    * `ImpactMids` is list of previous `ImpactMid` every `TickInterval`

**funding rate**

* `Premium = (twap(FundingMarks) - twap(Indexs)) / Index`
  * computed every `SettleInterval`
    * set to `1` hour
  * `Index` is oracle price
    * stork oracle
    * for prelaunch perpetuals, it is a computed value
  * `twap` is time weighted average price
    * `FundingMarks` is list of previous `FundingMark` over the last `SettleInterval`
    * `Indexs` is list of previous `Index` over the last `SettleInterval`
  * `Premium` is considered as an amount per `FundingInterval`
    * set to `8` hours
* `FundingRate = BaseRate + clamp(Premium / (FundingInterval / SettleInterval), -Clamp, Clamp)`
  * computed every `SettleInterval`
  * `BaseRate` is underlying interest rate of perpetual future per `SettleInterval`
    * set to `0`
  * `clamp(a, y, z)` clamps `a` between `y` and `z`
    * defined as
      * `a` if `y < a < z`
      * `y` if `a ≤ y`
      * `z` if `z ≤ a`
  * `Clamp` is maximum magnitude funding can take (before underlying interest) per `SettleInterval`
    * set to `0.005 = 0.5%`
  * `FundingRate` is considered as an amount per `SettleInterval`

**funding amount**

* `FundingAmount = FundingRate * Index`
  * computed every `SettleInterval`
  * the `FundingAmount` is the notional amount longs pay shorts per contract per `SettleInterval`

Note: Funding settlement occurs every `SettleInterval`. No settlement occurs at open/close of positions.
