Esempio n. 1
0
        //populate values
        public override void Populate()
        {
            TimeSeries source = Parameters[0].AsTimeSeries;
            Int32      period = Parameters[1].AsInt;

            DateTimes = source.DateTimes;

            //set EMA constant from period
            double rad = 360.0 / period;

            rad = rad.ToRadians();
            double alpha1 = (Math.Cos(rad) + Math.Sin(rad) - 1.0) / Math.Cos(rad);

            //calculate indicator values, prime with median
            int start = period + source.FirstValidIndex;

            if (start >= source.Count)
            {
                return;
            }
            double rm = Median.Calculate(start - 1, source, period);

            Values[start - 1] = rm;
            for (int n = start; n < source.Count; n++)
            {
                rm        = alpha1 * Median.Calculate(n, source, period) + (1.0 - alpha1) * rm;
                Values[n] = rm;
            }
        }
Esempio n. 2
0
        public void CanCalculateMedianWithEvenNumber()
        {
            var data = new List <decimal> {
                1.1m, 2.2m, 3.3m, 4.4m
            };

            var medianVale = Median.Calculate(data);

            Assert.AreEqual(medianVale, 2.75);
        }
Esempio n. 3
0
        public async Task Median_Calculate_ReturnsMedian(
            double[] values,
            double expected)
        {
            // Arrange
            var sut = new Median();

            // Act
            var actual = await sut.Calculate(values);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
 public void WillThrowArgumentExceptionWhenEmptyCollection()
 {
     Assert.Throws <ArgumentException>(() => Median.Calculate(new List <decimal>()));
 }
Esempio n. 5
0
 public void WillThrowArgumentNullExceptionWhenNull()
 {
     Assert.Throws <ArgumentNullException>(() => Median.Calculate(null));
 }