예제 #1
0
 private void AddItemToBestExchangeRate(CsvFileExchangeRate csvFileExchangeRate, DateTime currentDate)
 {
     _bestExchangeRates.Add(csvFileExchangeRate.Currency,
         new XmlOutputBestExchangeRate
         {
             Country = csvFileExchangeRate.Country,
             Unit = csvFileExchangeRate.Unit,
             Currency = csvFileExchangeRate.Currency,
             MaxForeignExchangeBuyValue = csvFileExchangeRate.ForeignExchangeBuy,
             MinForeignExchangeSellValue = csvFileExchangeRate.ForeignExchangeSell,
             MaxForeignExchangeBuyDate = currentDate,
             MinForeignExchangeSellDate = currentDate
         });
 }
예제 #2
0
        private void CalculateMinSellMaxBuyValues(CsvFileExchangeRate currentCsvFileExchangeRate, DateTime currentDate, string currentCurrency)
        {
            foreach (KeyValuePair<DateTime, List<CsvFileExchangeRate>> dateToExchangeRatePair in _sortedDateToExchangeRateDictionary.SkipWhile(item => currentDate > item.Key))
            {
                foreach (CsvFileExchangeRate innerLoopCsvFileExchangeRate in dateToExchangeRatePair.Value.Where(item => item.Currency == currentCurrency))
                {
                    var originDiff = _bestExchangeRates[currentCurrency].MaxForeignExchangeBuyValue - _bestExchangeRates[currentCurrency].MinForeignExchangeSellValue;
                    var newDiff = innerLoopCsvFileExchangeRate.ForeignExchangeBuy - currentCsvFileExchangeRate.ForeignExchangeSell;

                    if (newDiff > originDiff)
                    {
                        _bestExchangeRates[currentCurrency].MinForeignExchangeSellValue = currentCsvFileExchangeRate.ForeignExchangeSell;
                        _bestExchangeRates[currentCurrency].MinForeignExchangeSellDate = currentDate;

                        _bestExchangeRates[currentCurrency].MaxForeignExchangeBuyValue = innerLoopCsvFileExchangeRate.ForeignExchangeBuy;
                        _bestExchangeRates[currentCurrency].MaxForeignExchangeBuyDate = dateToExchangeRatePair.Key;
                    }
                }
            }
        }
예제 #3
0
        private void ProcessItem(CsvFileExchangeRate currentCsvFileExchangeRate, DateTime currentDate)
        {
            var currentCurrency = currentCsvFileExchangeRate.Currency;

            if (!_bestExchangeRates.ContainsKey(currentCurrency))
            {
                AddItemToBestExchangeRate(currentCsvFileExchangeRate, currentDate);
                CalculateMinSellMaxBuyValues(currentCsvFileExchangeRate, currentDate, currentCurrency);

                return;
            }

            if (currentCsvFileExchangeRate.ForeignExchangeSell < _bestExchangeRates[currentCurrency].MinForeignExchangeSellValue)
            {
                CalculateMinSellMaxBuyValues(currentCsvFileExchangeRate, currentDate, currentCurrency);
            }
        }