# Margin Engine

The Margin Engine is the off-chain, high-performance risk computation core of Arkis. It operates as a horizontally scalable service responsible for enforcing portfolio-level margin requirements, calculating Risk Factors, and preparing liquidation plans when thresholds are breached. While Arkis is a decentralized trading ecosystem, the Margin Engine plays a centralized but transparent role in maintaining system solvency and lender capital protection.

### **Core Responsibilities**

1. Real-Time Portfolio Evaluation
   * Continuously monitors all active [Margin Accounts](/home/concepts/margin-account.md) (across chains).
   * Aggregates data on borrowed assets, collateral balances, and open protocol positions.
   * Calculates portfolio market value and stress-tested value based on configurable rules.
2. Risk Factor Computation
   * Calculates the Risk Factor for every Margin Account as:
   * Triggers margin call alerts when Risk Factor < pre-defined thresholds.
   * Triggers liquidation execution when Risk Factor < liquidation threshold (e.g. 1.0).
3. Liquidation Planning & Execution
   * Generates a deterministic liquidation plan.
4. Stress-Test Evaluation
   * Applies custom stress scenarios per asset class and pool.
   * Supports:
     * VaR-based simulations
     * Curve LP slippage models
     * Pendle PT maturity modeling
   * Stores and reuses calculated stress values for efficient re-evaluation every 30 seconds.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arkis.xyz/home/concepts/margin-engine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
