Skip to content

BTC Historical Simulations#245

Open
RZhang05 wants to merge 2 commits intomainfrom
raymond/time-series-sim-3
Open

BTC Historical Simulations#245
RZhang05 wants to merge 2 commits intomainfrom
raymond/time-series-sim-3

Conversation

@RZhang05
Copy link
Copy Markdown
Contributor

@RZhang05 RZhang05 commented Apr 2, 2026

Closes: #221

Description

Verifies 0 liquidations under historical daily BTC data from 2021-2025 (2022 only survives under certain HFs, see this comment). All simulations use 1.3/1.5/1.3/1.1 (initial/max/target/min) default health factors.

Supports manual liquidation of positions, bringing HFs back to 1.04.

Note: uses default strategy health factors instead of the ones specified in the python simulations.

Test Outputs

2021
5:05PM INF LOG: "\n=== SIMULATION RESULTS ==="
5:05PM INF LOG: "Agents:              1"
5:05PM INF LOG: "Days simulated:      365"
5:05PM INF LOG: "Rebalance attempts:  365"
5:05PM INF LOG: "Vault rebalances:    0"
5:05PM INF LOG: "Position rebalances: 23"
5:05PM INF LOG: "Liquidation count:   0"
5:05PM INF LOG: ""
5:05PM INF LOG: "--- Price ---"
5:05PM INF LOG: "Initial BTC price:   $29374.15000000"
5:05PM INF LOG: "Lowest BTC price:    $29374.15000000"
5:05PM INF LOG: "Highest BTC price:   $67566.83000000"
5:05PM INF LOG: "Final BTC price:     $46306.45000000"
5:05PM INF LOG: "Price change:        +0.57643540"
5:05PM INF LOG: ""
5:05PM INF LOG: "--- Position (effective HF with collateralFactor=0.80000000) ---"
5:05PM INF LOG: "Lowest HF observed:  1.01783976"
5:05PM INF LOG: "Final HF (agent 0):  1.19670736"
5:05PM INF LOG: "Final collateral:    1.00000000 BTC ($46306.45000000)"
5:05PM INF LOG: "Final debt:          30955.90540801 MOET"
5:05PM INF LOG: "Final yield tokens:  32885.33010021 ($36164.85318749 @ yt=1.09972602)"
5:05PM INF LOG: ""
5:05PM INF LOG: "--- P&L ---"
5:05PM INF LOG: "Initial deposit:     1.00000000 BTC (~$29374.15000000)"
5:05PM INF LOG: "Net equity (USD):    $51515.39777948 (P&L: +$22141.24777948, +0.75376641)"
5:05PM INF LOG: "Net equity (BTC):    1.11248860 BTC (P&L: +0.11248860 BTC, +0.11248860)"
5:05PM INF LOG: "===========================\n"
5:05PM INF LOG: "=== TEST PASSED: 0 liquidations (expected 0) over 365 days of real BTC prices (1 agents) ==="
2022
3:29PM INF LOG: "\n=== SIMULATION RESULTS ==="
3:29PM INF LOG: "Agents:              1"
3:29PM INF LOG: "Days simulated:      365"
3:29PM INF LOG: "Rebalance attempts:  365"
3:29PM INF LOG: "Vault rebalances:    1"
3:29PM INF LOG: "Position rebalances: 10"
3:29PM INF LOG: "Liquidation count:   2"
3:29PM INF LOG: ""
3:29PM INF LOG: "--- Price ---"
3:29PM INF LOG: "Initial BTC price:   $47686.81000000"
3:29PM INF LOG: "Lowest BTC price:    $15787.28000000"
3:29PM INF LOG: "Highest BTC price:   $47686.81000000"
3:29PM INF LOG: "Final BTC price:     $16547.50000000"
3:29PM INF LOG: "Price change:        -0.65299628"
3:29PM INF LOG: ""
3:29PM INF LOG: "--- Position (effective HF with collateralFactor=0.80000000) ---"
3:29PM INF LOG: "Lowest HF observed:  0.95002070"
3:29PM INF LOG: "Final HF (agent 0):  1.22317799"
3:29PM INF LOG: "Final collateral:    0.66719795 BTC ($11040.45807762)"
3:29PM INF LOG: "Final debt:          7220.83500992 MOET"
3:29PM INF LOG: "Final yield tokens:  12030.56282213 ($13230.32297074 @ yt=1.09972602)"
3:29PM INF LOG: ""
3:29PM INF LOG: "--- P&L ---"
3:29PM INF LOG: "Initial deposit:     1.00000000 BTC (~$47686.81000000)"
3:29PM INF LOG: "Net equity (USD):    $17049.94603844 (P&L: -$30636.86396156, -0.64245991)"
3:29PM INF LOG: "Net equity (BTC):    1.03036386 BTC (P&L: +0.03036386 BTC, +0.03036386)"
3:29PM INF LOG: "===========================\n"
Test results: "cadence/tests/simulation_btc_daily_historical.cdc"
- FAIL: test_BTC_2022
                Execution failed:
                        error: assertion failed: not equal: expected: 0, actual: 2
                           --> cadence/tests/simulation_btc_daily_historical.cdc:625:4
