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

DataSnooping: SPA test, Reality Check, StepM and model confidence set - MetaTrader 5용 라이브러리

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

DataSnooping.mqh answers the question that follows every optimization: the best of many strategies (or of many parameter sets of one strategy) beat the benchmark, but was it better, or only the luckiest of the lot? It has Hansen's test for superior predictive ability (SPA), White's Reality Check, the Romano-Wolf StepM procedure that finds every strategy better than the benchmark, and the model confidence set of Hansen, Lunde and Nason. The bootstrap keeps the dependence of daily results (stationary bootstrap) and takes a seed. No DLL.

Usage

#include <DataSnooping\DataSnooping.mqh>

matrix returns;                            // one column per strategy (or parameter set), one row per day
vector benchmark;                          // returns of the benchmark on the same days (zeros: no position)
// ... fill returns and benchmark ...
CSuperiorAbility spa;
spa.SetData(returns, benchmark, true);     // true: higher is better
spa.Options(2000, 0.0, true, 1);           // draws, mean block (0: square root of the days), studentized, seed
if(spa.Compute())
  {
   double p = spa.PValue(1);               // consistent SPA p-value: is the best really better?
   int better[];
   int n = spa.StepM(0.05, better);        // all the strategies better than the benchmark at 5%
  }
CModelConfidenceSet mcs;
if(mcs.Compute(returns, true, 2000))
  {
   bool kept = mcs.Included(0, 0.1);       // is strategy 0 in the 90% set of the best?
  }

What is in it

  • CSuperiorAbility: the lower, consistent and upper p-values of the SPA test, the Reality Check (the upper p-value without studentization), critical values, the strategies above them, and StepM. Studentized (Hansen 2005: the best t statistic, with the long-run variances of the stationary bootstrap) or not.
  • CModelConfidenceSet: the p-value of every strategy and the set of the best at any size, with the 'R' statistic (pairs of strategies) or the 'max' statistic. The elimination keeps the largest pair of each draw in memory, so 200 strategies take 0.2 s.
  • CStationaryBootstrap: indices of the stationary bootstrap of Politis and Romano with a seed, and the means of the resamples from running sums (a whole block at a time).

A note on arch

The tests follow the Python package arch, and give the same p-values as arch when the same bootstrap draws are used. arch's SPA class has a studentize option, but in version 8.0 its computation does not divide by the standard deviations, so it returns the test without studentization whatever the option. Here, Options(..., studentize = false, ...) gives the same numbers as arch, and studentize = true gives Hansen's statistic, where a strategy with a high mean but very noisy results counts less than a steadier one.

Example

The script SnoopingExample.mq5 builds 100 moving average rules on a symbol (long while the fast average is above the slow one, flat otherwise, 10 fast and 10 slow lengths), or reads the returns of your own strategies from a CSV file, and compares the p-value of the best rule tested alone with the SPA, Reality Check, StepM and model confidence set results (picture 1). On US30 D1 the best rule has a t statistic of 1.72: alone, a p-value of 0.043; as the best of 100, an SPA p-value of 0.19 (picture 2).

Output of SnoopingExample.mq5

t statistics of the 100 rules

Picture 3: the t statistic of each rule, by fast and slow average. Neighbouring rules give similar numbers, because they are in the market on mostly the same days. The bootstrap of the SPA test and of the Reality Check keeps this dependence; a Bonferroni correction would ignore it and be far too strict.

t statistics of the 100 rules on a grid

Picture 4: the same best rule, SMA 5/160. Tested alone, its p-value is 0.043, below 5%. Taken as the best of the 100 rules that were tried, it is 0.244 (Reality Check) and 0.187 (SPA): nothing left to show that it beats staying out of the market.

p-values of the best rule

Checked

With the bootstrap indices drawn by arch 8.0 (stationary bootstrap, 1 000 draws) on three data sets (50 strategies of which 3 have a real edge, 200 correlated parameter sets without edge, the daily results of 9 sample Expert Advisors):

  • SPA without studentization: the lower, consistent and upper p-values identical to arch's, critical values within 2e-15, long-run variances identical, the same better strategies and the same StepM set;
  • SPA studentized: p-values identical to an independent numpy version of Hansen's test;
  • model confidence set, 'R' and 'max': the p-value of every strategy identical to arch's.

Files

DataSnooping.mqh goes to MQL5\Include\DataSnooping, SnoopingExample.mq5 to MQL5\Scripts\DataSnooping.

Basket Pair Closer Basket Pair Closer

Position manager for MT5 that closes the best winner together with the worst loser when their combined result reaches your minimum. Basket take profit and stop loss in money, magic filter, simple panel. Works with grid, martingale and manual trades. Open source code.

Cointegration: ADF, Engle-Granger and Johansen tests with a pair scanner Cointegration: ADF, Engle-Granger and Johansen tests with a pair scanner

Unit root and cointegration tests (ADF, Engle-Granger, Johansen) with MacKinnon p-values, hedge ratio, half-life and z-score of the spread, and a pair scanner.

Swap Markup Scanner Swap Markup Scanner

Shows the broker's hidden financing markup and the carry for every symbol, as annual % of notional.

MACD Signals MACD Signals

Indicator edition for new platform.