The funding rate is accrued continuously on the position size, and paid to/from the margin account in collateral currency at spot. Funding payments are realized when a trader modifies her position size, i.e. by performing an opening or closing trade.
Opening Trades
Opening a position or increasing the size of an existing position:
Locked-in-Value += Index Price * Trade Amount
Cash in margin account += ((Execution Price - Index Price) * Trade Amount
- Fee rate * |Trade Amount| * Index Price) / Collateral spot price
- Accumulated funding since last trade
Closing Trades
Closing or reducing the size of an existing position:
Locked-in-Value += Average Entry Price * Trade Amount
where
Average Entry Price = |Locked-in-Value| / |Position size|
Cash in margin account += ((Execution Price - Index Price) * Trade Amount
- Fee rate * |Trade Amount| * Index Price) / Collateral spot price
- Accumulated funding since last trade
Position Marking
The mark price determines Margin Account calculations and Liquidations.
Unrealized PnL
Current profit and loss of a given open position, in collateral currency: