> For the complete documentation index, see [llms.txt](https://vanilaprotocol.gitbook.io/vanila/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vanilaprotocol.gitbook.io/vanila/vanila-protocol/hedging.md).

# Hedging

In the [pricing section](/vanila/futures-contracts-1/pricing.md#protocol-pricing), the pricing formulas were derived to ensure that neither the protocol, nor the trader, could lock a risk free arbitrage profit (minus transaction fees). Hence, the protocol will follow some steps to hedge the long or short position taken by a trader. These steps will be realized atomically, i.e. in one transaction each time a trader buys or sells a futures. If for any reason the transaction fails then no position will be taken neither by the trader nor by the protocol.

|           | Bid                                                                                                                                                                                                                                                         | Ask                                                                                                                                                                                                                                                                                               |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Now       | <ul><li>Trader sells 1 unit of the base currency on the futures</li><li>Protocol borrows exp(-rBT) of the base currency from the liquidity pool</li><li>Protocol sells the borrowed amount on the spot market to synthesize a sell short position</li></ul> | <ul><li>Trader buys 1 unit of the base currency on the futures</li><li>Protocol borrows the amount needed of the quote currency from the liquidity pool to buy 1 unit of the base currency on the spot market</li><li>Protocol buys a unit of the base currency with the borrowed funds</li></ul> |
| At expiry | <ul><li>Protocol settles with the trader</li><li>Protocol gives back the borrowed funds including the accrued interest to the liquidity pool</li></ul>                                                                                                      | <ul><li>Protocol settles with the trader</li><li>Protocol gives back the borrowed funds including the accrued interest to the liquidity pool</li></ul>                                                                                                                                            |

**Example**

Given the price of ETHDAI on the spot market is 100, the borrowing rate on ETH is 4%, the borrowing rate on DAI is 5%, we have derived the bid and ask prices in the previous example for a futures expiring in 3 months, i.e. the bid price is 99.00 DAI and the ask price is 101.26 DAI. Each time a trader buys or sells a future, the protocol will realise the following steps supposing that no leverage is used, i.e. that the position is fully funded.<br>

|           | Bid                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Ask                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Now       | <ul><li>Trader sells 1 ETH for 99.00 DAI on the futures market</li><li>Protocol borrows 0.99 ETH from the liquidity pool at 4% and hence will owe 0.99\*exp(0.04/4)=1ETH in 3 months</li><li>Protocol sells 0.99 ETH in the spot market for 99 DAI</li></ul>                                                                                                                                                                                                                                    | <ul><li>Trader buys 1 ETH at 101.26 DAI on the futures market</li><li>Protocol borrows 100 DAI at 5% from the liquidity pool and hence will owe 100\*exp(0.05/4)=101.26 DAI in 3 months</li><li>Protocol buys 1 ETH with the borrowed DAI</li></ul>                                                                                                                                                                                                                                                                                                                                           |
| At expiry | <ul><li>Scenario 1: price at expiry is 150. The protocol makes 51 DAI of profit on the futures position. The total amount of DAI available is 99+51=150 DAI to buy 1 ETH</li><li>Scenario 2: price at expiry is 50. The protocol loses 49 DAI. The total amount of DAI available is 99-49=50 DAI to buy 1 ETH</li><li>By extrapolating the above scenarios, no matter the price at expiry, 1 ETH will be returned to the liquidity pool to cover the principal borrowed plus interest</li></ul> | <ul><li>Scenario 1: price at expiry is 150. The protocol loses 48.74 DAI on the futures position and, by selling the 1 ETH, the protocol gets 150 DAI, resulting in a total of 150-48.74=101.26 DAI</li><li>Scenario 2: price at expiry is 50. The protocol makes a profit of 51.26 DAI on the futures position and, by selling the 1 ETH, the protocol gets 50 DAI resulting in a total of 101.26 DAI</li><li>By extrapolating the above scenarios, no matter the price at expiry, 101.26 DAI will be returned to the liquidity pool to cover the principal borrowed plus interest</li></ul> |
