Esempio n. 1
0
        public double next(double toadd)
        {
            var todel = delay.next(toadd);

            // adjust the sorted prices...
            var endIndx = length - 1;

            for (int i = 0; i < length; ++i)
            {
                if (prices[i] == todel)
                {
                    if ((i == endIndx) ||
                        (prices[i + 1] >= toadd))
                    {
                        prices[i] = toadd;
                        break;
                    }
                    prices[i] = prices[i + 1];
                    todel     = prices[i];
                }
                else if (prices[i] > toadd)
                {
                    var tmp = prices[i];
                    prices[i] = toadd;
                    toadd     = tmp;
                }
            }

            // compute the median
            var ans = prices[length / 2];

            if ((length & 1) == 0)
            {
                ans = (0.5 * (ans + prices[length / 2 - 1]));
            }
            return(ans);
        }
Esempio n. 2
0
 public double next(double price)
 {
     sum = sum - delay.next(price) + price;
     return(sum / length);
 }