Esempio n. 1
0
        public void ShouldReturnValidObject_WhenValidInput(
            decimal price,
            decimal eps,
            int months,
            decimal expectedPE)
        {
            var result = new FinancialAnalysisBuilder()
                         .SetClosingPrice(price)
                         .SetEPS(eps)
                         .SetMonthsInReport(months)
                         .Build();

            result.PE.Should().Be(expectedPE);
        }
        public void ShouldReturnValidObject_WhenValidInput(
            string isin,
            string name,
            string ownInvestorLink,
            string stockExchangeLink,
            string position)
        {
            var datetime          = DateTime.Now.Date;
            var financialAnalysis = new FinancialAnalysisBuilder()
                                    .SetClosingPrice(1)
                                    .SetEPS(2.7m)
                                    .SetMonthsInReport(6)
                                    .Build();

            var financialReport = new FinancialReportBuilder()
                                  .SetEPS(3.8m)
                                  .SetMonthsInReport(3)
                                  .SetNextReportDate(datetime)
                                  .Build();

            var result = new RegistryEntryBuilder()
                         .SetIsin(isin)
                         .SetName(name)
                         .SetOwnInvestorLink(ownInvestorLink)
                         .SetStockExchangeLink(stockExchangeLink)
                         .SetPosition(position)
                         .SetFinancialAnalysis(financialAnalysis)
                         .SetFinancialReport(financialReport)
                         .Build();

            result.Should().NotBeNull();
            result.Isin.Should().Be(isin);
            result.Name.Should().Be(name);
            result.OwnInvestorLink.Should().Be(ownInvestorLink);
            result.StockExchangeLink.Should().Be(stockExchangeLink);
            result.Position.Should().Be(Position.NoPosition);
            result.FinancialAnalysis.Should().Be(financialAnalysis);
            result.FinancialReport.Should().Be(financialReport);
        }
Esempio n. 3
0
        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);
            }
        }