# 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](https://docs.arkis.xyz/home/concepts/margin-account) (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.
