> ## Documentation Index
> Fetch the complete documentation index at: https://docs.derive.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Standard Margin

Standard margin evaluates each position’s margin in isolation, with the exception of spreads whose margin requirements can be offset for the same expiry. It is the default margin option for traders.

Every risk universe runs its own standard margin manager. A standard margin subaccount can hold every option, perpetual and collateral token that **its universe** lists, and nothing else.

If a standard margin sub-acccount falls below its maintenance margin requirement, the account will be liquidated. See the write up on Liquidations for more details.

# Margin Calculation

The standard margin requirement is calculated by summing an account’s margin requirement for its perpetual and option positions and then adding the value of its cash balance and base assets (with haircut). For each market, the margin is calculated as follows:

```python Formula theme={null}
Initial Margin = Cash + Collateral + Perp Margin + Option Margin
    + Depeg Contingency + Oracle Contingency

Maintenance Margin = Cash + Collateral + Perp Margin + Option Margin
```

Where:

* `Perp Margin` is the margin requirement for all perpetuals in the account, calculated as a simple percentage of the underlying’s spot price. The profit and loss of said perpetuals, as well as owed/owing funding is included in this value.
* `Option Margin` is the margin requirement for all options in the account, typically calculated as the sum of isolated margin for each option, with the possibility for margin offsets for spreads and other multi-legged strategies within the same expiry.
* `Depeg Contingency` is extra initial margin conditionally required to protect against the cash asset depegging.
* `Oracle Contingency` is extra initial margin conditionally required to protect against inaccurate oracle data feeds.
* `Cash` is the subaccount's balance of the universe's cash asset (which can be positive or negative)
* `Collateral` is the value of the base assets held (or borrowed) in the subaccount, after a risk based haircut.

Each margin component has slightly greater initial margin requirements compared to maintenance margin requirements. This is applied via parameterization. Read the sections below for more details.

Both initial and maintenance margin are centred around zero. I.e. a sub-account is subject to liquidation if its `Maintenance Margin` is negative (see [Liquidations](doc:liquidations) for more details) and a sub-account is only able to open a new position if its final `Initial Margin` is positive. See the end of this page for more detail on this and risk reducing trades.

## \[New!] Collateral

Collateral is credited by a multiplicative **haircut factor**. This is a change of convention from V2, which subtracted a discount; the two express the same thing, but the V3 factor is the fraction of value that **counts**, and it is exactly the `marginFactor` configured on chain.

```python Formula theme={null}
Collateral(MM) = Σ_long Baseₘ * Spotₘ * MM_HAIRCUTₘ
               - Σ_short abs(Baseₘ) * Spotₘ * MM_SHORT_HAIRCUTₘ

Collateral(IM) = Σ_long Baseₘ * Spotₘ * IM_HAIRCUTₘ
               - Σ_short abs(Baseₘ) * Spotₘ * IM_SHORT_HAIRCUTₘ
```

Where:

* `Baseₘ` is the account’s balance of base asset `m`, positive if held and negative if borrowed.
* `MM_HAIRCUTₘ` is the **long factor**, always `< 1`. BTC is `0.75`, i.e. 1 BTC at $100,000$ contributes 75,000 towards maintenance margin.
* `IM_HAIRCUTₘ = MM_HAIRCUTₘ x imScaleₘ` is the long factor used for initial margin, always at or below the maintenance factor. BTC is `0.6975`.
* `MM_SHORT_HAIRCUTₘ` / `IM_SHORT_HAIRCUTₘ` are the **short factors**, always `> 1`. BTC is `1.3` for maintenance, i.e. borrowing 1 BTC at 100,000 requires 130,000 of margin.
* `Spotₘ` is the spot price of base asset `m`.

### The cash asset

The universe's cash asset carries a row of the same shape, so the quote is a configurable currency like any other. At launch USDC ships with a factor of `1.0` long and short: cash counts at face value and borrowing it carries no haircut beyond the interest rate. Protection against the cash asset losing its peg is handled separately, by the depeg contingency below.

## Perpetuals Margin

All perpetuals have margin requirements proportional to the spot price. This percentage is larger when computing initial margin, and is set per currency:

```python Formula theme={null}
Initial Perpetual Margin = -abs(Size) * perp_im * Spot
Maintenance Perpetual Margin = -abs(Size) * perp_mm * Spot
```

Where:

