Example #1
0
        public void Values_ThreeInputsAndDelayTwo_OneValue()
        {
            var start = 1;
            var end = 3;
            var expected = (decimal)((end - start) / start * 100);
            var rocIndex = new RocIndex(end - start);

            var result = 0.0M;
            var indexValue = rocIndex.Values.FirstAsync().Subscribe(next => result = next);

            Observable.Range(start, end)
                .Select(x => new StockQuote { Open = x })
                .Subscribe(rocIndex);


            Assert.AreEqual(expected, result);
        }
Example #2
0
        public void Values_SixInputsAndDelayTwo_FourValues()
        {
            var delay = 2;
            var inputs = new[] { 22.1M, 22.4M, 21, 19M, 20.5M, 22M };
            var rocIndex = new RocIndex(delay);

            decimal[] indexValues = null;

            rocIndex.Values.ToList().Subscribe(next => indexValues = next.ToArray());

            Observable.ToObservable(inputs)
                .Select(x => new StockQuote { Open = x })
                .Subscribe(rocIndex);

            var expected = inputs
                .Skip(delay)
                .Select((x, i) => (x - inputs[i]) / inputs[i] * 100);

            CollectionAssert.AreEqual(expected.ToArray(), indexValues);
        }
Example #3
0
        static void Main(string[] args)
        {
            BasicConfigurator.Configure();

            var directory = "Files";

            foreach (var filePath in Directory.EnumerateFiles(directory))
            {
                var descriptor = new SourceDescriptor(filePath);
                var reader = new SourceReader();
                var delay = 10;
                var inputSource = new StockQuotesStream(reader);
                var rocIndex = new RocIndex(delay);

                inputSource.Inputs.Subscribe(rocIndex);
                var pocket = new Pocket(inputSource.Inputs.Skip(delay), rocIndex.Values.Select(x => x > 0 ? true : false), 1000);

                decimal finalValue = 0;
                pocket.Money.Subscribe(Console.WriteLine);

                inputSource.Start(descriptor);
                Console.WriteLine(String.Format("{0}: {1}", Path.GetFileName(filePath), finalValue));
            }
        }