2023
5:36PM INF LOG: "\n=== SIMULATION RESULTS ==="
5:36PM INF LOG: "Agents:              1"
5:36PM INF LOG: "Days simulated:      365"
5:36PM INF LOG: "Rebalance attempts:  365"
5:36PM INF LOG: "Vault rebalances:    1"
5:36PM INF LOG: "Position rebalances: 9"
5:36PM INF LOG: "Liquidation count:   0"
5:36PM INF LOG: ""
5:36PM INF LOG: "--- Price ---"
5:36PM INF LOG: "Initial BTC price:   $16625.08000000"
5:36PM INF LOG: "Lowest BTC price:    $16625.08000000"
5:36PM INF LOG: "Highest BTC price:   $44166.60000000"
5:36PM INF LOG: "Final BTC price:     $42265.19000000"
5:36PM INF LOG: "Price change:        +1.54225483"
5:36PM INF LOG: ""
5:36PM INF LOG: "--- Position (effective HF with collateralFactor=0.80000000) ---"
5:36PM INF LOG: "Lowest HF observed:  1.09873967"
5:36PM INF LOG: "Final HF (agent 0):  1.42017374"
5:36PM INF LOG: "Final collateral:    1.02448987 BTC ($43300.25900862)"
5:36PM INF LOG: "Final debt:          24391.52766643 MOET"
5:36PM INF LOG: "Final yield tokens:  23284.65657132 ($25606.74269824 @ yt=1.09972602)"
5:36PM INF LOG: ""
5:36PM INF LOG: "--- P&L ---"
5:36PM INF LOG: "Initial deposit:     1.00000000 BTC (~$16625.08000000)"
5:36PM INF LOG: "Net equity (USD):    $44515.47404043 (P&L: +$27890.39404043, +1.67760961)"
5:36PM INF LOG: "Net equity (BTC):    1.05324201 BTC (P&L: +0.05324201 BTC, +0.05324201)"
5:36PM INF LOG: "===========================\n"
5:36PM INF LOG: "=== TEST PASSED: 0 liquidations (expected 0) over 365 days of real BTC prices (1 agents) ==="
2024
6:09PM INF LOG: "\n=== SIMULATION RESULTS ==="
6:09PM INF LOG: "Agents:              1"
6:09PM INF LOG: "Days simulated:      366"
6:09PM INF LOG: "Rebalance attempts:  366"
6:09PM INF LOG: "Vault rebalances:    1"
6:09PM INF LOG: "Position rebalances: 11"
6:09PM INF LOG: "Liquidation count:   0"
6:09PM INF LOG: ""
6:09PM INF LOG: "--- Price ---"
6:09PM INF LOG: "Initial BTC price:   $44167.33000000"
6:09PM INF LOG: "Lowest BTC price:    $39507.37000000"
6:09PM INF LOG: "Highest BTC price:   $106140.60000000"
6:09PM INF LOG: "Final BTC price:     $93429.20000000"
6:09PM INF LOG: "Price change:        +1.11534634"
6:09PM INF LOG: ""
6:09PM INF LOG: "--- Position (effective HF with collateralFactor=0.80000000) ---"
6:09PM INF LOG: "Lowest HF observed:  1.09295140"
6:09PM INF LOG: "Final HF (agent 0):  1.28745604"
6:09PM INF LOG: "Final collateral:    1.02938540 BTC ($96174.65441368)"
6:09PM INF LOG: "Final debt:          59761.04858049 MOET"
6:09PM INF LOG: "Final yield tokens:  58522.99973129 ($64375.29970441 @ yt=1.10000000)"
6:09PM INF LOG: ""
6:09PM INF LOG: "--- P&L ---"
6:09PM INF LOG: "Initial deposit:     1.00000000 BTC (~$44167.33000000)"
6:09PM INF LOG: "Net equity (USD):    $100788.90553760 (P&L: +$56621.57553760, +1.28197868)"
6:09PM INF LOG: "Net equity (BTC):    1.07877307 BTC (P&L: +0.07877307 BTC, +0.07877307)"
6:09PM INF LOG: "===========================\n"
6:09PM INF LOG: "=== TEST PASSED: 0 liquidations (expected 0) over 366 days of real BTC prices (1 agents) ==="
2025
6:15PM INF LOG: "\n=== SIMULATION RESULTS ==="
6:15PM INF LOG: "Agents:              1"
6:15PM INF LOG: "Days simulated:      365"
6:15PM INF LOG: "Rebalance attempts:  365"
6:15PM INF LOG: "Vault rebalances:    2"
6:15PM INF LOG: "Position rebalances: 6"
6:15PM INF LOG: "Liquidation count:   0"
6:15PM INF LOG: ""
6:15PM INF LOG: "--- Price ---"
6:15PM INF LOG: "Initial BTC price:   $94419.76000000"
6:15PM INF LOG: "Lowest BTC price:    $76271.95000000"
6:15PM INF LOG: "Highest BTC price:   $124752.53000000"
6:15PM INF LOG: "Final BTC price:     $87508.83000000"
6:15PM INF LOG: "Price change:        -0.07319368"
6:15PM INF LOG: ""
6:15PM INF LOG: "--- Position (effective HF with collateralFactor=0.80000000) ---"
6:15PM INF LOG: "Lowest HF observed:  1.07072587"
6:15PM INF LOG: "Final HF (agent 0):  1.18353254"
6:15PM INF LOG: "Final collateral:    1.02547431 BTC ($89738.05706315)"
6:15PM INF LOG: "Final debt:          60657.77070591 MOET"
6:15PM INF LOG: "Final yield tokens:  57640.89076870 ($63389.18739431 @ yt=1.09972602)"
6:15PM INF LOG: ""
6:15PM INF LOG: "--- P&L ---"
6:15PM INF LOG: "Initial deposit:     1.00000000 BTC (~$94419.76000000)"
6:15PM INF LOG: "Net equity (USD):    $92469.47375155 (P&L: -$1950.28624845, -0.02065548)"
6:15PM INF LOG: "Net equity (BTC):    1.05668735 BTC (P&L: +0.05668735 BTC, +0.05668735)"
6:15PM INF LOG: "===========================\n"
6:15PM INF LOG: "=== TEST PASSED: 0 liquidations (expected 0) over 365 days of real BTC prices (1 agents) ==="

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@RZhang05 RZhang05 changed the title Raymond/time series sim 3 BTC Historical Simulations Apr 2, 2026
Base automatically changed from raymond/time-series-sim-2 to main April 3, 2026 21:14
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@RZhang05 RZhang05 force-pushed the raymond/time-series-sim-3 branch from f030eeb to 5ec01ca Compare April 8, 2026 19:48
@RZhang05 RZhang05 force-pushed the raymond/time-series-sim-3 branch from 5ec01ca to 1615635 Compare April 8, 2026 19:51
@RZhang05 RZhang05 marked this pull request as ready for review April 8, 2026 19:57
@RZhang05 RZhang05 requested a review from a team as a code owner April 8, 2026 19:57
directMintYT: true
)

access(all) let btc_daily_2022_bear_expectedLiquidationCount: Int = 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For bear market, it triggers no liquidation?

And why do we use a different HF range (1.1-1.3), instead of the standard (1.1-1.5)? But with 1.1-1.3, a 10% price drop should be enough to trigger liquidation. no?

access(all) let btc_daily_2022_bear_agents: [SimAgent] = [
    SimAgent(
        count: 1,
        initialHF: 1.20000000,
        maxHF: 1.30000000,
        minHF: 1.10000000,
        targetHF: 1.20000000,
        debtPerAgent: 133333.00000000,
        totalSystemDebt: 20000000.00000000
    )
]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we use a different HF range (1.1-1.3)

This is an example of surviving the 2022 market which requires a different HF then the standard. You can see the standard version suffers 2 liquidations.

Triggering liquidation is dependent on the HF on the day, it just happens that with this config we are usually at target (1.2) for most major price drops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BTC 2021-2024 Historical Simulations

2 participants