Skip to content

About

Proof and backtest code for optimal leverage sequencing in leveraged DCA strategies. Companion code for the paper: "Optimal Leverage Sequencing in Leveraged Dollar Cost Averaging: Theory and Multi-Asset Evidence"

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Optimal Leverage Sequencing in Leveraged Dollar Cost Averaging

Theory and Multi-Asset Evidence

Proof and backtest code accompanying the research paper submitted to Applied Mathematical Finance (Taylor & Francis)


What This Paper Proves

Among all leverage sequences with the same total leverage applied to a Dollar Cost Averaging (DCA) entry schedule, the non-decreasing (increasing) sequence is the unique optimal allocation — it minimises the weighted average entry price and maximises the reference-to-entry span.

Example: For sequences with average leverage 6×:

Strategy Sequence Avg Entry Span B P/L @ 75% Recovery
Increasing (2, 4, 6, 8, 10) 86.7 13.3% +9.57%
Uniform (6, 6, 6, 6, 6) 90.0 10.0% +5.56%
Decreasing (10, 8, 6, 4, 2) 93.3 6.7% +1.82%

The proof uses the Rearrangement Inequality (Hardy, Littlewood & Pólya, 1952) and is parameter-independent.


Empirical Validation

Backtest on 9.5 million one-minute bars across 5 markets (2021–2026):

Market Increasing Sharpe Uniform Sharpe Decreasing Sharpe Inc. Liquidations
XAUUSD (Gold) 0.66 0.40 -0.00 3
BTCUSDT -0.09 -2.41 -0.79 62
ETHUSDT -0.73 -4.69 -0.94 135
SPY (S&P 500) 1.60 1.52 0.59 2
QQQ (NASDAQ 100) 3.36 2.92 0.90 0

The increasing sequence ranks first in Sharpe ratio and fewest liquidations in every market. Approximate replication p-value: (1/3)⁵ ≈ 0.004.


Repository Structure

├── dca_backtest.py          # Primary XAUUSD backtest engine
├── dca_multi_asset.py       # Multi-asset backtest (BTC, ETH, SPY, QQQ)
├── DCA_AMF_manuscript.tex   # LaTeX source of the research paper
├── references.bib           # BibTeX references
└── README.md

How to Run

Requirements

pip install pandas numpy matplotlib pyarrow

Primary Backtest (XAUUSD)

python dca_backtest.py
  • Reads XAUUSD_1m.csv (1-minute candlestick data)
  • Outputs equity curves, annual P/L, P/L distributions as PNG
  • Prints full performance table for all three leverage strategies

Multi-Asset Backtest

python dca_multi_asset.py
  • Reads XAUUSD, BTCUSDT, ETHUSDT CSVs and SPY/QQQ parquet files
  • Outputs per-asset equity curves and cross-asset comparison charts

Data Format

Asset Format Required Columns
XAUUSD CSV datetime, open, high, low, close
BTCUSDT / ETHUSDT CSV Date, Open, High, Low, Close
SPY / QQQ Parquet (directory) timestamp, open, high, low, close

Strategy Parameters

Parameter Value Description
f 3% Initial entry drawdown from rolling high
M 15% Maximum drawdown threshold (final entry)
n 4 Number of DCA intervals (5 total entries)
W 7,200 bars Lookback window for rolling reference high (≈5 days)
Cooldown 480 bars Minimum gap between new DCA sequences (8 hours)
Capital $100/step Margin per DCA entry ($500 total per trade)
Max hold 20,160 bars Maximum position hold time (14 days)

Leverage Sequences Compared

INCREASING = [2, 4, 6, 8, 10]   # Optimal — proven by Proposition 1
UNIFORM    = [6, 6, 6, 6, 6]    # Baseline
DECREASING = [10, 8, 6, 4, 2]   # Worst

All sequences sum to 30 (average 6×) — comparisons reflect only the distribution of leverage, not the total amount.


Key Result

Assign lower leverage to earlier (higher-priced) DCA entries and higher leverage to later (lower-priced) entries.

This is not a heuristic — it is the provably optimal allocation.


Paper

Ayush Pandey (2026). Optimal Leverage Sequencing in Leveraged Dollar Cost Averaging: Theory and Multi-Asset Evidence. Submitted to Applied Mathematical Finance, Taylor & Francis.

Contact: ayushpandey85986@gmail.com


Disclaimer

This repository is provided for academic research purposes only. Nothing in this repository constitutes financial advice. Leveraged derivatives trading carries significant risk of loss, including total loss of deposited margin. Past backtest performance does not guarantee future results.

About

Proof and backtest code for optimal leverage sequencing in leveraged DCA strategies. Companion code for the paper: "Optimal Leverage Sequencing in Leveraged Dollar Cost Averaging: Theory and Multi-Asset Evidence"

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages