거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Twitter에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

DrawdownBootstrap: Monte Carlo of the maximal drawdown - MetaTrader 5용 라이브러리

Mohamed-amine Baddir
Mohamed-amine Baddir
MetaTrader 5용 Expert Advisor(EA)를 개발하고, 실제 거래에 사용하기 전에 충분히 테스트합니다.
제가 제공하는 작업:
고객의 전략, TradingView 스크립트 또는 문서화된 규칙을 깔끔한 MT5 Expert Advisor로 구현
기존 EA 수정 및 문제 해결: % 기준 리스크 포지션 사이징, 트레일링 스톱, 세션 및 시간 필터, 스프레드 필터, 멀티 심볼 포트폴리오, 드로다운 보호 기능
조회수:
155
평가:
(1)
게시됨:
\MQL5\Include\DrawdownBootstrap\ \MQL5\Scripts\DrawdownBootstrap\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

DrawdownBootstrap.mqh estimates how deep the drawdown of an account or a strategy can get over the coming months, from its past daily results. The worst drawdown of a backtest happened once, in one order of events; a Monte Carlo of the same results in other orders shows the range to expect, and how often the worst of the history is exceeded.

Usage

#include <DrawdownBootstrap\DrawdownBootstrap.mqh>

double days[];                      // daily results in money (or in percent)
// ... fill the days ...
double dd[];
CDrawdownBootstrap::Run(days, 252, 10000, 10.0, 12345, dd);   // horizon, paths, mean block, seed
double p95 = CDrawdownBootstrap::Quantile(dd, 0.95);          // 1 period in 20 goes deeper than this
double worst = CDrawdownBootstrap::MaxDrawdown(days);         // the drawdown of the history itself

How it works

  • Stationary bootstrap (Politis and Romano, 1994): a simulated path starts on a random day, continues with the following days, and jumps to a new random day with probability 1 / meanBlock. Whole stretches of days are kept together, so losing streaks and days when several positions lost at once stay in the simulation; drawing single days independently would make the drawdowns look smaller than they are.
  • For each path the largest fall of the cumulated results from their peak is recorded. Quantile() gives any percentile of these drawdowns, with linear interpolation.
  • CSeededRandom is a small mulberry32 generator: the same seed gives the same simulation on every computer, so a result can be checked again.
  • Days are taken as they come: results in money assume fixed lots; for lots that grow with the balance, pass daily results in percent of the balance.

Example

The script DrawdownBootstrapExample.mq5 takes the daily closed results of this account (all of them or one magic number), or a CSV file of daily results, simulates 10 000 paths of one year and prints the percentiles of the drawdown in money and as a percent of a capital, and the share of the paths that go deeper than the worst drawdown of the history (picture 1).

Output of DrawdownBootstrapExample.mq5

Checked

On 1 041 days of results, three runs (2 000 paths of 252 days with blocks of 10 days, 500 paths of 63 days with single days, 300 paths of 500 days with blocks of 25 days, three different seeds) gave the same drawdown for every path as an independent Python version of the same algorithm, within 2e-11.

Files

DrawdownBootstrap.mqh goes to MQL5\Include\DrawdownBootstrap, DrawdownBootstrapExample.mq5 to MQL5\Scripts\DrawdownBootstrap.

PortfolioWeights: risk parity, HRP, minimum variance and maximum diversification PortfolioWeights: risk parity, HRP, minimum variance and maximum diversification

Portfolio weights from the returns of symbols or Expert Advisors: inverse volatility, risk parity, hierarchical risk parity, minimum variance, maximum diversification, Ledoit-Wolf covariance.

TesterReport: read a saved Strategy Tester report into deals and trades TesterReport: read a saved Strategy Tester report into deals and trades

Reads a Strategy Tester report saved as HTML into its deals, closed trades, net profit and balance drawdowns, for comparing, combining or exporting backtests.

BacktestOverfitting: probability of backtest overfitting (PBO) of an optimization BacktestOverfitting: probability of backtest overfitting (PBO) of an optimization

Probability of Backtest Overfitting (PBO) of an MT5 optimization by combinatorially symmetric cross-validation. Every pass sends its daily results as a frame, and the PBO is computed when the optimization ends.

Risk Lot Panel Risk Lot Panel

On-chart panel that turns a risk setting into a lot size and shows what the broker's volume step and minimum lot do to that risk. Display only - it never places, modifies or closes an order.