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

RealizedVol: range volatility estimators, realized variance and HAR forecasts - 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: 실거래 결과가 백테스트와 다른 이유, 손절과 청산 위치
조회수:
234
평가:
(1)
게시됨:
\MQL5\Include\RealizedVol\
RealizedVol.mqh (11.01 KB) 조회
\MQL5\Scripts\RealizedVol\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

RealizedVol.mqh measures and forecasts volatility from prices. It has five estimators on OHLC bars (close to close, Parkinson, Garman-Klass, Rogers-Satchell and Yang-Zhang), the daily realized variance, bipower variation and realized quarticity from intraday bars (the bipower variation is the part of the variance without jumps), and the HAR model of Corsi (2009), the usual benchmark for forecasting realized volatility, with Newey-West standard errors. No DLL.

Usage

#include <RealizedVol\RealizedVol.mqh>

MqlRates d1[], m5[];
CopyRates(_Symbol, PERIOD_D1, 1, 21, d1);
CopyRates(_Symbol, PERIOD_M5, 1, 300 * 288, m5);
double yz = CRangeVolatility::Estimate(d1, 20, 20, RV_YANG_ZHANG);   // variance per day over the last 20 days
double vol = 100.0 * MathSqrt(yz * 252);                              // % a year
datetime days[];
vector rv, bv, rq;
int counts[];
CRealized::Daily(m5, days, rv, bv, rq, counts);                       // realized and bipower variance per day
CHar har;
if(har.Fit(rv, 5, true))                                              // HAR on log realized variance, 5 days ahead
  {
   double week = 100.0 * MathSqrt(har.Forecast() * 252);              // volatility expected over the next 5 days
  }

What is in it

  • CRangeVolatility: Estimate() over any window of bars, Rolling() for every bar. The range estimators use the high and low of each bar and need 5 to 8 times fewer bars than close to close for the same precision; Rogers-Satchell is right with a drift, Yang-Zhang also counts the gaps between bars (weekend, overnight).
  • CRealized::Daily: one value per day from intraday bars, with the returns inside each day only (the gap from the day before is left out), a shift for the start of the day and a minimum number of bars. Jump() gives the part of the variance above the bipower variation.
  • CHar: the average realized variance of the next 1, 5 or 22 days regressed on the last day and the averages of the last 5 and 22 days, in levels or logs, with Newey-West standard errors, R squared and the forecast.

Example

The script VolatilityForecast.mq5 prints the volatility of a symbol over the last 20 days by the five estimators, its realized volatility from M5 bars (last day and last 22 days), how much of it comes from jumps, and the HAR forecasts for the next day, week and month with their t statistics (picture 1). It can write the daily realized and bipower variances to a CSV file (picture 2).

Output of VolatilityForecast.mq5

Daily realized volatility of gold

Checked

  • the five estimators with windows of 10, 20 and 60 bars on BTCUSDT D1 and XAUUSD H1 against an independent pandas version: within 4e-12;
  • the daily realized variance, bipower variation and quarticity of 1 359 days from 391 271 M5 bars of BTCUSDT against pandas: the same days and counts, values within 2e-12 (4 ms for all the bars);
  • 6 HAR fits (horizons 1, 5 and 22, levels and logs) against statsmodels OLS with HAC covariance: coefficients, standard errors, R squared and forecasts within 2e-12.

Files

RealizedVol.mqh goes to MQL5\Include\RealizedVol, VolatilityForecast.mq5 to MQL5\Scripts\RealizedVol.

Stationarity: KPSS, Phillips-Perron, DF-GLS, Zivot-Andrews and variance ratio tests Stationarity: KPSS, Phillips-Perron, DF-GLS, Zivot-Andrews and variance ratio tests

Five tests to tell a random walk from a mean-reverting series: KPSS, Phillips-Perron, DF-GLS, Zivot-Andrews with the break date, and the variance ratio.

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.

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.

Session Boxes Asia London New York Session Boxes Asia London New York

Draws Asia, London and New York session boxes on the chart with each session's high and low.