Cover photo

Selecting Optimal Parameters for Launching Markets on LlamaLend

Want to create your own lending market on LlamaLend but don’t know where to start? Begin by choosing the right parameters — do your research and determine the optimal settings for your market


Table of Contents

  1. Introduction

  2. Installing and Setting Up the Simulator

  3. Pre‑Simulation Configuration

    • Explanation of Script Variables

  4. Running Simulations & Choosing Market Parameters

    1. Finding the Optimal Amplification Parameter (A)

    2. Finding the Optimal Fee

    3. Calculating liquidation_discount and loan_discount

    4. Summary of Parameters Needed to Deploy a Market

  5. Telegram Bot

  6. General Tips for Parameter Selection

    • Choosing Parameters by Asset Volatility

    • Balancing Yield and Safety

    • Back‑testing on Historical Data

  7. Conclusion


Introduction

Proper parameter selection is the foundation of a successful and secure lending market on Curve Finance’s lending platform. The process requires thorough analysis of historical data and modeling of various market scenarios.

LlamaLend markets operate permissionlessly—any user can create them without special permissions. However, this task demands expertise and responsibility, so the market-creation functionality is not integrated into Curve’s standard user interface. Instead, new markets must be deployed using a dedicated factory contract. (A guide to market deployment will be released soon.)

Before launching a new market, you must conduct a comprehensive study of the collateral asset’s behavior under different market conditions. The ideal candidate is an asset with a long trading history that has experienced various market phases—bull and bear trends as well as periods of high volatility.

To facilitate simulations and back-testing, the Curve Finance team has developed a specialized tool—the LLAMMA Simulator (Lending-Liquidating AMM Algorithm). It enables you to:

  • Analyze historical price data

  • Model market behavior under a range of parameter settings

  • Assess potential risks and returns

  • Optimize key market parameters (fees, the A-parameter, number of price bands)

The simulator provides a reliable, data-driven foundation for making informed decisions when configuring a new market, thereby reducing risk for both lenders and borrowers.


Installing and Setting Up the Simulator

To work with the simulator, you’ll need a minimal environment: Python with the NumPy and Matplotlib libraries. All source code and examples are hosted in the official GitHub repository: https://github.com/curvefi/llamma-simulator

If you’re already feeling daunted, don’t go just yet—scroll down to learn about our Telegram bot, which offers the same functionality without running any local Python scripts. That said, if you plan to deploy a market on LlamaLend, we strongly recommend familiarizing yourself with the full toolset.

1. Create and Activate a Virtual Environment

python -m venv .venv
source .venv/bin/activate

2. Install Required Packages

pip install --upgrade pip
pip install numpy matplotlib requests

3. Fetch Historical Price Data

The simulator requires historical price feeds. You can download these using the scripts in the data/ directory (named fetch-*.py). For example, to fetch CRV/USDT data:

cd data
python3 fetch-crvusd.py
mv crvusdt.json crvusdt-1m.json     # Rename to include the timeframe
gzip crvusdt-1m.json                # Compress to save disk space

Note: The simulator reads compressed `.gz` files for faster I/O and reduced disk-space usage.


Pre-Simulation Configuration

To select market parameters, we need to run two main simulations: 2_simulate_A.py and 1_simulate_fee.py. Despite the numbering, always run 2_simulate_A.py first to determine A.

