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

Stationarity: KPSS, Phillips-Perron, DF-GLS, Zivot-Andrews and variance ratio tests - MetaTrader 5용 라이브러리

Mohamed-amine Baddir
Mohamed-amine Baddir
  • MT5 developer: EA testing and risk tools 에  Independent MQL5 developer
  • 모로코
  • 1701
Market의 MetaTrader 5 도구 (구매 전에 전략 테스터에서 무료로 사용해 볼 수 있습니다):
- Prop Risk Guard: 프롭 펌 계좌용 일일 손실 및 드로다운 한도
- TradeMirror: MT5 계좌 간 로컬 거래 복사기
- Portfolio Allocator, Portfolio Backtest Combiner: 여러 EA의 랏 배분과 합산 결과
- Backtest vs Live, Trade Excursion Analyzer: 실거래 결과가 백테스트와 다른 이유, 손절과 청산 위치
조회수:
148
평가:
(1)
게시됨:
\MQL5\Include\Stationarity\ \MQL5\Scripts\Stationarity\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Stationarity.mqh has five tests that tell a random walk from a series that comes back to its mean, beyond the augmented Dickey-Fuller test: KPSS (whose null is the other way round: stationarity), Phillips-Perron, DF-GLS of Elliott, Rothenberg and Stock (more power than ADF near a unit root), Zivot-Andrews (a unit root against a stationary series with one structural break, with the date of the break) and the Lo-MacKinlay variance ratio. Every test gives its statistic, p-value, critical values at 1%, 5% and 10%, and the lags or bandwidth used. No DLL.

Usage

#include <Stationarity\Stationarity.mqh>

vector y;                                  // for example log prices
// ... fill y ...
SStationarityResult r;
if(CStationarity::KPSS(y, r, ST_TREND_CONSTANT))                 // null: stationary
   PrintFormat("KPSS %.3f, p-value %.3f, bandwidth %d", r.stat, r.pvalue, r.lags);
if(CStationarity::DFGLS(y, r, ST_TREND_LINEAR))                  // null: unit root
   PrintFormat("DF-GLS %.3f, p-value %.3f, %d lags", r.stat, r.pvalue, r.lags);
if(CStationarity::PhillipsPerron(y, r))
   PrintFormat("Phillips-Perron %.3f, p-value %.3f", r.stat, r.pvalue);
if(CStationarity::ZivotAndrews(y, r, ZA_BREAK_BOTH))             // unit root against one break
   PrintFormat("Zivot-Andrews %.3f, p-value %.3f, break at bar %d", r.stat, r.pvalue, (int)r.extra);
if(CStationarity::VarianceRatio(y, r, 10))                       // random walk?
   PrintFormat("VR(10) %.3f, p-value %.3f", r.extra, r.pvalue);

The tests

  • KPSS, constant or trend: bandwidth chosen automatically (Hobijn, Franses and Ooms), or 12 (n/100)^(1/4), or given. p-values by interpolation in the simulated quantiles.
  • PhillipsPerron, no constant, constant or trend: Z-tau or Z-rho, Newey-West long-run variance, MacKinnon p-values and critical values.
  • DFGLS, constant or trend: the series is detrended by GLS with c = -7 or -13.5, the lag chosen by AIC, BIC or t-statistic on the OLS-detrended series.
  • ZivotAndrews: break in the level, in the trend, or both, every date between the trimmed ends (15% by default); the regression at each date reuses the cross-products of the columns that do not move, so 2 800 bars take about 0.1 s.
  • VarianceRatio: q-period against 1-period variance, overlapping or not, debiased, with the heteroskedasticity robust variance of Lo and MacKinlay. The ratio is in r.extra; below 1 means mean reversion, above 1 momentum.
  • SelectLags (the lag search of the Dickey-Fuller regression) and the DickeyFullerP / DickeyFullerCrit functions for t and normalized bias (z) statistics are public.

The tables of p-values and critical values are in StationarityTables.mqh.

Example

The script StationarityReport.mq5 runs the tests on the log price and on the returns of a symbol and prints each result with its verdict at 5%, the date of the most likely break, and the variance ratios at 2 to 60 bars (picture 1). On EURUSD D1 the price behaves as a random walk and the returns are stationary, as expected; the most likely break is November 2022, just after the low (picture 2).

Output of StationarityReport.mq5

EURUSD and its most likely break

Checked

Against arch 8.0 (arch.unitroot) on six series (a random walk, a stationary AR(1), a trend-stationary series, a series with a break in its level, the log price of gold on H4 and of BTCUSD on D1), 204 tests with every trend, lag rule and option:

  • the same lags, bandwidths, numbers of observations, break dates and critical values;
  • statistics within 3e-11 and p-values within 2e-11.

Files

Stationarity.mqh and StationarityTables.mqh go to MQL5\Include\Stationarity, StationarityReport.mq5 to MQL5\Scripts\Stationarity.

Risk Lot Calculator - lot size from your risk and stop (class for EAs + chart panel) Risk Lot Calculator - lot size from your risk and stop (class for EAs + chart panel)

Drag the stop-loss line and read the lot size that risks exactly your money or percent. The CRiskSizer class does the same in an EA: lot rounded down, minimum lot never forced, max lot, volume limit, stop level and margin checked.

Broker Time - server, UTC, New York, London, Sydney, Tokyo with the right summer time (class + session lines) Broker Time - server, UTC, New York, London, Sydney, Tokyo with the right summer time (class + session lines)

CBrokerTime converts server time, UTC, New York, London, Sydney and Tokyo with the real summer time of every year and finds your broker's clock from the history (also in the tester). The indicator draws session lines and a clock panel.

RealizedVol: range volatility estimators, realized variance and HAR forecasts RealizedVol: range volatility estimators, realized variance and HAR forecasts

Parkinson, Garman-Klass, Rogers-Satchell and Yang-Zhang estimators, daily realized and bipower variance from intraday bars, and HAR volatility forecasts.

Close All Positions and Pending Orders Close All Positions and Pending Orders

Closes all open positions and optionally deletes pending orders with one click. Filter by symbol and magic number.