AMM Mean Reversion Backtest
Overview
The AMM Mean Reversion Backtest component simulates trading strategy performance using historical DEX pool data while accounting for realistic trading conditions, including:
Price impact from pool reserves
Gas costs and fee deductions
Slippage simulation
Portfolio balance tracking
How It Works
Data Retrieval: The backtest first fetches historical candle and liquidity data for the specified pair and timeframe using
TradingStrategyDataManager
. Gas data is fetched using.GasDataManager
.Average Price Calculation: For each day (or selected interval), it computes the moving average of the asset’s price over the chosen time window.
Trade Signal Generation:
If current price < average price * (1 - threshold), it’s a BUY signal.
If current price > average price * (1 + threshold), it’s a SELL signal.
Otherwise, no trade is executed.
Trade Simulation: On a trade signal, the strategy uses
AMMPriceSimulator
To:Calculate the expected amount out based on current pool reserves.
Apply trading fees, slippage, and gas costs.
Update the pool’s reserves and the strategy’s balances accordingly.
Performance Tracking: With each simulated trade, the system records:
P&L: How balances evolve over time.
Slippage costs: Difference between theoretical and realized price.
Gas fees: Deducted from quote (or base) balances, representing real trading friction.
Result Compilation: At the end of the backtest, the component produces:
Final portfolio value in base/quote assets and USD.
Total number of trades, average slippage, and cumulative gas fees.
Performance metrics (percentage returns, drawdowns, etc.)
Backtest Execution Flow

Output Metrics
After the backtest is complete, here are some key metrics available:
Backtest Period:
Start Time, End Time
Total Duration
Configuration:
Exchange Name, Chain, Trading Pair
Threshold, Trade Amount
Initial and Final Pool States:
TVL, prices, and reserve amounts in USD
Gas Balance Summary:
Total Gas Used
Remaining Gas balance
Trades Analysis:
Number of buy and sell trades
Total trade volume in base and quote assets
Average prices for executed trades
Performance Analysis:
Total portfolio value at start and end
Total gas fees (native and USD)
Slippage cost (native and USD)
Total P&L and percentage return.
Last updated