Before running the simulations, configure each script for your collateral asset. You can copy a ready-made example from the GitHub repo (https://github.com/curvefi/llamma-simulator) or set the variables manually.


Key Variables in the Scripts

# In 2_simulate_A.py
A = [int(a) for a in logspace(log10(10), log10(300), 50)]
  • Purpose: Range of A-parameter values to scan.

  • Meaning: 10 = minimum A, 300 = maximum A, 50 = number of sample points for the final plot.

  • Recommendation: Use lower A for volatile tokens; higher A for pegged assets (e.g. stablecoins). Example presets are available in the repo.

# In 1_simulate_fee.py
A = 30
  • Purpose: Fixed A value (from your A-scan) for fee scanning.

# In both scripts
range_size = 4
  • Purpose: Number of price “bands” in the simulation.

  • Recommendation: A minimal range_size = 4 tests the worst-case scenario.

# In 2_simulate_A.py
fee = 0.002
  • Purpose: Fixed fee while scanning A.

  • Recommendation: Use fee = 0.002 (0.2 %) on your first A scan; once you’ve selected A, scan fee in the next step.

# In 1_simulate_fee.py
fee = logspace(log10(0.0001), log10(0.02), 20)
  • Purpose: Range of fee values to scan.

  • Meaning: 0.0001 = 0.01 % (minimum), 0.02 = 2 % (maximum), 20 = sample points.

  • Recommendation: Use higher fees for volatile tokens, lower fees for tightly-pegged assets. Refer to examples for presets.

# Loan duration, in days
min_loan_duration = 1/24/2, max_loan_duration = 1/24/2
  • Purpose: Defines the loan time window in days.

  • Recommendation: For most real-world scenarios, choose a short duration—roughly the maximum time liquidators need to close a position.

  • Example: 1/24/2 = 1/48 day = 30 minutes.

min_loan_duration = 0.5, max_loan_duration = 0.5
  • Alternative format: You can also specify durations directly in decimal days (e.g. 0.5 days).

You may scan a range of durations, but using a single fixed duration (min = max) is also valid.

Tip: In thinner markets or where arbitrage is slow, choose a longer duration; in deep, active markets, shorter durations are sufficient.

samples = 500_000, n_top_samples = 5
  • samples: Number of Monte Carlo runs—i.e., how many random scenarios (positions with varied start times and durations) will be generated and simulated.

    • More runs → more precise and stable loss estimates, but longer compute time (500 000 runs can take hours on a typical machine).

  • n_top_samples: After all runs, select the N worst (highest-loss) scenarios—here, the top 5—and average their losses.

    • This measures tail risk, showing how badly things could go in extreme situations.

Recommendations:

  1. When researching the optimal A, use at least 500 000 samples for a thorough analysis.

  2. When researching the optimal fee, you can reduce the total runs (e.g., samples = 10_000) but increase the number of worst cases considered (e.g., n_top_samples = 1_000).

# Whether to append the time-reversed price series
add_reverse = True
  • Purpose: Appends the real price series in reverse chronological order, doubling your dataset and offsetting any trend bias. This lets you test symmetrical scenarios of price rises and falls.

  • Tip: If volatility is primarily one-sided, you can set add_reverse = False.

# Exponential-moving-average (EMA) window, in seconds
Texp = 600
  • Purpose: EMA smoothing window length, in seconds.

  • Note: Must match your oracle’s EMA parameter. The default for all NG-pool oracles is 600; override this value if your oracle uses a different setting.


Simulation & Parameter Selection

When creating a market on LlamaLend, you must determine several key parameters that affect its efficiency and safety. Let’s examine each in detail.

1. Optimal Amplification Parameter (A)

Begin by finding the optimal amplification parameter, A. The amplification parameter controls how aggressively the pool rebalances and is critically dependent on the asset’s volatility: higher volatility calls for a more conservative (lower) A.

To determine the optimal A, run:

python3 2_simulate_A.py 

This script produces two plots for your specified number of price bands:

  • Loss curve (orange)

  • Discount curve (blue)

post image

The optimal A is at the minimum point of the orange (loss) curve. In this example, that value is approximately 30.

2. Optimal Fee

The fee in LLAMMA affects both the market’s yield and its stability. For most assets (excluding EUR), the ideal fee range is 0.2%–0.9% (i.e., fee = 0.002–0.009 in code). You should determine the exact optimal fee through simulation, as shown below.

To find the optimal fee, run:

python3 1_simulate_fee.py 

This script computes the loss as a function of fee for a position with your chosen number of price bands and the previously determined amplification parameter A.

The resulting plot displays loss versus fee. The optimal fee is at the minimum point of that curve.

post image

For example, in this case the optimal fee is approximately 0.3% (set in code as 0.003).

Table of Contents

  1. Introduction

  2. Installing and Setting Up the Simulator

  3. Pre‑Simulation Configuration

    • Explanation of Script Variables

  4. Running Simulations & Choosing Market Parameters

    1. Finding the Optimal Amplification Parameter (A)

    2. Finding the Optimal Fee

    3. Calculating liquidation_discount and loan_discount

    4. Summary of Parameters Needed to Deploy a Market

  5. Telegram Bot

  6. General Tips for Parameter Selection

    • Choosing Parameters by Asset Volatility

    • Balancing Yield and Safety

    • Back‑testing on Historical Data

  7. Conclusion


Introduction

Proper parameter selection is the foundation of a successful and secure lending market on Curve Finance’s lending platform. The process requires thorough analysis of historical data and modeling of various market scenarios.

LlamaLend markets operate permissionlessly—any user can create them without special permissions. However, this task demands expertise and responsibility, so the market-creation functionality is not integrated into Curve’s standard user interface. Instead, new markets must be deployed using a dedicated factory contract. (A guide to market deployment will be released soon.)

Before launching a new market, you must conduct a comprehensive study of the collateral asset’s behavior under different market conditions. The ideal candidate is an asset with a long trading history that has experienced various market phases—bull and bear trends as well as periods of high volatility.

To facilitate simulations and back-testing, the Curve Finance team has developed a specialized tool—the LLAMMA Simulator (Lending-Liquidating AMM Algorithm). It enables you to:

  • Analyze historical price data

  • Model market behavior under a range of parameter settings

  • Assess potential risks and returns

  • Optimize key market parameters (fees, the A-parameter, number of price bands)

The simulator provides a reliable, data-driven foundation for making informed decisions when configuring a new market, thereby reducing risk for both lenders and borrowers.


Installing and Setting Up the Simulator

To work with the simulator, you’ll need a minimal environment: Python with the NumPy and Matplotlib libraries. All source code and examples are hosted in the official GitHub repository: https://github.com/curvefi/llamma-simulator

If you’re already feeling daunted, don’t go just yet—scroll down to learn about our Telegram bot, which offers the same functionality without running any local Python scripts. That said, if you plan to deploy a market on LlamaLend, we strongly recommend familiarizing yourself with the full toolset.

1. Create and Activate a Virtual Environment

python -m venv .venv
source .venv/bin/activate

2. Install Required Packages

pip install --upgrade pip
pip install numpy matplotlib requests

3. Fetch Historical Price Data

The simulator requires historical price feeds. You can download these using the scripts in the data/ directory (named fetch-*.py). For example, to fetch CRV/USDT data:

cd data
python3 fetch-crvusd.py
mv crvusdt.json crvusdt-1m.json     # Rename to include the timeframe
gzip crvusdt-1m.json                # Compress to save disk space

Note: The simulator reads compressed `.gz` files for faster I/O and reduced disk-space usage.


Pre-Simulation Configuration

To select market parameters, we need to run two main simulations: 2_simulate_A.py and 1_simulate_fee.py. Despite the numbering, always run 2_simulate_A.py first to determine A.

Before running the simulations, configure each script for your collateral asset. You can copy a ready-made example from the GitHub repo (https://github.com/curvefi/llamma-simulator) or set the variables manually.


Key Variables in the Scripts

# In 2_simulate_A.py
A = [int(a) for a in logspace(log10(10), log10(300), 50)]
  • Purpose: Range of A-parameter values to scan.

  • Meaning: 10 = minimum A, 300 = maximum A, 50 = number of sample points for the final plot.

  • Recommendation: Use lower A for volatile tokens; higher A for pegged assets (e.g. stablecoins). Example presets are available in the repo.

# In 1_simulate_fee.py
A = 30
  • Purpose: Fixed A value (from your A-scan) for fee scanning.

# In both scripts
range_size = 4
  • Purpose: Number of price “bands” in the simulation.

  • Recommendation: A minimal range_size = 4 tests the worst-case scenario.

# In 2_simulate_A.py
fee = 0.002
  • Purpose: Fixed fee while scanning A.

  • Recommendation: Use fee = 0.002 (0.2 %) on your first A scan; once you’ve selected A, scan fee in the next step.

# In 1_simulate_fee.py
fee = logspace(log10(0.0001), log10(0.02), 20)
  • Purpose: Range of fee values to scan.

  • Meaning: 0.0001 = 0.01 % (minimum), 0.02 = 2 % (maximum), 20 = sample points.

  • Recommendation: Use higher fees for volatile tokens, lower fees for tightly-pegged assets. Refer to examples for presets.

# Loan duration, in days
min_loan_duration = 1/24/2, max_loan_duration = 1/24/2
  • Purpose: Defines the loan time window in days.

  • Recommendation: For most real-world scenarios, choose a short duration—roughly the maximum time liquidators need to close a position.

  • Example: 1/24/2 = 1/48 day = 30 minutes.

min_loan_duration = 0.5, max_loan_duration = 0.5
  • Alternative format: You can also specify durations directly in decimal days (e.g. 0.5 days).

You may scan a range of durations, but using a single fixed duration (min = max) is also valid.

Tip: In thinner markets or where arbitrage is slow, choose a longer duration; in deep, active markets, shorter durations are sufficient.

samples = 500_000, n_top_samples = 5
  • samples: Number of Monte Carlo runs—i.e., how many random scenarios (positions with varied start times and durations) will be generated and simulated.

    • More runs → more precise and stable loss estimates, but longer compute time (500 000 runs can take hours on a typical machine).

  • n_top_samples: After all runs, select the N worst (highest-loss) scenarios—here, the top 5—and average their losses.

    • This measures tail risk, showing how badly things could go in extreme situations.

Recommendations:

  1. When researching the optimal A, use at least 500 000 samples for a thorough analysis.

  2. When researching the optimal fee, you can reduce the total runs (e.g., samples = 10_000) but increase the number of worst cases considered (e.g., n_top_samples = 1_000).

# Whether to append the time-reversed price series
add_reverse = True
  • Purpose: Appends the real price series in reverse chronological order, doubling your dataset and offsetting any trend bias. This lets you test symmetrical scenarios of price rises and falls.

  • Tip: If volatility is primarily one-sided, you can set add_reverse = False.

# Exponential-moving-average (EMA) window, in seconds
Texp = 600
  • Purpose: EMA smoothing window length, in seconds.

  • Note: Must match your oracle’s EMA parameter. The default for all NG-pool oracles is 600; override this value if your oracle uses a different setting.


Simulation & Parameter Selection

When creating a market on LlamaLend, you must determine several key parameters that affect its efficiency and safety. Let’s examine each in detail.

1. Optimal Amplification Parameter (A)

Begin by finding the optimal amplification parameter, A. The amplification parameter controls how aggressively the pool rebalances and is critically dependent on the asset’s volatility: higher volatility calls for a more conservative (lower) A.

To determine the optimal A, run:

python3 2_simulate_A.py 

This script produces two plots for your specified number of price bands:

  • Loss curve (orange)

  • Discount curve (blue)

post image

The optimal A is at the minimum point of the orange (loss) curve. In this example, that value is approximately 30.

2. Optimal Fee

The fee in LLAMMA affects both the market’s yield and its stability. For most assets (excluding EUR), the ideal fee range is 0.2%–0.9% (i.e., fee = 0.002–0.009 in code). You should determine the exact optimal fee through simulation, as shown below.

To find the optimal fee, run:

python3 1_simulate_fee.py 

This script computes the loss as a function of fee for a position with your chosen number of price bands and the previously determined amplification parameter A.

The resulting plot displays loss versus fee. The optimal fee is at the minimum point of that curve.

post image

For example, in this case the optimal fee is approximately 0.3% (set in code as 0.003).

3. Calculating liquidation_discount and loan_discount

Calculation of liquidation_discount
Take the value of the blue (discount) curve directly under the minimum point of the orange (loss) curve—here it’s approximately 0.07. This represents the potential loss in the worst-case scenario (over the given time period) for N = 4 bands—i.e., how much the position could lose if volatility spikes.

liquidation_discount = 0.07   # 7%

Calculation of loan_discount
To prevent users from being instantly liquidated under such a scenario, the standard practice on LlamaLend is to add 3% to the liquidation_discount:

loan_discount = 0.07 + 0.03 = 0.10   # 10%

4. Final Summary of Parameters for Market Deployment

A              				        = 10
fee               				    = 0.003
liquidation_discount  		= 0.07
loan_discount   			    = 0.10

Note: When you deploy the market, all values except A must be converted to Wei (×10¹⁸).


Telegram Bot

post image

llamma-simulator-bot: https://t.me/llamma_simulator_bot

If you’d rather not run the Python scripts yourself, you can use the Telegram bot, which provides all of the LLAMMA simulator’s features without any local setup.

Note: The bot is in early testing and may contain bugs or inaccuracies.

Use the bot’s menu to interact with the simulator:

post image
  • Fetch prices
    Download historical price data for a selected token. Data can be pulled from Curve or Binance.

    post image
  • Archives
    Browse and select from previously downloaded price archives for simulation.

    post image
  • Chart
    Plot the price history of your chosen archive to verify that the data was collected correctly.

    post image
  • Parameters
    Configure the simulation variables (A-parameter range, fee range, loan durations, etc.).

    post image
  • Scan Fee and Scan A
    Initiate the fee-scan and A-scan simulations, respectively.

post image
post image

General Recommendations for Parameter Selection

When creating a new market on LlamaLend, keep the following guidelines in mind:

Choosing Parameters Based on Asset Volatility

The principles for setting up a LlamaLend market mirror those used in leveraged trading strategies—except you’re configuring the parameters for the entire market rather than a single position. For highly volatile assets, it’s advisable to:

  • Select a more conservative amplification parameter (A)

  • Set a higher loan_discount

  • Cap the maximum LTV to reduce liquidation risk

Balancing Yield and Safety

Optimizing your parameters requires a balance between potential capital efficiency for users and overall market safety. Settings that are too conservative can make the market uncompetitive (poor LTV), while overly aggressive settings risk mass liquidations during sharp price moves.

Back-testing on Historical Data

Before deployment, test your parameter choices against historical data—especially periods of high volatility:

  1. Download historical price data for your target asset.

  2. Run simulations with various parameter sets.

  3. Analyze the output to identify the optimal configuration.

  4. Stress-test that configuration under extreme scenarios (rapid price surges and crashes).


Conclusion

The llamma-simulator offers a scientific framework for parameter optimization, but it also requires expert understanding of the market and the specifics of each asset.

Building an efficient and secure lending market demands careful analysis and tuning of all key parameters. Properly configured settings protect against unexpected liquidations and maximize capital efficiency for both borrowers and lenders.

By applying the approaches and tools outlined in this article, you can launch markets on Curve Finance’s LlamaLend that are both attractive to users and resilient to market volatility.