//+------------------------------------------------------------------+ //| Equity_vs_Forex_Asymmetry_Significance_Test.mq5 | //| Copyright 2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #resource "\\Files\\VolatilityModels\\sp500.csv" as string equity_data #property script_show_inputs #include //--- input parameters input string Symbol_="AUDUSD"; input ENUM_TIMEFRAMES TimeFrame=PERIOD_D1; input datetime StartDate=D'2025.01.01'; input ENUM_VOLATILITY_MODEL VolatilityModel = VOL_GJR_GARCH; input double ScaleFactor=100.; input ENUM_MEAN_MODEL MeanModel = MEAN_CONSTANT; input bool MeanConstant = true; input ulong _P_ = 1; input ulong _O_ = 1; input ulong _Q_ = 1; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { if(VolatilityModel != VOL_GJR_GARCH && VolatilityModel!=VOL_TARCH) { Print(" INVALID INPUT: choose either Tarch or Gjr-Garch"); return; } //--- matrix data = np::readcsv_from_string(equity_data,false,",",true,0); vector equity = data.Col(1); vector forex; if(!forex.CopyRates(Symbol_,TimeFrame,COPY_RATES_CLOSE,datetime(data[0,0]),datetime(data[data.Rows()-1,0]))) { Print(" failed to get close prices for ", Symbol_,". Error ", GetLastError()); return; } forex = log(forex); equity = log(equity); forex = np::diff(forex); equity = np::diff(equity); forex*=ScaleFactor; equity*=ScaleFactor; ArchParameters asym_vol_spec; asym_vol_spec.include_constant = MeanConstant; asym_vol_spec.mean_model_type = MeanModel; asym_vol_spec.vol_model_type = VolatilityModel; asym_vol_spec.garch_p = _P_; asym_vol_spec.garch_q = _Q_; asym_vol_spec.garch_o = _O_; asym_vol_spec.observations=equity; HARX* equity_model = NULL; HARX* forex_model = NULL; switch(MeanModel) { case MEAN_CONSTANT: equity_model = new ConstantMean(); forex_model = new ConstantMean(); break; case MEAN_ZERO: equity_model = new ZeroMean(); forex_model = new ZeroMean(); break; default: equity_model = new ConstantMean(); forex_model = new ConstantMean(); break; } if(!equity_model.initialize(asym_vol_spec)) { delete equity_model; return; } ArchModelResult equity_result = equity_model.fit(ScaleFactor); Print("Results for ", EnumToString(VolatilityModel)); if(!equity_result.params.Size()) { Print(" Equity model fit failed "); delete equity_model; } else { Print(" Equity: Pvalue of gamma parameter is ", equity_result.pvalues()[3]); delete equity_model; } asym_vol_spec.observations = forex; if(!forex_model.initialize(asym_vol_spec)) { delete forex_model; return; } ArchModelResult forex_result = forex_model.fit(ScaleFactor); if(!forex_result.params.Size()) { Print(" Forex model fit failed "); delete forex_model; } else { Print(" Forex: Pvalue of gamma parameter is " , forex_result.pvalues()[3]); delete forex_model; } } //+------------------------------------------------------------------+