Ejemplo n.º 1
0
        public IEnumerable <DataSet> GetDataSets(int assetId, int timeframeId)
        {
            _repository = new EFQuotationRepository();
            var quotationDtos = _repository.GetQuotations(assetId, timeframeId).OrderBy(q => q.DateIndex);
            var extremumDtos  = _repository.GetExtrema(assetId, timeframeId);
            var result        = new List <DataSet>();

            foreach (var dto in quotationDtos)
            {
                var ds        = new DataSet(assetId, timeframeId, dto.Date, dto.DateIndex);
                var quotation = Quotation.FromDto(dto);
                ds.quotation = quotation;
                ds.price     = new Price();
                result.Add(ds);
            }

            foreach (var dto in extremumDtos)
            {
                var extremum = Extremum.FromDto(dto);
                var ds       = result.SingleOrDefault(d => d.DateIndex == extremum.DateIndex && d.TimeframeId == extremum.TimeframeId);
                if (ds != null && ds.price != null)
                {
                    ds.price.SetExtremum(extremum);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public void FromDto_ReturnsProperExtremumObject()
        {
            //Arrange

            ExtremumDto dto = new ExtremumDto()
            {
                Id                  = 1,
                SimulationId        = DEFAULT_SIMULATION_ID,
                Date                = DEFAULT_BASE_DATE,
                IndexNumber         = DEFAULT_INDEX_NUMBER,
                AssetId             = DEFAULT_ASSET_ID,
                TimeframeId         = DEFAULT_TIMEFRAME_ID,
                LastCheckedDateTime = new DateTime(2017, 3, 5, 12, 0, 0),
                ExtremumType        = 1,
                Volatility          = 1.23,
                EarlierCounter      = 15,
                EarlierAmplitude    = 7.45,
                EarlierChange1      = 1.12,
                EarlierChange2      = 2.21,
                EarlierChange3      = 3.12,
                EarlierChange5      = 4.56,
                EarlierChange10     = 5.28,
                LaterCounter        = 16,
                LaterAmplitude      = 1.23,
                LaterChange1        = 0.72,
                LaterChange2        = 0.54,
                LaterChange3        = 1.57,
                LaterChange5        = 2.41,
                LaterChange10       = 3.15,
                IsOpen              = true,
                Timestamp           = DateTime.Now,
                Value               = 123.42
            };


            //Act
            Price    price          = getPrice(DEFAULT_INDEX_NUMBER);
            Extremum actualExtremum = Extremum.FromDto(price, dto);

            //Assert
            Extremum expectedExtremum = new Extremum(price, ExtremumType.PeakByClose)
            {
                ExtremumId          = 1,
                SimulationId        = DEFAULT_SIMULATION_ID,
                LastCheckedDateTime = new DateTime(2017, 3, 5, 12, 0, 0),
                Volatility          = 1.23,
                EarlierCounter      = 15,
                EarlierAmplitude    = 7.45,
                EarlierChange1      = 1.12,
                EarlierChange2      = 2.21,
                EarlierChange3      = 3.12,
                EarlierChange5      = 4.56,
                EarlierChange10     = 5.28,
                LaterCounter        = 16,
                LaterAmplitude      = 1.23,
                LaterChange1        = 0.72,
                LaterChange2        = 0.54,
                LaterChange3        = 1.57,
                LaterChange5        = 2.41,
                LaterChange10       = 3.15,
                Open  = true,
                Value = 123.42
            };

            Assert.AreEqual(expectedExtremum, actualExtremum);
        }