//+------------------------------------------------------------------+ //| recursions.mqh | //| Copyright 2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #include"base.mqh" //--- #define SQRT2_OV_PI 0.79788456080286541 const double LNSIGMA_MAX = log(DBL_MAX) - 0.1; //+------------------------------------------------------------------+ //| helper function | //+------------------------------------------------------------------+ double bounds_check(double _sigma2, vector &varbounds) { if(_sigma2varbounds[1]) { if(MathClassify(_sigma2) == FP_NORMAL) _sigma2 = varbounds[1] +log(_sigma2/varbounds[1]); else _sigma2 = varbounds[1] + 1000; } return _sigma2; } //+------------------------------------------------------------------+ //|arch recursion utility | //+------------------------------------------------------------------+ vector arch_recursion(vector& parameters, vector& resids, vector& sigma2, ulong p, ulong nobs, double backcast, matrix &var_bounds) { for(ulong t =0; t= 0) lnsigma2[t] += parameters[loc] * (abs_std_resids[t - 1 - j] - SQRT2_OV_PI); loc += 1; } for(ulong j = 0; j= 0) lnsigma2[t] += parameters[loc] * std_resids[t - 1 - j]; loc += 1; } for(ulong j = 0; j LNSIGMA_MAX) lnsigma2[t] = LNSIGMA_MAX; sigma2[t] = exp(lnsigma2[t]); if(sigma2[t] < var_bounds[t, 0]) { sigma2[t] = var_bounds[t, 0]; lnsigma2[t] = log(sigma2[t]); } else if(sigma2[t] > var_bounds[t, 1]) { sigma2[t] = var_bounds[t, 1] + log(sigma2[t]) - log(var_bounds[t, 1]); lnsigma2[t] = log(sigma2[t]); } std_resids[t] = resids[t] / sqrt(sigma2[t]); abs_std_resids[t] = MathAbs(std_resids[t]); } return sigma2; } //+------------------------------------------------------------------+ //|Compute variance recursion for GARCH and related models | //+------------------------------------------------------------------+ vector garch_recursion(vector ¶meters, vector& fresids,vector& sresids, vector& sigma2, ulong p, ulong o, ulong q, ulong nobs, double backcast,matrix &var_bounds) { for(long t = 0; t= 0) m_insigma2[t] += parameters[loc] * (m_abs_std_resids[t - 1 - j] - SQRT2_OV_PI); loc += 1; } for(ulong j = 0; j= 0) m_insigma2[t] += parameters[loc] * m_std_resids[t - 1 - j]; loc += 1; } for(ulong j = 0; j LNSIGMA_MAX) m_insigma2[t] = LNSIGMA_MAX; sigma2[t] = exp(m_insigma2[t]); if(sigma2[t] < var_bounds[t, 0]) { sigma2[t] = var_bounds[t, 0]; m_insigma2[t] = log(sigma2[t]); } else if(sigma2[t] > var_bounds[t, 1]) { sigma2[t] = var_bounds[t, 1] + log(sigma2[t]) - log(var_bounds[t, 1]); m_insigma2[t] = log(sigma2[t]); } } };*/ //+------------------------------------------------------------------+