-
Data Generation
- Generate or load synthetic market data (ETH prices, funding rates) using
generate_data.nim.
- Generate or load synthetic market data (ETH prices, funding rates) using
-
Liquidity Pool Setup
- Initialize liquidity positions in Uniswap V2 ETH/USDC pool.
-
Hedging Initialization
- Establish initial hedge by shorting ETH perpetual futures on Binance.
For each simulated day:
-
Update LP Position
- Adjust pool balances based on ETH price movements (
simulateUniswapLP).
- Adjust pool balances based on ETH price movements (
-
Calculate PnL
- Compute futures profit and loss.
- Include funding rate costs.
-
Fee Calculation
- Account for liquidity provider fees.
- Deduct Binance trading fees.
- Deduct Ethereum gas costs.
-
Hedge Rebalancing
- If ETH exposure deviates by more than the set threshold (5%), rebalance the short position.
-
Record Metrics
- Track daily portfolio metrics.
- Compute and output initial investment, final portfolio value, and net return (
main.nim).
Start
│
├─ Load Synthetic or Real Market Data (generate_data.nim)
│
├─ Initialize LP Position in Uniswap V2 ETH/USDC Pool
├─ Establish Initial Hedge via Short ETH Perpetuals (Binance)
│
├─ For each day in Backtest Period:
│ ├─ Update LP Position based on ETH price movements (simulateUniswapLP)
│ ├─ Calculate futures PnL & funding rate costs
│ ├─ Calculate Fees (LP, Binance, Gas)
│ ├─ Check Hedge Rebalance Threshold (5%)
│ │ ├─ If exceeded → Adjust Short Position & record gas/trade fees
│ └─ Update Daily Portfolio Metrics
│
├─ Calculate Final Performance Metrics (initial, final value, net returns)
│
└─ Output results (main.nim)
End
generate_data.nim: Synthetic data generationbacktest.nim: Core simulation and hedging logicutils.nim: Helper functions for simulationsmain.nim: Orchestrates data loading, backtest execution, and results presentation
- Integration of live data feeds (Uniswap API, Binance API)
- Advanced rebalancing strategies (volatility-based triggers, ML models)
- Multi-chain support (e.g., SushiSwap, Uniswap V3)
- Gas cost optimization (batch transactions, Layer 2 solutions)