DOI: 10.5281/zenodo.18347843
title: Supplementary Material for Analysis of CEX-DEX Arbitrage Opportunities with Hidden Markov Models

description: Analysis of CEX-DEX Arbitrage Opportunities with Hidden Markov Models

This repository provides a collection of Python and C tools to analyse Automated Market Maker (AMM) swap data, estimate Geometric Brownian Motion (GBM) parameters, and simulate market behaviour. It reproduces the main results and figures presented in "Analysis of CEX-DEX Arbitrage Opportunities with Hidden Markov Models".

DATASET

Download the dataset from this repository.

Copy all CSV files into the same directory where the Python scripts are located.

REQUIREMENTS

Install the required Python packages:

pip install pandas numpy

For figure generation, R must also be installed (used in generate_figure3.sh).

USAGE



Calculate GBM parameters


Drift and volatility for each trading pair (Table 1):

python3 calculate_mu_and_sigma.py



Calculate price jumps (Table 2)


python3 calculate_jumps.py



Analyse AMM swaps (Table 3)


python3 analyse_swaps.py ETHUSDC 0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852



Plot AMM swaps for a specific date range (Figure 2)


python3 generate_swap_figure.py ETHUSDC 0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852 2025-09-22 2025-09-25 2025-09-26 2025-10-02



Generate Figure 3


Requires R:

bash generate_figure3.sh



Get swap sizes per day


python3 get_swap_sizes_per_day.py ETHUSDC 0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852



Analyse relay bids


python3 get_relay_bids.py



Generate Table IV


python3 generate_table4.py --price-source crypto_prices ETHUSDC 0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852



Generate the Appendix


bash generate_appendix.sh

MONTE CARLO SIMULATION

Compile the simple GBM simulator:

gcc -DLOGLEVEL=3 -o simple_gbm_simulator simple_gbm_simulator.c -lgsl -lgslcblas -lm -fopenmp

Run the simulation:

bash gbm_monte_carlo.sh

Compile the full Monte Carlo simulator:

gcc -DLOGLEVEL=1 -o sim sim.c -lgsl -lgslcblas -lm -fopenmp

Generate results for Table VI:

python3 parametrisable_optimiser.py --target-trades 258,231,148,203,342,321,188,385,363,286 --target-profit 944.5,232.7,225.3,166.6,22311.1,1020.8,827.7,3756.5,3172.4,601 --date 2025-09-18,2025-09-19,2025-09-20,2025-09-21,2025-09-22,2025-09-23,2025-09-24,2025-09-25,2025-09-26,2025-09-27 --gbm-drift 0.0145,-0.0272,0.0042,-0.0042,-0.0629,-0.0038,-0.0090,-0.0599,0.0301,-0.0023 --gbm-sigma 0.0181,0.0177,0.0095,0.0098,0.0361,0.0161,0.0204,0.0401,0.0312,0.0142 --drift-factor 2.00,5.00,1.50,3.00,11.00,12.00,3.00,2.00,6.00,2.70 --sigma-factor 0.50,2.50,0.50,0.50,0.50,0.70,0.50,1.00,1.00,0.50 --runs 20 --grid 7 --output results_optimised.json --range-pct 0.8 --n-runs 20

OUTPUTS

Script: calculate_mu_and_sigma.py Output: Drift and volatility estimates Table/Figure: Table 1

Script: calculate_jumps.py Output: Jump statistics Table/Figure: Table 2

Script: analyse_swaps.py Output: AMM swap analysis Table/Figure: Table 3

Script: generate_swap_figure.py Output: Swap visualisation Table/Figure: Figure 2

Script: generate_figure3.sh Output: Additional analysis Table/Figure: Figure 3

Script: generate_table4.py Output: Relay bid results Table/Figure: Table IV

Script: parametrisable_optimiser.py Output: Optimised GBM simulation results Table/Figure: Table VI

NOTES

Ensure all Python scripts are executed from the directory containing the CSV data files.

The Monte Carlo simulators require GSL and OpenMP.

All results correspond to the specific ETH–USDC pair used in the examples.

CONTACT

For questions or collaboration inquiries, please contact the author.