public Decimal GetVolumeWeightedStockPrice(String stockSymbol, Int32 rangeInMinutes) { try { var trades = tradeRepo.GetRecentTradesBySymbol(stockSymbol, rangeInMinutes); Decimal totalPrice = 0; Int32 totalQuantity = 0; foreach (var trade in trades) { totalPrice += (trade.Price * trade.Quantity); totalQuantity += trade.Quantity; } Decimal volumeWeightedStockPrice = totalPrice / totalQuantity; return(Math.Round(volumeWeightedStockPrice, 2)); } catch (Exception ex) { Logger.LogError(Logging.Events.GET_VOLUME_WEIGHTED_STOCK_PRICE, ex, "Failure calculating volume weighted stock price"); throw new Exception("Failure calculating volume weighted stock price", ex); } }