public override void OnData(Slice slice) { var symbol = Securities[_symbol].Symbol; if (slice.HasData && slice.TryGetValue(symbol, out var ticks)) { foreach (var tick in ticks) { _vwapCalculator.Tick(tick.Price, tick.Quantity); } } }
public void OnTick_ShouldCalculateAverage(decimal[] values, long[] weights, double[] expected) { Assert.AreEqual(values.Length, weights.Length, $"Length of {nameof(values)} does not match that of {nameof(weights)}"); Assert.AreEqual(values.Length, expected.Length, $"Length of {nameof(values)} does not match that of {nameof(expected)}"); Assert.AreNotEqual(0, values.Length, $"Length of {nameof(values)} must not be 0"); for (var i = 0; i < values.Length; i++) { sut.Tick(values[i], weights[i]); var actual = sut.Average; Assert.IsTrue(Utilities.ApproximatelyEquals(expected[i], actual), $"Average is incorrect at step i={i}. Expected={expected[i]}, Actual={actual}"); } }