Discussion of article "Statistical Distributions in MQL5 - taking the best of R" - page 14

 

Forum on trading, automated trading systems and testing trading strategies

Help with correlation

Quantum, 2016.12.01 12:53 pm.

Math.mqh file should be put in terminal_data_folder\MQL5\Include\Math\Stat\ folder.

It does not compile under MT4. #property strict does not help

'Math.mqh'      Math.mqh        1       1
'MathLog1p' - no one of the overloads can be applied to the function call       Math.mqh        4655    17
'MathLog1p' - no one of the overloads can be applied to the function call       Math.mqh        4676    16
'MathExpm1' - no one of the overloads can be applied to the function call       Math.mqh        4702    17
'MathExpm1' - no one of the overloads can be applied to the function call       Math.mqh        4723    16
'MathSinh' - no one of the overloads can be applied to the function call        Math.mqh        4750    17
'MathSinh' - no one of the overloads can be applied to the function call        Math.mqh        4772    16
'MathCosh' - no one of the overloads can be applied to the function call        Math.mqh        4799    17
'MathCosh' - no one of the overloads can be applied to the function call        Math.mqh        4821    16
'MathTanh' - no one of the overloads can be applied to the function call        Math.mqh        4848    17
'MathTanh' - no one of the overloads can be applied to the function call        Math.mqh        4870    16
'MathArcsinh' - no one of the overloads can be applied to the function call     Math.mqh        4897    17
'MathArcsinh' - no one of the overloads can be applied to the function call     Math.mqh        4919    16
'MathArccosh' - no one of the overloads can be applied to the function call     Math.mqh        4946    17
'MathArccosh' - no one of the overloads can be applied to the function call     Math.mqh        4968    16
'MathArctanh' - no one of the overloads can be applied to the function call     Math.mqh        4995    17
'MathArctanh' - no one of the overloads can be applied to the function call     Math.mqh        5017    16
16 error(s), 0 warning(s)               17      1
MQL4 bug?
 
Question to the developer, why are the math functions (in the Math.mqh file) not wrapped in a class? Maybe they work faster that way?
 

This is an MQL5 library without MQL4 support.

Classes are not needed in this matrix library.

 
Renat Fatkhullin:

This is an MQL5 library without MQL4 support.

But it works 99% in MQL4, just like GraphPlot. It would be 100% if they fixed the bug in MQL4 - none of the overloads can be applied to the function call.
 
The topic of MQL4 and MT4 is closed. There will be no movements or improvements there.
 
fxsaber:
But it works 99% in MQL4, just like GraphPlot. It would be 100% if they fixed the bug in MQL4 - none of the overloads can be applied to the function call.

I looked carefully, but this is not a bug of MQL4, but a bug of MQL5!

//+------------------------------------------------------------------+
//| MathLog1p|
//+------------------------------------------------------------------+
//| The function calculates log(1+x) for the elements from the array.||
//||
//| Arguments:|
//| array[] : Array with values|
//| result[] : Output array with calculated values |
//||
//| Return value: true if successful, otherwise false |
//+------------------------------------------------------------------+
bool MathLog1p(const double &array[],double &result[])
  {
   int size=ArraySize(array);
   if(size==0)
      return(false);
//--- prepare target array
   if(ArraySize(result)<size)
      if(ArrayResize(result,size)!=size)
         return(false);
//--- calculate values
   for(int i=0; i<size; i++)
      result[i]=MathLog1p(array[i]);
//---
   return(true);
  }
//+------------------------------------------------------------------+
//| MathLog1p|
//+------------------------------------------------------------------+
//| The function calculates log(1+x) for the elements from the array.||
//||
//| Arguments:|
//| array[] : Array with values|
//||
//| Return value: true if successful, otherwise false |
//+------------------------------------------------------------------+
bool MathLog1p(double &array[])
  {
   int size=ArraySize(array);
   if(size==0)
      return(false);
//--- calculate values
   for(int i=0; i<size; i++)
      array[i]=MathLog1p(array[i]);
//---
   return(true);
  }

MQL4 correctly cusses - no one of the overloads can be applied to the function call. But MQL5 is silent when there is an obvious error. @Renat Fatkhullin, a bug?

 
fxsaber:
MQL4 correctly warns - no one of the overloads can be applied to the function call. And MQL5 is silent when there is an obvious error.

This is not an error. MQL5 has these functions.


 
Quantum:

This is not an error. MQL5 has these functions.

Thank you! And I, like a fool, press ALT+G....
 

Hello,
encountered a problem when calculating the quantile of gamma distribution
in R:
> qgamma(0.05,2,scale=1)
[1] 0.3553615
> qgamma(0.05,10,scale=1)
[1] 5.425406

in mql5:

#include <Math\Stat\Gamma.mqh>
void OnStart()
  {
   int ner;
   double q=MathQuantileGamma(0.05,2,1,ner);
   if(!MathIsValidNumber(q)) {Print("Error ",ner); return;}
   Print(q);
   q=MathQuantileGamma(0.05,10,1,ner);
   if(!MathIsValidNumber(q)) {Print("Error ",ner); return;}
   Print(q);
  }

Results:
0.3553615106986621
Error 4

build 1596

 
Alexey Nikolaev:

Hi,
encountered a problem when calculating the quantile of the gamma distribution

Good afternoon, thank you for your message.

Error 4 means convergence problems in Newton's back iteration algorithm, which is used to find quantiles. We will look into it.