public ExchangeRatesAnalyzer(IExchangeRatesLoader exchangeRatesLoader, ExchangeRatesReader exchangeRatesReader)
        {
            _exchangeRatesLoader = exchangeRatesLoader;
            _exchangeRatesReader = exchangeRatesReader;

            _bestExchangeRates = new Dictionary<string, XmlOutputBestExchangeRate>();
        }
Esempio n. 2
0
        public ExchangeRatesAnalyzer(IExchangeRatesLoader exchangeRatesLoader, ExchangeRatesReader exchangeRatesReader)
        {
            _exchangeRatesLoader = exchangeRatesLoader;
            _exchangeRatesReader = exchangeRatesReader;

            _bestExchangeRates = new Dictionary <string, XmlOutputBestExchangeRate>();
        }
        public void TestBestExchangeRate()
        {
            var startDate = new DateTime(2014, 9, 26);
            var endDate = new DateTime(2014, 9, 30);

            var fileHelper = new ExchangeRatesFileHelper(startDate, endDate, "../../TestData");
            var exchangeRatesLoader = new FakeExchangeRatesLoader();
            var exchangeRatesReader = new ExchangeRatesReader(fileHelper);
            var exchangeRatesAnalyzer = new ExchangeRatesAnalyzer(exchangeRatesLoader, exchangeRatesReader);

            exchangeRatesAnalyzer.Analyze();

            var bestExchangeRate = exchangeRatesAnalyzer.FindBestExchangeRate();

            Assert.IsNotNull(bestExchangeRate);

            Assert.IsTrue(bestExchangeRate.Currency == "RUB");

            Assert.IsTrue(bestExchangeRate.MinForeignExchangeSellDate == new DateTime(2014, 9, 29));

            Assert.IsTrue(bestExchangeRate.MaxForeignExchangeBuyDate == new DateTime(2014, 9, 30));
        }
Esempio n. 4
0
        private static void Main()
        {
            if (!GetInputData())
            {
                return;
            }

            var fileHelper = new ExchangeRatesFileHelper(_startDate, _endDate, "Downloads");
            var exchangeRatesLoader = new ExchangeRatesLoader(fileHelper);
            var exchangeRatesReader = new ExchangeRatesReader(fileHelper);
            var exchangeRatesAnalyzer = new ExchangeRatesAnalyzer(exchangeRatesLoader, exchangeRatesReader);

            exchangeRatesAnalyzer.Analyze();

            var bestExchangeRate = exchangeRatesAnalyzer.FindBestExchangeRate();

            if (bestExchangeRate != null)
            {
                var remainingCapital = exchangeRatesAnalyzer.CalculateRemainingCapital(bestExchangeRate, _initialCapital);

                var resultingXml = new XElement("Root",
                    new XElement("Currency", bestExchangeRate.Currency),
                    new XElement("BestDayOfBuy", bestExchangeRate.MinForeignExchangeSellDate.ToString(fileHelper.DateFormat, fileHelper.CultureInfo)),
                    new XElement("BestDayOfSell", bestExchangeRate.MaxForeignExchangeBuyDate.ToString(fileHelper.DateFormat, fileHelper.CultureInfo)),
                    new XElement("InitialCapital", _initialCapital),
                    new XElement("RemainingCapital", remainingCapital),
                    new XElement("Profit", remainingCapital - _initialCapital));

                resultingXml.Save(fileHelper.ResultingXmlPath);

                Console.WriteLine("Resulting xml file has been generated to Output folder of the current assembly");
            }
            else
            {
                Console.WriteLine("Too short period to make profit :)");
            }

            Console.ReadKey();
        }