Getting Started
This tutorial will walk you through your first AMM simulation using quantammsim.
Your First Simulation
Let’s create a simple balancer-style AMM pool and run a simulation:
from quantammsim.runners.jax_runners import do_run_on_historic_data
import jax.numpy as jnp
# Set up a basic simulation
run_fingerprint = {
'tokens': ['BTC', 'USDC'],
'rule': 'balancer',
'initial_pool_value': 1000000.0
}
params = {
"initial_weights": jnp.array([0.5, 0.5]),
}
# Run simulation
result = do_run_on_historic_data(run_fingerprint, params, verbose=True)
Anything not set in the run_fingerprint will take on a default value
Understanding the Results
Let’s examine what the simulation tells us:
# Access key metrics
print(f"Final pool value: {result['final_value']}")
Now that you’ve run your first simulation, you might want to:
Learn about the principles of dynamic pools (see Temporal Function Market Makers: Introduction to Dynamic AMMs)
Read about how QuantAMM pools work (see QuantAMM: Pools as Portfolios)
Explore Balancer, CowAMM, and Gyroscope pools (see Balancer Pools, CoW Pools, Gyroscope Pools)
Learn about deeper mechanics and implementation of the pools (see Pools)
Basic Usage
Let’s walk through a simple example of simulating a BTC/USDC balancer-style AMM pool:
from quantammsim.runners.jax_runners import do_run_on_historic_data
import jax.numpy as jnp
# Define the basic parameters for our simulation
run_fingerprint = {
'tokens': ['BTC', 'USDC'], # Token pair to simulate
'rule': 'balancer', # Weight update strategy
'initial_pool_value': 1000000.0, # Starting liquidity in USD
'fees': 0.001, # Charge fees of 10bps on swaps
'startDateString': '2023-06-01 00:00:00',
'endDateString': '2023-12-31 23:59:59'
}
params = {
"initial_weights": jnp.array([0.5, 0.5]),
}
# Run simulation
result = do_run_on_historic_data(run_fingerprint, params, verbose=True)
# The result dictionary contains various metrics and time series including:
# - Token prices
# - Pool value over time
Advanced Configuration
The run_fingerprint supports many additional parameters for fine-tuning the simulation:
run_fingerprint = {
# ... basic parameters ...
'fees': 0.003, # Trading fees (30 bps)
'maximum_change': 0.0003 # Max weight change per update
}
Next Steps
To learn more about:
Different pool types and strategies, see Core Concepts
Detailed parameter configuration, see Run Fingerprints
Dive into the math and implementation details, see Pools