* `Size` is the number of perpetual contracts (this number is negative for shorts).
* `perp_im`, `perp_mm` are per-currency requirements — `0.066` / `0.05` for BTC and ETH, `0.1` / `0.08` for HYPE, `0.2` / `0.15` for ADA.
* `Spot` is the spot price of the underlying base asset.

## Option Margin

Options are typically margined in isolation, with the exception of spreads and multi-legged strategies whose margin requirements can be offset for the same expiry.

The option margin for an account is the sum of each expiry’s margin, which is calculated by grouping positions per expiry, summing their isolated margin and offsetting spreads and multi-legged strategies where possible.

Options with different underlyings (ETH, BTC) are margined separately and then added together. I.e. the option margin of all ETH options is found, then added to that for all BTC options to get the total option margin for the subaccount. In the following, we focus on computing the option margin for a single underlying; the option margin for a subaccount with multiple underlyings is easily found given this.

### Isolated Margin

The isolated margin of an option for strike price `j` is calculated as follows:

For long calls and puts:

```python Formula theme={null}
Initial Isolated Option Marginⱼ = None 
Maintenance Isolated Option Marginⱼ = None
```

For short calls:

```python Formula theme={null}
Initial Isolated Option Marginⱼ = n * (-max(maxSpotReqCall - OTMⱼ/Spot, minSpotReqCall) * Spot
    + Mark Priceⱼ)
Maintenance Isolated Option Marginⱼ = n * (-mmCallSpotReq * Spot + Mark Priceⱼ)
```

For short puts:

```python Formula theme={null}
Initial Isolated Option Marginⱼ = n * (-max((maxSpotReqPut - OTMⱼ/Spot) * Spot,
    maxStrikeReqPut * Strikeⱼ) + Mark Priceⱼ)

Maintenance Isolated Option Marginⱼ = n * (-min(mmPutStrikeReq * Strikeⱼ,
    mmPutSpotReq * Spot) + Mark Priceⱼ)
```

Where:

