[英]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.