# Position opening

## Pricing with margin

### Formulas

The formulas below present the price at which a trader could open a long position at a price $$P\_{O,L}$$ or a short position at a price $$P\_{O,S}$$ with an initial margin $$M$$ (other notations have been introduced in [theoretical pricing](/exchange/protocol/theoretical-pricing.md)).

<table><thead><tr><th width="150"> Side</th><th width="396.2857142857143">Price to open a position</th></tr></thead><tbody><tr><td>Long</td><td><span class="math">P_{O,L}=S_{L}*{ \bigg( \dfrac{1+r_{Q,b}}{1+r_{B,l}} \bigg) }^T  - M *[{(1+r_{Q ,b })}^T -1]</span></td></tr><tr><td>Short</td><td><span class="math">P_{O,S}=S_{S}*{ \bigg( \dfrac{1+r_{Q,l}}{1+r_{B,b}} \bigg) }^T + M *[{(1+r_{Q , l})}^T -1]</span></td></tr></tbody></table>

{% hint style="info" %}
Contango protocol provides a price improvement compared to the theoretical formulas presented in [theoretical pricing](/exchange/protocol/theoretical-pricing.md):

* &#x20;Since $$M \*\[{(1+r\_{Q ,b })}^T -1] > 0$$, the price to open a long position is at a lower price, i.e. more favourable to the trader.&#x20;
* Since $$M \*\[{(1+r\_{Q , l})}^T -1] > 0$$, the price to open a short position is at a higher price, i.e. more favourable to the trader.
  {% endhint %}

### Example

Let's consider a contract on ETHDAI expiring in 3 months ($$T=1$$) and where the traders posts $$50 :DAI$$ as margin:

* Given one could borrow DAI at a yearly fixed rate of $$r\_{Q,b}=10.10%$$​, lend ETH at a yearly fixed rate $$r\_{B,l}=2.90%$$and buy ETH on the spot market at $$S\_{L}=100.10:DAI$$ then the price at which a trader could open a long a position is:

$$P\_{O,L}=100.10\*{ \bigg( \dfrac{1+0.1010}{1+0.0290} \bigg) }^{0.25}  - 50 \*\[{(1+{0.1010})}^{0.25} -1] = 100.59 : DAI$$​

* Given one could borrow ETH at a yearly fixed rate of $$r\_{B,b}=3.10%$$​, lend DAI at a yearly fixed rate of $$r\_{Q,l}=9.90%$$and sell ETH on the spot market at $$S\_{S}=99.90:DAI$$ then the price at which a trader could open a short position is:

$$P\_{O,S}=99.90\*{ \bigg( \dfrac{1+0.0990}{1+0.0310} \bigg) }^{0.25}  + 50 \*\[{(1+{0.0990})}^{0.25} -1] = 102.70: DAI$$​

### Demonstration

#### Long

Let's consider that a trader wants to buy 1 expirable (the numerical values are taken from the above example). In this demonstration, we will present the steps to replicate the cash flows of a expirable position. Let's figure out the price of the expirable, i.e. the DAI money needed, to get 1 ETH at expiry:

1\. To receive 1 ETH at expiry, the trader needs to lend $$\dfrac{1}{(1+r\_{B,l})^T} : ETH$$, i.e.  $$0.9929 : ETH$$

2\. To get that ETH, the trader first swaps $$\dfrac{S\_{L}}{(1+r\_{B,l})^T} : DAI$$, i.e. $$99.39 : DAI$$.

3\. Since the trader has already some margin, she only needs to borrow $$\dfrac{S\_{L}}{(1+r\_{B,l})^T}  - M  : DAI$$, i.e. $$49.39 : DAI$$.

4\. The debt $$D$$ the trader owes at expiry (principal + interest) is: $$D = \[\dfrac{S\_{L}}{(1+r\_{B,l})^T}  - M] \* {(1+r\_{Q , b})}^T  : DAI$$, i.e. $$D=50.59 : DAI$$.

5\. Hence, the money needed to receive 1 ETH at expiry is the sum of the debt and the margin provided: $$\[\dfrac{S\_{L}}{(1+r\_{B,l})^T}  - M] \* {(1+r\_{Q , b})}^T + M  : DAI$$ or $$S\_{L}\*{ \bigg( \dfrac{1+r\_{Q,b}}{1+r\_{B,l}} \bigg) }^T  - M \*\[{(1+r\_{Q ,b })}^T -1] : DAI$$, i.e. $$100.59 : DAI$$.

