> ## 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.

# Oracles

For each market, there is a set of oracle inputs used for marking assets when computing margin and liquidations. This data is posted onchain for transparency and available via the public REST API. This data is provided by [Block Scholes](https://www.blockscholes.com/).

| Name | Description |
| - | - |
| Spot Price | Spot price of the market |
| Forward Price | Forward price for given expiry |
| Perp Price | Market Price perp contract is trading at |
| Implied Volatility | Implied volatility for expiry, strike |
| Risk Free Rate | Annualised interest rate for USD |

Feeds are published per market and are shared by every risk universe that lists that market.

Associated with each feed is a confidence score which ranges between 0 (low confidence) and 1 (high confidence). Confidence scores are used to calculate oracle contingencies for both standard and portfolio margin accounts.

# Implied Volatility

The implied volatility for each strike in a given expiry is obtained from a (raw) Stochastic Volatility Inspired (SVI) curve. Such a surface is characterised by 5 parameters. The implied volatility `(IV)` for a given strike is given by

```python Formula theme={null}
IV = sqrt((a + b * (rho * (k - m) + sqrt((k - m)**2 + e**2))) / tau)
```

Where:

* `a`, `b`, `rho`, `m`, `e` are parameters supplied by the data feed.
* `k = log(K / forward)` is the (natural) log moneyness of the given strike `K`.
* `tau` is time to expiry (in years).
* `Spot` is the spot price of the underlying base asset.

For large and near 0 strikes `K`, the minimum and maximum values of the log moneyness`k` is bounded between `k_min` and `k_max` where:

* `k_min = - MIN_SCALE * sqrt(a + b * sigma)`
* `k_max = MAX_SCALE * sqrt(a + b * sigma)`

and `(MIN_SCALE, MAX_SCALE) = (4,4)`.

In other words:

* if `k > k_max`, set `k = k_max` and
* if `k < k_min`, set `k = k_min`.

Essentially, the SVI curve flattens out past strikes 4 standard deviations (using ATM total implied volatility) away from the current spot.

Further, note that the maximum total implied volatility and total implied variance are capped to, respectively:

* `MAX_TOTAL_VOL = 24.0`
* `MAX_TOTAL_VAR = 144.0`

# Risk Free Rate

The rate feed is **signed** and may print negative. Both margin engines clamp it at zero before use, so a negative rate feed margins identically to a zero rate. Without the clamp a negative rate would inflate every option premium by `exp(-r * tau) > 1`, handing a long book extra credit and under-charging a short one off a feed glitch.

# Settlement Aggregates

The forward feed also carries the running inputs to the settlement TWAP for each expiry:

| Field | Meaning |
| - | - |
| `spot_aggregate_start` | Cumulative price x seconds at the start of the settlement window |
| `spot_aggregate_latest` | Cumulative price x seconds as of the feed's timestamp |
| `timestamp` | The time the feed was published |

The settlement price is the difference of the two aggregates divided by the seconds actually elapsed:

```python Formula theme={null}
window_start = expiry - SETTLEMENT_TWAP_PERIOD
elapsed      = min(feed_timestamp, expiry) - window_start
settlement   = (spot_aggregate_latest - spot_aggregate_start) / elapsed
```

# Confidence Scores

Every feed carries a confidence score. When it drops, both margin engines add an oracle contingency to **initial** margin only. Maintenance margin is never affected, so a degraded feed cannot by itself make an account liquidatable.

The two engines differ in the detail:

| | Standard Margin | Portfolio Margin |
| - | - | - |
| Threshold test | `confidence <= threshold` | `confidence < threshold` |
| Option feeds used | `min(Spot, Forward, Vol)` | `min(Spot, Forward, Vol, Perp)` |
| Options charged | short contracts only | long **and** short contracts |
| Perp feeds used | `min(Spot, Perp)` | `min(Spot, Perp)` |
| Collateral | token spot confidence | token spot confidence; risk cancelling collateral takes `min(currency, token)` |
| Scale | `OCFactor = 1.0` | `CONFIDENCE_SCALE = 0.4` |
| Threshold | `0.55` | `0.55` |

In both engines the charge has the same shape:

```python Formula theme={null}
Oracle Contingency = - SCALE * Size * Spot * (1 - confidence)
```


## Related topics

- [Standard Margin](/standard-margin.md)
- [Portfolio Margin Parameters](/untitled-page-3.md)
- [Portfolio Margin](/portfolio-margin.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.