private void EnrichQuotes(List <StockQuote> quotes, DateTime date) { var allQuotesFromPreviousSession = _stockQuoteRepository.GetAllQuotesFromPreviousSession(date).ToHashSet(); foreach (var quote in quotes) { quote.Company = _companyRepository.GetById(quote.Ticker); if (quote.Company == null) { var newCompanyEntity = new Company { Ticker = quote.Ticker }; quote.Company = newCompanyEntity; _companyRepository.Add(newCompanyEntity); _companyRepository.SaveChanges(); } else { quote.PreviousStockQuote = allQuotesFromPreviousSession.SingleOrDefault(x => x.Ticker.Equals(quote.Ticker)); if (quote.PreviousStockQuote != null) { quote.AveragePriceChange = (quote.AveragePrice - quote.PreviousStockQuote.AveragePrice) / quote.PreviousStockQuote.AveragePrice; } else { _logger.LogWarning($"Inconsistent state. {quote.Ticker} is present in database, yet it does not have any record from previous session dated in {allQuotesFromPreviousSession.First().DateParsed.ToShortDateString()}" + $"Add it to blacklist or data fix manually."); } } quote.DateParsed = DateTime.ParseExact(quote.Date.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture); } }
public virtual List <StockQuote> GetSignals(TradingSimulationConfig tradingSimulationConfig, DateTime date) { var allQuotesFromLastSession = StockQuoteRepository.GetAllQuotesFromPreviousSession(date); return(GetTopN(tradingSimulationConfig, allQuotesFromLastSession, date)); }