繁体   English   中英

皮尔逊相关系数计算 MQL4

[英]Pearson Correlation Coefficient calculation MQL4

嗨,我正在尝试计算跨 nbars 的 Pearson 相关系数。 [Pearson 相关系数方程1

我正在尝试使用 for 循环 function 来做到这一点。 x^2 y^2 total 由 for 循环收集,但 MathPow(f,2) function 不起作用。 其次,我不知道如何计算每个柱的 xy 计算以找到总的 xy 计算。 想法? 我还想知道是否有更好的方法来计算皮尔逊相关系数 (r)。

  //time
   double y1=0.0;
   int counttime=2000;
   for(int c=counttime-1; c>=0; c--)
     {
      y1+=Time[c];
     }
   double Meantime = totaltime/counttime;

      double y2=0.0;
   int counttime2=2000;
   for(int f=counttime2-1; f>=0; f--)
     {
      y2+=Time[MathPow(f,2)];
     }
   double Meantime2 = totaltime2/counttime2;
   
  //  Price
   double x1=0.0;
   int count1=2000;
   for(int g=count1-1; g>=0; g--)
     {
      x1+=High[g];
     }
   
    double x2=0.0;
   int countprice=2000;
   for(int e=countprice-1; e>=0; e--)
     {
      x2+=High[MathPow(e,2)];
     }  

 double x22 = MathPow(x1,2);
       double y22 = MathPow(y1,2);

  
 double r = (count1*(x1*y1)-(x1*y1))/sqrt(count1*(x2-x22)*(count1*(y2-y22));

您的实际公式解释似乎不正确:试试这个:

int count=2000;

double time=0.0, high=0.0;
for(int i=count-1; i>=0; i--) {time+=double(Time[i]); high+=High[i];}
double timeAVG=time/count; double highAVG=high/count;

double timeDiff=0.0, highDiff=0.0, ProductDiff=0.0;
for(int i=count-1; i>=0; i--) {timeDiff+=MathPow(double(Time[i])-timeAVG,2); highDiff+=MathPow(High[i]-highAVG,2); ProductDiff+=(double(Time[i])-timeAVG)*(High[i]-highAVG);}

Print("Correlation = ", DoubleToString(ProductDiff/(MathSqrt(timeDiff)*MathSqrt(highDiff)),8));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM