Backtest and optimization to built a DCA Strategy

A statistical example of how in-sample optimization and martingale dynamics guarantee eventual ruin.

The contest is of a mean reverting greedy strategy, that use leverage and trade long and short.
The original goal was to find parameter configurations that would make liquidation effectively impossible. In practice, this means pushing the failure mode outside the observed sample.

This article is not about how to make 10% per month.

It is about why a strategy that did make 10% per month still ended in liquidation.

I originally developed this system for TradingView and FreqTrade.

Here, however, the focus is not on execution, but on the backtesting and optimization process used to push a martingale-style strategy as far as possible before it inevitably fails.

Strategy


The strategy is a leveraged mean-reversion system that trades both long and short using Bollinger Bands as entry triggers.

When price crosses a band, a base order is opened.

If price continues to move against the position, additional safety orders are placed at increasing distances and sizes, progressively shifting the average entry price.

A fixed take-profit closes the entire position when mean reversion occurs.

A very important aspect of the strategy is the search for a stable setup. Since it’s a strategy that doesn’t accept losses, the trade can remain open for a long time, despite the potential for liquidation. The optimization process takes these aspects into account, and liquidation has been modeled using typical “isolated margin” limits plus an additional safety buffer.

Start                     2021-06-02 10:40:00
End                       2024-09-28 10:45:00
Duration                   1214 days 00:05:00
Equity Final [$]                   5209.83856
Commissions [$]                     420.80113
Return [%]                          941.96771
Buy & Hold Return [%]                -71.5597
Return (Ann.) [%]                   102.19721
CAGR [%]                             102.3141
Sharpe Ratio                          1.13084
Max. Drawdown [%]                   -42.69857
# Trades                                 2573
Win Rate [%]                         82.66615
margin calls                                0

The whole article and research jupyter is available on substack

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Torna in alto