IReadOnlyDictionary <CurrencyCode, SumState> CalculateAssetSums( AssetISIN isin, IReadOnlyCollection <VirtualAsset> allAssets, DateTimeOffset date) { var assets = allAssets .Where(a => a.Isin == isin) .ToArray(); if (assets.Length == 0) { return(new Dictionary <CurrencyCode, SumState>()); } var baseCurrency = assets[0].Currency; var baseRealSum = assets.Sum(a => a.RealSum); var baseVirtualSum = assets.Sum(a => a.VirtualSum); return(_currencyConfig.GetAll() .ToDictionary( c => c, c => { if (c == baseCurrency) { return new SumState(baseRealSum, baseVirtualSum); } var realSum = _exchangeManager.Exchange(baseCurrency, c, baseRealSum, date); var virtualSum = _exchangeManager.Exchange(baseCurrency, c, baseRealSum, date); return new SumState(realSum, virtualSum); } )); }