Ejemplo n.º 1
0
        public void Indicator_Chaining_MAofMA()
        {
            var results1 = new List<DataPoint<decimal>>();
            var results2 = new List<DataPoint<decimal>>();
            var ma1 = new MovingAverageIndicator(2);
            var ma2 = new MovingAverageIndicator(2);
            ma1.Subscribe(ma2); // ma2 of ma1
            ma1.Subscribe(results1.Add);
            ma2.Subscribe(results2.Add);

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 1));
            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 2));
            Assert.That(results1.Last().Value, Is.EqualTo(1.5));
            Assert.That(results2.Any(), Is.EqualTo(false));

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 3));
            Assert.That(results1.Last().Value, Is.EqualTo(2.5));
            Assert.That(results2.Last().Value, Is.EqualTo(2));

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 4));
            Assert.That(results1.Last().Value, Is.EqualTo(3.5));
            Assert.That(results2.Last().Value, Is.EqualTo(3));

            ma1.OnNext(new DataPoint<decimal>(DateTime.Now, 5));
            Assert.That(results1.Last().Value, Is.EqualTo(4.5));
            Assert.That(results2.Last().Value, Is.EqualTo(4));

            ma1.Dispose();
            ma2.Dispose();
        }
Ejemplo n.º 2
0
        public void ProducesValues()
        {
            var sut = new MovingAverageIndicator(3);
            
            var results = new List<DataPoint<decimal>>();
            using (sut.Subscribe(results.Add))
            {
                sut.OnNext(new DataPoint<decimal>(DateTime.Now, 1));
                Assert.That(results.Count, Is.EqualTo(0));

                sut.OnNext(new DataPoint<decimal>(DateTime.Now, 2));
                Assert.That(results.Count, Is.EqualTo(0));

                sut.OnNext(new DataPoint<decimal>(DateTime.Now, 3));
                Assert.That(results.Count, Is.EqualTo(1));
                Assert.That(results.Last().Value, Is.EqualTo(2));

                sut.OnNext(new DataPoint<decimal>(DateTime.Now, 4));
                Assert.That(results.Count, Is.EqualTo(2));
                Assert.That(results.Last().Value, Is.EqualTo(3));

                sut.OnNext(new DataPoint<decimal>(DateTime.Now, 2));
                Assert.That(results.Count, Is.EqualTo(3));
                Assert.That(results.Last().Value, Is.EqualTo(3));

                sut.Dispose();
            }
        }
Ejemplo n.º 3
0
        public void CompositeIndicator()
        {
            var ciResults = new List<DataPoint<decimal>>();
            var maResults = new List<DataPoint<decimal>>();

            var ci = new CountIndicator(TimeSpan.FromSeconds(1));
            var ma = new MovingAverageIndicator(2);
            
            // composite indicator
            ci.Subscribe(ma);
            ci.Subscribe(ciResults.Add);
            ma.Subscribe(maResults.Add);

            // 2 second test

            // produce 10 in the second #1
            for (int i = 0; i < 10; i++)
            {
                ci.OnNext(new DataPoint<decimal>(DateTime.Now, 1));
                Thread.Sleep(99);
            }
            Thread.Sleep(50);
            // produce 20 in the second #2
            for (int i = 0; i < 20; i++)
            {
                ci.OnNext(new DataPoint<decimal>(DateTime.Now, 1));
                Thread.Sleep(48);
            }


            Thread.Sleep(50);

            Assert.That(ciResults.ElementAt(0).Value, Is.EqualTo(10));
            Assert.That(ciResults.ElementAt(1).Value, Is.EqualTo(20));
            Assert.That(maResults.ElementAt(0).Value, Is.EqualTo(15));

        }