> For the complete documentation index, see [llms.txt](https://ch-docs.aftermath.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ch-docs.aftermath.finance/yong-xu-he-yue/architecture/margin.md).

# 保证金

Aftermath Perpetuals 的保证金系统保障协议的偿付能力，并规定开仓与持仓所需的保证金资产要求。

保证金是交易者为覆盖仓位和潜在亏损而存入的保证金资产。在 Aftermath 上，保证金用于支撑您的杠杆。如果账户价值跌破要求的保证金水平，您的仓位可能被强制平仓（清算）。

## 保证金率公式

保证金率是衡量账户健康度的首要指标，计算方式为**账户价值**（权益）与**仓位敞口**（按 `MaxNetBase` 调整）之比。

$$
{\small
\begin{align\*}
MarginRatio(p) &= \frac{
Collateral(p) \cdot CollateralPrice + UnrealizedFundings(p) + Pnl(p)\
}{
MaxNetBase(p) \cdot BasePrice
}
\end{align\*}
}%
$$

#### 理解 MaxNetBase

仓位的敞口由 `MaxNetBase` 决定。

$$
\small MaxNetBase(p) = \max { | BaseAmount(p) + PendingBids(p) | , | BaseAmount(p) - PendingAsks(p) | }
$$

{% hint style="info" %}
𝑀𝑎𝑥𝑁𝑒𝑡𝐵𝑎𝑠𝑒(𝑝) 的设计动机如下：我们取上式中的最大值而非 |𝐵𝑎𝑠𝑒𝐴𝑚𝑜𝑢𝑛𝑡(𝑝) + 𝑃𝑒𝑛𝑑𝑖𝑛𝑔𝐵𝑖𝑑𝑠(𝑝) − 𝑃𝑒𝑛𝑑𝑖𝑛𝑔𝐴𝑠𝑘𝑠(𝑝)|，否则用户可以挂出等量的买单和卖单而不增加杠杆，从而人为加深订单簿。
{% endhint %}

## 初始与维持保证金率（IMR/MMR）

**IMR**（初始保证金率）和 **MMR**（维持保证金率）是市场创建时设定的基础风险参数，代表杠杆的倒数：

* **IMR（初始）：决定开仓**时的最大杠杆。
  * \_示例：\_IMR 为 **0.1** 时，最大杠杆为 **10 倍**（$1 / 0.1$）。
* \*\*MMR（维持）：\*\*决定清算阈值。
  * \_示例：\_MMR 为 **0.05** 意味着仓位的有效杠杆达到 **20 倍**（$1 / 0.05$）时将被清算。

#### 治理

`AdminCapability` 的持有者可以调整这些参数以适应市场状况。但为保护用户：

1. 智能合约先将新值存储在链上。
2. 更新是**延时生效**的：需经过足够长的等待期（数天）才会生效，确保用户有时间调整仓位。

## 仓位保证金要求

特定仓位所需的绝对保证金计算如下：

$$
{\small
\begin{align}
MarginRequirements(p) &= MaxNetBase(p) \cdot BasePrice \cdot IMR\
\end{align}
}%
$$

#### 偿付能力检查

要验证仓位具备偿付能力（即保证金率健康），协议检查保证金率是否大于 IMR。这在数学上等价于检查**权益**是否覆盖**要求**：

$$
{\small
\begin{align}
MarginRatio(p) &> IMR
\\
&\equiv
\\
\frac{
Coll(p) \cdot CollPrice + UF(p) + Pnl(p)\
}{
MaxNetBase(p) \cdot BasePrice
} &>
\frac{
MaxNetBase(p) \cdot BasePrice \cdot IMR\
}{
MaxNetBase(p) \cdot BasePrice
}
\\
&\equiv
\\
\underbrace{
Coll(p) \cdot CollPrice + UF(p) + Pnl(p)
}*{\text{margin}(p)}
&>
\underbrace{
MaxNetBase(p) \cdot BasePrice \cdot IMR
}*{\text{margin\_requirements}(p)}
\end{align}
}%
$$

{% hint style="info" %}
要得到仓位的\_**维持保证金要求**\_，把 𝐼𝑀𝑅 替换为 𝑀𝑀𝑅 即可。
{% endhint %}
