//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; } }
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); }
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); }
public void WillThrowArgumentExceptionWhenEmptyCollection() { Assert.Throws <ArgumentException>(() => Median.Calculate(new List <decimal>())); }
public void WillThrowArgumentNullExceptionWhenNull() { Assert.Throws <ArgumentNullException>(() => Median.Calculate(null)); }