线性回归渠道 - 页 13

 
Задача: Подсчет среднего значения и дисперсии числового ряда
Задача: Подсчет среднего значения и дисперсии числового ряда
  • 投票: 2
  • 2015.10.16
  • Google+
  • purecodecpp.com
Эта задача имеет очень большое практическое применение: в статистической обработке данных, обработке временных рядов, в цифровой обработке сигналов применительно к цифровым отсчётам сигнала. Постановка задачи такая: – вводится последовательность (вещественных) чисел … – нужно просчитать, в итоге, среднее значение и дисперсию (или СКО...
 

我会试一试的。

 

这里是 1

下面是计算结果。

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

   int start;
   if(prev_calculated==0){
      start=period;
      double ms=0;
      for(int i=0;i<period;i++){
         ms+=close[i];
      }
      ma[period-1]=ms/period;
   }
   else{
      start=prev_calculated-1;
   }

   for(int i=start;i<rates_total;i++){      
      //ma[i]=ma[i-1]+(-close[i-period]+close[i])/period;      
      double s1=0;
      double s2=0;
      for(int j=i-period+1;j<=i;j++){
         s1+=close[j];
         s2+=close[j]*close[j];
      }
      s1/=period;
      s2=s2/period-s1*s1;
      Label1Buffer[i]=s2;
   }

   return(rates_total);
  }

不是一个加速的算法来检查公式。也许我做错了什么?

附加的文件:
stdX4.mq5  6 kb
 
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      period=14;
//--- indicator buffers
double         Label1Buffer[];

int OnInit()
  {
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);


//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   static double ms,ms2;
   int start;
   if(prev_calculated==0)
     {
      start=period;
      ms=0; ms2=0;
      for(int i=0;i<period;i++)
        {
         ms +=close[i];
         ms2+=close[i]*close[i];
        }
     }
   else
     {
      start=prev_calculated-1;
     }

   for(int i=start;i<rates_total;i++)
     {
      double Ms =ms +(-close[i-period]+close[i]);
      double Ms2=ms2+(-close[i-period]*close[i-period]+close[i]*close[i]);
      double s=Ms/period;
      Label1Buffer[i]=sqrt(s*s+(Ms2-2*Ms*s)/period);
      ms=Ms;
      ms2=Ms2;
     }
   return(rates_total);
  }
 
Yuriy Asaulenko:
不是和你打赌。2.天的沉默,请。
反正你不会得到任何轩尼诗)。但你会毁了我的晚餐。

喝酒对你不好。对不起。我先来的。))

 

谷歌 "移动标准差"

https://www.johndcook.com/blog/standard_deviation/

Accurately computing running variance
  • www.johndcook.com
The most direct way of computing sample variance or standard deviation can have severe numerical problems. Mathematically, sample variance can be computed as follows. The most obvious way to compute variance then would be to have two sums: one to accumulate the sum of the x‘s and another to accumulate the sums of the squares of the x‘s. If the...
 
Dmitry Fedoseev:

这里是

下面是计算结果。

不是一个加速的算法来检查公式。也许你做错了什么?

你没有考虑到新数据的到来和删除旧数据的需要(窗外)。

尼古拉是这样的。请看你的信息下面的代码。

 

所以...我的最后留言。

告诉尤里,让他亲自给我发信息,让我把东西送到哪里,或者买一张证书,或者其他什么。

将会见到你。我将在一个月内回来。

 
Nikolai Semko:

喝酒是不健康的。对不起。我是第一个。))

不客气。我不打算参加比赛。只是要求不要插手,知道的人就闭嘴吧。
这个算法,是的,实际上是等价的,我在该主题的第1-2页写了这个算法。
迪米特里,对不起,虽然经过证明,我不能接受轩尼诗,我很遗憾。
我想,这些代码写起来毫无意义。来吧Semko,就这样......优先想))。仿佛除了迪米特里之外,其他人都有任何怀疑。
我将不得不亲自去商店。
 
Dmitry Fedoseev:

所以...我的最后留言。

告诉尤里,让他亲自给我发信息,让我把东西送到哪里,或者买一张证书,或者其他什么。

将会见到你。我将在一个月内回来。

我很羡慕你。硕果累累的工作!
我的意思是,这不仅可以用RMS来做一个简单的挥舞机,还可以用任何程度的多项式来做。
诚然,该公式随着多项式的度数增加而 指数级增长。