Quant Metrics
- ライブラリ
- バージョン: 1.0
QuantMetrics – Deflated Sharpe, Monte Carlo & OnTester Criteria
Stop optimising on net profit. QuantMetrics gives your EA the statistics quant funds use to separate skill from luck, in a single #import.
Features
- Deflated Sharpe Ratio (DSR) – Bailey & López de Prado. Probability your Sharpe is real after accounting for skew, fat tails and the number of optimisation passes.
- Probabilistic Sharpe Ratio (PSR) – Probability the true Sharpe beats any benchmark, given your sample size.
- Monte Carlo – Trade-order reshuffling: drawdown at any percentile and probability of ruin.
- Risk-adjusted ratios – Sharpe, Sortino, Calmar, CAGR, Ulcer Index, Ulcer Performance Index, Kestner K-Ratio, Van Tharp SQN, skewness, kurtosis.
- 10 OnTester criteria – Recovery, Sharpe, Sortino, Calmar, UPI, K-Ratio, SQN, PSR, DSR, PSR×Calmar, with a minimum trade count.
- Reads history directly – Filter by magic and symbol. Swaps, commissions and fees are included. Or load your own return array.
Quick start
1. Buy and download the library. MetaTrader installs it to MQL5\Libraries\QuantMetrics.ex5.
2. Paste the import block below at the top of your EA, indicator or script.
3. Call the functions.
double OnTester() { QM_BuildFromHistory(TesterStatistics(STAT_INITIAL_DEPOSIT),-1,""); QM_SetTrials(200); // optimisation passes you ran Print(QM_Report()); return(QM_Criterion(QM_CRIT_DSR,30)); }
Import block (copy into your code)
#define QM_OK 0 #define QM_ERR_NODATA 1 #define QM_ERR_PARAM 2 #define QM_ERR_HISTORY 3 #define QM_CRIT_RECOVERY 0 #define QM_CRIT_SHARPE 1 #define QM_CRIT_SORTINO 2 #define QM_CRIT_CALMAR 3 #define QM_CRIT_UPI 4 #define QM_CRIT_KRATIO 5 #define QM_CRIT_SQN 6 #define QM_CRIT_PSR 7 #define QM_CRIT_DSR 8 #define QM_CRIT_PSR_CALMAR 9 #import "QuantMetrics.ex5" int QM_LastError(); int QM_BuildFromHistory(const double initial_deposit,const long magic,const string symbol); int QM_LoadReturns(const double &returns[],const double start_equity,const double years); int QM_Trades(); double QM_NetProfit(); double QM_WinRate(); double QM_ProfitFactor(); double QM_Expectancy(); int QM_MaxConsecLosses(); double QM_MaxDrawdownPct(); double QM_MaxDrawdownMoney(); double QM_RecoveryFactor(); double QM_CAGR(); double QM_Skewness(); double QM_Kurtosis(); double QM_Sharpe(const bool annualize); double QM_Sortino(const bool annualize); double QM_Calmar(); double QM_UlcerIndex(); double QM_UlcerPerformance(); double QM_KRatio(); double QM_SQN(); double QM_ProbabilisticSharpe(const double benchmark_sr); bool QM_SetTrials(const int trials); double QM_DeflatedSharpe(); bool QM_MonteCarlo(const int sims,const double percentile,const double ruin_dd_pct, const uint seed,double &dd_at_percentile,double &prob_ruin); double QM_Criterion(const int mode,const int min_trades); string QM_Report(); #import
Notes
- Select Custom max in the Strategy Tester to rank passes by your criterion.
- Monte Carlo work is capped so optimisation stays fast.
- Example on S&P 500 daily (Donchian 55/20): PSR 0.90 falls to DSR 0.11 after 100 tested variants.
Technical
- Pure MQL5. No DLL, no WebRequest, no file I/O.
- Every exported function validates its inputs. QM_LastError() returns the reason for any failed call.
- Works in the Strategy Tester and live, on any broker, symbol and account currency.
Past performance shown in screenshots is from historical data and does not guarantee future results.