* `n` is the number of short options held
* `OTM` is the out-the-money amount. For calls, `OTM = max(0, Strike - Spot)` and for puts, `OTM = max(0, Spot - Strike).`
* `Spot` is the spot price of the underlying base asset.
* `Strikeⱼ` is the strike of the option.
* `Mark Price` is the mark-to-market value of the option calculated using [Black76](https://en.wikipedia.org/wiki/Black_model), discounted at the expiry's risk free rate. Since the option is short, this is a negative quantity.
* For BTC and ETH, `(maxSpotReqCall, minSpotReqCall, mmCallSpotReq) = (0.15, 0.13, 0.09)` and `(maxSpotReqPut, maxStrikeReqPut, mmPutSpotReq, mmPutStrikeReq) = (0.15, 0.13, 0.09, 0.09)`.

> 📘 **\[New!] Short put requirements are now anchored to the strike.** In V2 the put floor was a flat percentage of spot. In V3 the initial margin takes the *larger* of a spot-based and a strike-based leg, and the maintenance margin takes the *smaller* of the two. For a deep out-of-the-money put where the old spot leg could fall to nothing the strike leg keeps the requirement meaningful; for a deep in-the-money put the maintenance requirement is capped by the spot leg.

> 📘 **\[New!] Option marks are discounted.** Standard margin now prices options with the expiry's risk free rate rather than assuming zero discounting. A negative rate feed is clamped to zero, so it margins identically to a zero rate.

### Expiry Margin

The default margin of expiry `i` is calculated by summing the isolated margin of each option in the account for that expiry:

```python Formula theme={null}
Default Initial Marginᵢ = Σ Initial Marginⱼ
Default Maintenance Marginᵢ = Σ Maintenance Marginⱼ
```

We also compute an offset margin for expiry `i` to offset spreads and other multi-legged strategies. This is made up of 2 components:

1. The minimum intrinsic value of the expiry’s options evaluated at all strikes in with this expiry (including the zero strike), floored at 0.
2. A percentage of the expiry's forward price multiplied by the number of "naked" short calls in the expiry.

**Note**: Naked short calls in an expiry are found by summing the net positions over all calls in the expiry and capping the result at 0, i.e.

```python Formula theme={null}
Naked Short Call Size = -max(Number of Short Calls - Number of Long Calls, 0)
```

For example, if an expiry has 3 short calls on the 1600 strike and 2 long calls on the 1800 strike, then Naked Short Call Size is simply -1. Combining all of this, we have

```python Formula theme={null}
Offset Initial Marginᵢ = min(Intrinsic Valueᵢ, 0)
    + UNPAIRED_SCALE_IM * Naked Short Call Sizeᵢ * Forward Priceᵢ

Offset Maintenance Marginᵢ = min(Intrinsic Valueᵢ, 0)
    + UNPAIRED_SCALE_MM * Naked Short Call Sizeᵢ * Forward Priceᵢ
```

Where:

* `Intrinsic Valueᵢ` is the intrinsic value of all options in the expiry evaluated at each strike `k` for expiry `i` (including the zero strike).
* `Naked Short Call Sizeᵢ` is the number of naked short call contracts open in the expiry `i`.
* `Forward Priceᵢ` is the forward price for the expiry `i`.
* `UNPAIRED_SCALE_IM = 1.2` scales naked short calls for initial margin requirements.
* `UNPAIRED_SCALE_MM = 1.1` scales naked short calls for maintenance margin requirements.

The final margin for expiry `i` is then the better (larger) of the default expiry margin and offset expiry margin:

```python Formula theme={null}
Initial Marginᵢ = max(Default Initial Marginᵢ, Offset Initial Marginᵢ)
Maintenance Marginᵢ = max(Default Maintenance Marginᵢ, Offset Maintenance Marginᵢ)
```

Note that both `Default Initial Margin` and `Offset Initial Margin` are negative, so the above takes the more lenient margin requirements for the trader.

### \[New!] Settled Expiries

Once an expiry has settled, its value is fixed at the settlement TWAP and it carries no remaining spot risk. Neither the isolated percentage-of-spot requirement nor the spread scenario search applies, i.e. both explore spot moves that can no longer happen. The requirement is simply the realized payoff, floored at zero:

```python Formula theme={null}
Marginᵢ = min(0, Payoffᵢ(Settlement Price))
```

The floor preserves the standard margin convention that long options earn no collateral credit.

### Total Margin

Finally, the total option margin for an account is the sum of each expiry’s margin:

```python Formula theme={null}
Option Initial Margin = Σ Initial Marginᵢ
Option Maintenance Margin = Σ Maintenance Marginᵢ
```

## Depeg Contingency

When the cash asset depegs from \$1, additional initial margin requirements are added:

```python Formula theme={null}
Depeg Contingency = -max(0, depeg_threshold - Cash Asset Value) * Spot * depegFactor
    * (Σ Short Option Sizeⱼ + abs(Perp Size))
```

Where:

* `Cash Asset Value` is the market value of the universe's cash asset.
* `Spot` is the spot price of the underlying base asset.
* `Short Option Sizeⱼ` is the absolute number of contracts for a short option with strike `j` in the account.
* `Perp Size` is the number of perpetual contracts (this number is negative for shorts).
* `depeg_threshold = 0.99` is the threshold value that triggers a depegging event.
* `depegFactor = 2.0` scales the depeg contingency.

Note that this is the depeg contingency for a given underlying (say, ETH). For multiple underlying assets, the relevant asset's spot and corresponding subaccount positions are used.

> 📘 When the cash asset's value (reported by oracle data feeds) is greater than the depegging threshold, the depeg margin requirement is \$0.

## Oracle Contingency

Associated to each oracle data feed is a confidence score; a metric for the feed's reliability and accuracy. When confidence scores are below a given threshold, this indicates the data feeds could be feeding inaccurate price data into the system, and the protocol automatically introduces additional initial margin requirements.

The oracle contingency is the sum of collateral, perpetual and option oracle contingencies:

```python Formula theme={null}
Collateral Oracle Contingency = - OCFactor * Collateral Balance * Spot
    * (1 - Spot Confidence) if Spot Confidence <= oc_collateralThreshold, otherwise 0
```

```python Formula theme={null}
Perp Oracle Contingency = - OCFactor * abs(Perp Size) * Spot
		* (1 - min(Spot Confidence, Perp Confidence))
  if min(Spot Confidence, Perp Confidence) <= oc_perpThreshold, otherwise 0
```

```python Formula theme={null}
Option Oracle Contingency = - OCFactor * abs(Short Options Size) * Spot
    * (1 - min(Spot Confidence, Forward Confidence, Vol Confidence))
  if min(Spot Confidence, Forward Confidence, Vol Confidence) <= oc_optionThreshold, otherwise 0 
```

I.e.

```python Formula theme={null}
Oracle Contingency = Collateral + Perp + Option Oracle Contingencies
```

Where:

* `OCFactor = 1.0` is a constant scaling factor.
* `Short Options Size` is the number of **short** options contracts for the relevant feeds, i.e. long options are not charged.
* `Perp Size` is the number of perpetual contracts open in the account.
* `Spot Confidence` is confidence score of the spot price data.
* `Forward Confidence` is confidence score of the forward data.
* `Vol Confidence` is confidence of the implied volatility data.
* `Perp Confidence` is confidence of the perpetual price data.
* `oc_collateralThreshold = oc_perpThreshold = oc_optionThreshold = 0.55` represent the thresholds at or below which extra initial margin is added due to low confidence.

## Open Interest Caps

Each universe caps the open interest, spot supply and spot borrow of every instrument its standard manager supports.

# Risk Reducing Trades and Risk Assessors

On the smart contract level, the standard risk manager will allow any trade to be conducted so long as it satisfies either of the following conditions:

* the initial margin of the portfolio after the transaction is conducted is positive (`IM(post) > 0`) OR
* the trade is *risk reducing*

To clarify the last point, we say a trade is *risk reducing* if it consists of one of the following transactions:

* Adds a long option
* Adds a positive amount of the cash asset
* Adds base collateral
* Closes a perpetual

It is highly desirable to always allow users to be able to close risky positions. For example, suppose a trader has a short ETH 1700 call with 300 of USDC as collateral. Perhaps the trader wishes to de-risk and buy back 0.5 of this call with some of their USDC.

On the smart contract layer, this transaction does not satisfy the second condition (since cash will be taken from the account to buy back the option). Further, if the option is sufficiently risky, there is no guarantee that the first condition will be satisfied either. This is problematic, since the above conditions would otherwise prohibit users from de-risking their portfolios.

This motivates the existence of **risk assessors (RAs)**; entities permitted to skip certain risk checks (see [Portfolio Margin](doc:portfolio-margin)) and/or allow certain trades not normally allowed by the managers.

Specifically for the standard manager, the risk assessor will have special logic to always allow users to close risky (i.e. short) positions. On-chain, the managers will always verify that all accounts have positive maintenance margin.

**This means that a malicious risk assessor can never open liquidatable (nor insolvent) positions**.

The worst that such a nefarious entity can do is refuse to permit users from closing risky positions (short options, etc) (but this can still be done permissionlessly on-chain).

# Examples

All examples below are in the **Prime** universe, which hosts BTC and ETH.

## Example 1: A simple short call

ETH is trading at \$1900.

Account:

* \$2000 of USDC
* 3.0 short ETH 1800 calls expiring in 3 weeks, mark price  120 per call.

We have:

```python Formula theme={null}
Cash = 2000
```

Since ETH is at \$1900, we have `OTM = max(0,1800-1900)=0`.

```python Formula theme={null}
Initial Margin(short calls) = 3 * (-max(0.15 - 0/1900, 0.13) * 1900 - 120) = -$1215
Maintenance Margin(short calls) = 3 * (-0.09 * 1900 - 120) = -$873
```

Thus:

```python Formula theme={null}
Initial Margin = -1215 + 2000 = $785
Maintenance Margin = -873 + 2000 = $1127
```

Since both the maintenance and initial margin are positive, the subaccount is not liquidatable and new positions may be added.

## Example 2: A short put (new put logic)

ETH is trading at \$2000.

Account:

* \$2500 of USDC
* 2.0 short ETH 2400 puts, mark price 430 per put.

The put is in the money, so `OTM = max(0, 2000 - 2400) = 0`. For initial margin we compare the two legs:

```python Formula theme={null}
Spot leg   = (maxSpotReqPut - OTM/Spot) * Spot = (0.15 - 0) * 2000 = $300
Strike leg = maxStrikeReqPut * Strike          = 0.13 * 2400       = $312
```

Initial margin takes the **larger**, here the strike leg:

```python Formula theme={null}
Initial Margin(short puts) = 2 * (-312 - 430) = -$1484
```

Maintenance margin takes the **smaller** of its two legs:

```python Formula theme={null}
Spot leg   = mmPutSpotReq * Spot     = 0.09 * 2000 = $180
Strike leg = mmPutStrikeReq * Strike = 0.09 * 2400 = $216

Maintenance Margin(short puts) = 2 * (-180 - 430) = -$1220
```

Thus:

```python Formula theme={null}
Initial Margin = -1484 + 2500 = $1016
Maintenance Margin = -1220 + 2500 = $1280
```

## Example 3: Spread Logic

Account:

* \$2000 of USDC
* 8 x SHORT \$1700 ETH calls expiring in 2 weeks
* 8 x LONG \$1900 ETH calls expiring in 2 weeks

Assume that ETH is trading at 2100 and the 2 weekly forward at 2105.

Let’s begin by computing the default margin.

```python Formula theme={null}
Default Margin = margin(SHORT 1700 call) + margin(LONG 1900 call)
```

Since long options contribute nothing to the default margin, we only have to compute the margin of the short \$1700 call.

Assuming an implied volatility of 92.5%, the mark price of the 1700 call is 425. We have:

```python Formula theme={null}
Default Initial Margin = 8 * (-max(0.15 - 0/2100, 0.13) * 2100 - 425) = -5920
Default Maintenance Margin = 8 * (-0.09 * 2100 - 425) = -4912
```

Next, we compute the offset margin. In the 2 week expiry there are 8 long calls and 8 short calls; thus, there are no naked calls. We compute the intrinsic value at all relevant strikes (0, $1700, $1900) in the table below:

| Strike | Intrinsic Value |
| ------ | --------------- |
| \$0    | 0               |
| \$1700 | 0               |
| \$1900 | -\$1600         |

Thus, we have

```python Formula theme={null}
Offset Margin = -1600
```

Finally,

```python Formula theme={null}
Initial Option Marginᵢ = max(-5920, -1600) = -1600
Maintenance Option Marginᵢ = max(-4912, -1600) = -1600
```

and so both the initial and maintenance option margin are -\$1600. We thus have

```python Formula theme={null}
Initial Margin = -1600 + 2000 = +400 
Maintenance Margin = -1600 + 2000 = +400
```

## Example 4: Multi Asset Account with a Borrow

Account (Prime universe):

* \$25,000 USDC
* 0.5 BTC held as collateral
* 5.0 ETH **borrowed**
* 8 x SHORT 1700 ETH calls / 8 x LONG 1900 ETH calls expiring in 2 weeks
* 0.3 x LONG BTC perpetuals (with no unrealized PNL or funding)

Assume BTC (and its perpetual) trade at 100,000 and ETH at 2,100, as in Example 3.

From Example 3:

```python Formula theme={null}
Initial Option Margin(ETH) = -1600
Maintenance Option Margin(ETH) = -1600
```

The BTC collateral is credited by its haircut factors:

```python Formula theme={null}
Collateral(BTC, MM) = 0.5 * 100,000 * 0.75   = $37,500
Collateral(BTC, IM) = 0.5 * 100,000 * 0.6975 = $34,875
```

The borrowed ETH is charged by its short factors:

```python Formula theme={null}
Collateral(ETH, MM) = -5 * 2,100 * 1.24 = -$13,020
Collateral(ETH, IM) = -5 * 2,100 * 1.30 = -$13,650
```

The perpetual is charged at its per-currency requirement:

```python Formula theme={null}
Initial Margin(BTC Perp) = -0.3 * 0.066 * 100,000 = -$1,980
Maintenance Margin(BTC Perp) = -0.3 * 0.05 * 100,000 = -$1,500
```

Thus, the total margin requirements for the account are:

```python Formula theme={null}
Initial Margin = 25,000 + 34,875 - 13,650 - 1,600 - 1,980 = $42,645
Maintenance Margin = 25,000 + 37,500 - 13,020 - 1,600 - 1,500 = $46,380
```

## Example 5: General Case

Consider the same subaccount as in example 4, but now assume:

* The confidence of the BTC perp feed decreases to 0.50 (below the threshold of 0.55) and
* The market price of USDC depegs to \$0.70.

Let’s now compute the oracle and depeg contingencies. We have

```python Formula theme={null}
Perp Oracle Contingency(BTC) = -1.0 * 0.3 * 100,000 * (1 - 0.5) = -$15,000
```

For the depeg contingency, we have

```python Formula theme={null}
Depeg(ETH) = -max(0, 0.99 - 0.70) * 2100 * 2.0 * 8 = -$9,744
Depeg(BTC) = -max(0, 0.99 - 0.70) * 100,000 * 2.0 * 0.3 = -$17,400
```

So the margin requirements of the subaccount become

```python Formula theme={null}
Initial Margin = 42,645 - 15,000 - 9,744 - 17,400 = $501
Maintenance Margin = $46,380
```

The account is still able to open new positions, but only just and a further deterioration of either feed would block it.


## Related topics

- [Standard Margin Parameters](/untitled-page-2.md)
- [Portfolio Margin](/portfolio-margin.md)
- [Risk Universes](/risk-universes.md)