#### Short

Let's consider a trader who wants to sell 1 expirable (the numerical values are taken from the example above). This means she would give 1 ETH at expiry, let's figure out the steps and how much money she would need to receive at expiry:

1\. The trader will give 1 ETH at expiry to reimburse a debt. Hence the trader borrows $$\dfrac{1}{(1+r\_{B,b})^T} : ETH$$, i.e. $$0.9924 : ETH$$.

2\. The trader swaps the ETH to get  $$\dfrac{S\_{S}}{(1+r\_{B,b})^T} : DAI$$, i.e. $$99.14 : DAI$$.

3\. The trader lends the DAI from the swap and her margin. At expiry the trader receives an amount $$L=\[\dfrac{S\_{S}}{(1+r\_{B,b})^T}  + M] \*{(1+r\_{Q , l})}^T        : DAI$$, i.e. $$L=152.70 : DAI$$.

4\. The amount of money the trader will receive at expiry, which is also the price of the expirable, is the difference between the amount L and the margin: $$\[\dfrac{S\_{S}}{(1+r\_{B,b})^T}  + M] *{(1+r\_{Q , l})}^T - M  : DAI$$ or  $$S\_{S}*{ \bigg( \dfrac{1+r\_{Q,l}}{1+r\_{B,b}} \bigg) }^T + M \*\[{(1+r\_{Q , l})}^T -1] : DAI$$, i.e. $$102.70 : DAI$$.

## Pricing with margin ratio

### Formulas

Given the [margin ratio](/exchange/resources/glossary.md#margin-ratio) $$MR$$:

* &#x20;the margin for a long position could be expressed as $$M = MR\*P\_{O,L}$$, e.g. if the price to open a long position is $$P\_{O,L}=100 :DAI$$ and if the trader wants a margin ratio of 50%, then the required margin is $$M=50 :DAI$$
* the margin for a short position could be expressed as $$M = MR\*P\_{O,S}$$, e.g. if the price to open a short position is $$P\_{O,S}=100 :DAI$$ and if the trader wants a margin ratio of 50%, then the required margin is $$M=50 :DAI$$

Replacing the margin $$M$$ in the main [pricing formula](/exchange/protocol/protocol-pricing/position-opening.md) to open a position, we find new expressions depending on the collaterisation ratio $$MR$$ :&#x20;

<table><thead><tr><th width="150"> Side</th><th width="571.7557531380754">Price to open a position</th></tr></thead><tbody><tr><td>Long</td><td><span class="math">P_{O,L}=S_{L}*{ \bigg( \dfrac{1+r_{Q,b}}{1+r_{B,l}} \bigg) }^T * \dfrac{1}{1+MR*[{(1+r_{Q ,b })}^T -1]}</span></td></tr><tr><td>Short</td><td><span class="math">P_{O,S}=S_{S}*{ \bigg( \dfrac{1+r_{Q,l}}{1+r_{B,b}} \bigg) }^T  * \dfrac{1}{1-MR*[{(1+r_{Q ,l })}^T -1]}</span></td></tr></tbody></table>

### Example

Let's consider a contract on ETHDAI expiring in 3 months ($$T=1$$) where the trader puts a $$50%$$MR:

* Given one could borrow DAI at a yearly fixed rate of $$r\_{Q,b}=10.10%$$, lend ETH at a yearly fixed rate $$r\_{B,l}=2.90%$$ and buy ETH on the spot market at $$S\_{L}=100.10:DAI$$then the price at which a trader could open a long a position is:

$$P\_{O,L}=100.10\*{ \bigg( \dfrac{1.1010}{1.0290} \bigg) }^{0.25} \* \dfrac{1}{1+0.5\*\[{(1.1010)}^{0.25} -1]}=100.68:DAI$$

* Given one could borrow ETH at a yearly fixed rate of $$r\_{B,b}=3.10%$$, lend DAI at a yearly fixed rate of $$r\_{Q,l}=9.90%$$, and sell ETH on the spot market at $$S\_{S}=99.90:DAI$$ then the price at which a trader could open a short position is:

$$P\_{O,S}=99.90\*{ \bigg( \dfrac{1.0990}{1.0310} \bigg) }^{0.25}  \* \dfrac{1}{1-0.5\*\[{(1.0990)}^{0.25} -1]}=100.31:DAI$$


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://contango-2.gitbook.io/exchange/protocol/protocol-pricing/position-opening.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
