Esempio n. 1
0
        public void MovingAverageData3()
        {
            PureData pureData = new PureData(new List <DataElement>
            {
                new DataElement(new DateTime(2018, 2, 19), new[] { 1.1D, 2.1D, 3.1D, 4.1D, 5.1D }),
                new DataElement(new DateTime(2018, 2, 20), new[] { 1.2D, 2.2D, 3.2D, 4.2D, 5.2D }),
                new DataElement(new DateTime(2018, 2, 21), new[] { 1.3D, 2.3D, 3.3D, 4.3D, 5.3D }),
                new DataElement(new DateTime(2018, 2, 21), new[] { 1.4D, 2.4D, 3.4D, 4.4D, 5.4D })
            });

            var sut = new MovingAverage(3, pureData, StockIndex.High);

            DataElement[] inputData = sut.CreateData().ToArray();

            Assert.NotNull(inputData);
            Assert.AreEqual(2, inputData.Length);
            Assert.IsTrue(Math.Abs(3.2D - inputData[0].Values[0]) < 0.00000001, $"{inputData[0].Values[0]}");
            Assert.IsTrue(Math.Abs(3.3D - inputData[1].Values[0]) < 0.00000001, $"{inputData[1].Values[0]}");
        }
Esempio n. 2
0
        public void MovingAverageData2()
        {
            PureData pureData = new PureData(new List <DataElement>
            {
                new DataElement(new DateTime(2018, 2, 19), new[] { 1.1D, 2.1D, 3.1D, 4.1D, 5.1D }),
                new DataElement(new DateTime(2018, 2, 20), new[] { 1.2D, 2.2D, 3.2D, 4.2D, 5.2D }),
                new DataElement(new DateTime(2018, 2, 21), new[] { 1.3D, 2.3D, 3.3D, 4.3D, 5.3D }),
                new DataElement(new DateTime(2018, 2, 21), new[] { 1.4D, 2.4D, 3.4D, 4.4D, 5.4D })
            });

            var sut = new MovingAverage(2, pureData, StockIndex.Close);

            DataElement[] inputData = sut.CreateData().ToArray();

            Assert.NotNull(inputData);
            Assert.AreEqual(3, inputData.Length);
            Assert.IsTrue(Math.Abs(2.15D - inputData[0].Values[0]) < 0.00000001);
            Assert.IsTrue(Math.Abs(2.25D - inputData[1].Values[0]) < 0.00000001);
            Assert.AreEqual(pureData.GetData()[1].Key, inputData[0].Key);
            Assert.AreEqual(pureData.GetData()[2].Key, inputData[1].Key);
            Assert.AreEqual(pureData.GetData()[3].Key, inputData[2].Key);
        }