public void ShouldReturnValidObject_WhenValidInput(decimal fastSMA, decimal slowSMA, TAZ taz, Trend trend) { var result = new TechnicalAnalysisBuilder() .SetFastSMA(fastSMA) .SetSlowSMA(slowSMA) .SetTAZ(taz.ToString()) .SetTrend(trend.ToString()) .Build(); result.Should().NotBeNull(); result.FastSMA.Should().Be(fastSMA); result.SlowSMA.Should().Be(slowSMA); result.TAZ.Should().Be(taz); result.Trend.Should().Be(trend); }
public void ShouldReturnValidObject_WhenValidInput(decimal price, string name, int qty) { ITechnicalAnalysis technicalAnalysis = new TechnicalAnalysisBuilder() .SetFastSMA(1) .SetSlowSMA(2) .Build(); IAnalysis result = new AnalysisBuilder() .SetClosingPrice(price) .SetName(name) .SetQtyInBuyingPacket(qty) .SetTechnicalAnalysis(technicalAnalysis) .Build(); result.Should().NotBeNull(); result.ClosingPrice.Should().Be(price); result.Name.Should().Be(name); result.QtyInBuyingPacket.Should().Be(qty); result.TechnicalAnalysis.Should().Be(technicalAnalysis); }
private KeyValuePair <string, IAnalysis> GetAnalysis(IEnumerable <IMarketDataEntity> marketDataInput) { if (marketDataInput == null) { throw new ArgumentNullException(nameof(marketDataInput)); } try { var marketData = marketDataInput.ToImmutableList(); if (!marketData.Any()) { throw new ArgumentException("Market data set cannot be empty", nameof(marketDataInput)); } var isin = marketDataInput.First().Isin; if (string.IsNullOrEmpty(isin)) { throw new ServiceException("No ISIN found in market data set."); } var closingPrice = marketDataInput.FirstOrDefault().ClosingPrice; var fastSMA = marketDataInput.Take(_fastMovingAverage).Average(d => d.ClosingPrice); var slowSMA = marketDataInput.Take(_slowMovingAverage).Average(d => d.ClosingPrice); var stockBaseData = _registryRepository.GetById(isin); if (stockBaseData is null) { throw new ServiceException($"No registry entry found for {isin}"); } var financialAnalysis = new FinancialAnalysisBuilder() .SetClosingPrice(closingPrice) .SetEPS(stockBaseData.FinancialReport?.EPS) .SetMonthsInReport(stockBaseData.FinancialReport?.MonthsInReport) .Build(); var technicalAnalysis = new TechnicalAnalysisBuilder() .SetFastSMA(fastSMA) .SetSlowSMA(slowSMA) .SetTAZ(GetTAZ(closingPrice, fastSMA, slowSMA)) .SetTrend(GetTrend(fastSMA, slowSMA)) .Build(); if (technicalAnalysis is null) { throw new ServiceException($"No technical analysis can be created for {isin}"); } var analysis = new AnalysisBuilder() .SetClosingPrice(closingPrice) .SetName(stockBaseData.Name) .SetQtyInBuyingPacket((int)Math.Floor(_buyingPacketInEuro / closingPrice)) .SetFinancialAnalysis(financialAnalysis) .SetTechnicalAnalysis(technicalAnalysis) .Build(); if (analysis is null) { throw new ServiceException($"No analysis can be created for {isin}"); } return(new KeyValuePair <string, IAnalysis>(isin, analysis)); } catch (Exception ex) { throw new ServiceException($"No analysis can be created.", ex); } }