コード例 #1
0
        public void CalculateExponentialMovingAverageFromBasicPriceHistory()
        {
            int searchId = 2, conditionId = 2;
            var mockRepository = CreateBasicMockRepository(searchId, conditionId);

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(searchId, conditionId);

            sut.AddExponentialMovingAverage(results, 5);

            var emas = results.Select(ph => ph.EMA.HasValue ? Math.Round(ph.EMA.Value, 8) : ph.EMA);

            // Test results
            emas.AssertSequenceIsEqual(null, null, null, null, 12.694, 12.976, 12.64733333, 12.60822222, 12.66548148,
                13.36365432, 13.57243621, 13.74495748, 14.01663832, 14.34442554, 13.3262837, 13.21752246);
        }
コード例 #2
0
        public void CalculateExponentialMovingAverageWhenIntervalBiggerThanNumberOfPricesDoesntSetEMAs()
        {
            var mockRepository = A.Fake<ISoldOutRepository>();

            A.CallTo(() => mockRepository.GetSearchResultsByProductID(A<int>.Ignored, A<int>.Ignored, A<bool>.Ignored)).Returns(CreateListOfTwoSearchResults());

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(1, 2);

            sut.AddExponentialMovingAverage(results, 5);

            foreach (var result in results)
                Assert.IsNull(result.EMA);
        }
コード例 #3
0
        public void CalculateExponentialMovingAverageWhenIntervalEqualsNumberOfPrices()
        {
            var mockRepository = A.Fake<ISoldOutRepository>();

            A.CallTo(() => mockRepository.GetSearchResultsByProductID(A<int>.Ignored, A<int>.Ignored, A<bool>.Ignored)).Returns(CreateTestSearchResults().Take(5));

            var sut = new PriceHistoryService(mockRepository) as IPriceHistoryService;

            var results = sut.CreateBasicPriceHistory(1, 2);

            sut.AddExponentialMovingAverage(results, 5);

            Assert.AreEqual(Math.Round(results[4].EMA.Value, 3), 12.694);
        }