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.
Files
crypto_prices.csv
Files
(6.8 GB)
| Name | Size | |
|---|---|---|
|
md5:ef2ba3476b6818f828f7112805ff4834
|
12.7 kB | Download |
|
md5:e1c8c2fa09d33dc8669422bfbb0add54
|
4.0 kB | Download |
|
md5:4e52f4c2757a379647e9bdeb6601f75c
|
5.2 kB | Download |
|
md5:e73b047258e9374027ce48b645998e59
|
560.5 MB | Preview Download |
|
md5:794bb6846ed6f97970b4eb37e223f5da
|
3.1 MB | Preview Download |
|
md5:ce17bddc958ba75503caa9cf14934644
|
156.9 MB | Preview Download |
|
md5:f436ffce56f4ae4cc27e97a36b868a83
|
2.8 kB | Download |
|
md5:b7d1fc0ead59f5eaa20760ad30e99459
|
539 Bytes | Download |
|
md5:63754dadbcf6233b6e4aa29c1cea3f14
|
623 Bytes | Download |
|
md5:0b7d51d71494e7e89a5251f96e63c393
|
7.9 kB | Download |
|
md5:86a788df38efcb482ca5a967b89829e1
|
8.4 kB | Download |
|
md5:431fa28e98bd34a4d7f6a342cc781f01
|
1.2 kB | Download |
|
md5:14a56cd55ce02e6c063a9aabe421528c
|
6.6 kB | Download |
|
md5:51792576f8f799053eac02f58d38989e
|
51.7 MB | Preview Download |
|
md5:742f9471d14f0b8b24469c8b159d7327
|
1.3 kB | Download |
|
md5:f8e090b42323bfe8cd16becb2e5cc7bc
|
3.0 GB | Preview Download |
|
md5:eabc65cd0ca2c5bda7d8dbb3afb2c78c
|
11.7 kB | Download |
|
md5:9f4c82e5251d431ade2e2a7110e16efd
|
4.0 kB | Download |
|
md5:863af88dab3029d6bac6f0a28375afc9
|
228 Bytes | Download |
|
md5:1e114806855e44ac16bb04e2a45a4e5d
|
4.0 kB | Preview Download |
|
md5:b463a2b61283fd7fde88e96d1d1a44f6
|
2.1 GB | Preview Download |
|
md5:1f145ee1fff7c5f14b80973fb3b2512a
|
35.4 kB | Download |
|
md5:efe8399d49e44744a3db442afa2b5193
|
21.8 kB | Download |
|
md5:cb8f5ae4b62c9d89d55765e1eeaf8d39
|
947.0 MB | Preview Download |
|
md5:66b1b7761fbda16fe8309c8b553b1348
|
670 Bytes | Download |
|
md5:3202603c5c11ee8afa9d73cc2781dfa9
|
8.9 kB | Download |
Additional details
Related works
- Is supplemented by
- Conference paper: 10.1145/3774904.3792185 (DOI)
Software
- Repository URL
- https://github.com/mlvl36667/cexdexarbitrageanalysis/tree/main
- Programming language
- Python
- Development Status
- Active