Image of the program code showing with Bitcoin

Futures contract on Bitcoin

This post was first published on Medium.

In this article we will explore the implementation of a futures smart contract on Bitcoin. Putting financial derivatives on chain, such as forwards and options we introduced before, can potentially make them more secure, efficient, and transparent.

Bitcoin with violet background

What is a Futures contract?

Futures contracts are standardized financial agreements to buy or sell a specified quantity of an underlying asset at a predetermined price on a future date. These contracts are traded on organized futures exchanges, and they play a crucial role in risk management, price discovery, and facilitating market liquidity.

Futures contracts serve various purposes, including risk management for hedgers, speculation for traders seeking profit from price movements, and price discovery for the broader market. They are an integral part of financial markets and contribute to overall market efficiency.

Margin

In futures trading, margin refers to the amount of money or collateral that traders are required to deposit with their brokers in order to open and maintain a futures position. This is known as futures margin. Margin requirements are set by the exchanges and the brokerage firms, and they are designed to ensure that traders have enough funds to cover potential losses in their positions.

Here are key points regarding margin in futures trading:

  1. Initial Margin: the amount of money that must be deposited when a futures position is opened. It acts as a security deposit and is a percentage of the total value of the futures contract.
  2. Maintenance Margin: Once a futures position is open, traders must maintain a certain level of funds in their trading accounts, known as maintenance margin. If the account balance falls below this level, the trader may receive a margin call.
  3. Variation Margin: Also known as marking-to-market, variation margin represents the daily settlement of gains and losses in a futures position, helping maintain the required margin levels. It ensures that the trader’s account balance reflects the current market value of the position.

Margin Call

A margin call occurs when the account balance falls below the maintenance margin level. The trader is then required to deposit additional funds to meet the initial margin requirement. Margin calls help prevent situations where traders are unable to cover their losses, ensuring that the market remains orderly and that traders fulfill their financial obligations.

Example

Let’s go through a simple example to illustrate how margin works in futures trading: suppose you want to trade a single futures contract for XYZ Company, and the contract has a notional value of $100,000. The exchange sets an initial margin requirement of 5% and a maintenance margin requirement of 3%.

1. Initial Margin Calculation:

The initial margin required to open the position is calculated as follows: Initial Margin=Notional Value×Initial Margin Requirement = $100,000 * 0.05 = $5,000. Therefore, you would need to deposit $5,000 as an initial margin to open the futures position.

2. Maintenance Margin Calculation:

The maintenance margin is calculated similarly to the initial margin: Maintenance Margin=Notional Value×Maintenance Margin Requirement = $100,000 * 0.03 = $3,000

After opening the position, you need to maintain at least $3,000 in your trading account.

3. Variation Margin:

Let’s say the market moves against you, causing a loss of $2,000 on your position. The variation margin, also known as marking-to-market, is the daily settlement of gains and losses. In this case, you would need to deposit an additional $2,000 to meet the maintenance margin requirement and keep the position open.

4. Margin Call:

If your account falls below the maintenance margin of $3,000, you would receive a margin call. To meet the call, you need to deposit funds to bring the margin back to the initial level.

Implementation

The futures smart contract below settles in cash. Parties settle the monetary difference between the contract price and the market price at the settlement date. This process negates the need to physically exchange the underlying asset.

  • Margin accounts: The contract manages margin accounts for both the buyer and the seller, adjusting them according to the asset’s market price fluctuations. The initial margin is deposited by both parties upon the deployment of the contract.
  • Settlement by difference: On the settlement date or upon a margin call, the contract calculates the difference between the initial and current asset values, and this difference is exchanged in satoshis. This approach means that the entire value of the underlying asset does not change hands; only the net difference is settled.

The contract exposes the following public methods:

  • settle: This method marks the futures contract to the market based on the latest market information. It is typically called in response to changes in the market price of the underlying asset, obtained from an oracle. If the margin balance of either party falls below the maintenance threshold, she will receive a margin call.

Settle screenshot code

  • marginCall: This method is used to meet a margin call, where either the buyer or seller must deposit additional funds to meet the maintenance margin requirements.

MarginCall code inline

  • close: This method is used to close the futures contract. It can be called either when the settlement date is reached or after a margin call deadline has passed. The contract will release the deposited margin balances to the respective party.

Code screenshot

The full code of the smart contract is available on GitHub.

Watch: sCrypt makes smart contracts possible on the BSV blockchain

YouTube video

New to blockchain? Check out CoinGeek’s Blockchain for Beginners section, the ultimate resource guide to learn more about blockchain technology.