# Contract Calculation

For a typical transaction of CFD, we have a set of states $\mathbb{S}$:

$\mathbb{S}=\{S_{open},\cdots,S_t,\cdots,S_{close}\}$
• $S_{open}$ is the state at the time which the position is opened.

• $S_{close}$ is the state at the time which the position is closed.

• $S_t$ is the state of each moment $t$ during the holding period of position.

For each transaction with a given set $\mathbb{S}$, trader deposit initial margin $m$ at $S_{open}$ and withdraw the remaining equity $e$ at $S_{close}$.

The amount of remaining equity $e$ is determined by $m$, $S_{open}$, $S_{close}$ and $S_{liquidation}$, which can be described as follows:

$e=\begin{cases} \boldsymbol{f}(m,S_{open},S_{close}),&S_{liquidation}\notin\mathbb{S}\\ \\ 0,&S_{liquidation}\in\mathbb{S} \end{cases}$
• $S_{liquidation}$ means the state that the liquidation is triggered.

To illustrate, if the liquidation is not triggered during the holding period of position, then $e$ shall be a function of $m$, $S_{open}$ and $S_{close}$, while if the liquidation is triggered during the holding period of position, then $e=0$.

Since $m$, $S_{open}$, $S_{close}$ and $S_{liquidation}$ are always known for any given moment of a position, $e$ can be calculated accordingly.

The calculation process of remaining equity $e$ is called contract calculation.