예제 #1
0
        public void GetFinalCapital_GivenTwoImplicitThursdays()
        {
            var listDailyStock = new List <DailyStock>
            {
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 23), OpenDay = 3, CloseDay = 2
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 25), OpenDay = 2.5m, CloseDay = 4
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 28), OpenDay = 3, CloseDay = 2
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 6, 27), OpenDay = 1, CloseDay = 7
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 6, 29), OpenDay = 2, CloseDay = 3
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 6, 30), OpenDay = 1, CloseDay = 3
                }
            };

            InvestmentSimulator investmentSimulator = new InvestmentSimulator();
            var result   = investmentSimulator.Calculate(listDailyStock);
            var expected = 220.5m;

            Assert.AreEqual(expected, result);
        }
예제 #2
0
        public void GetFinalCapital_GivenASingleExplicitThursday()
        {
            var listDailyStock = new List <DailyStock>
            {
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 23), OpenDay = 1, CloseDay = 2
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 24), OpenDay = 3, CloseDay = 4
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 25), OpenDay = 5, CloseDay = 6
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 26), OpenDay = 6, CloseDay = 6
                },
                new DailyStock {
                    DateTime = new DateTime(2001, 5, 27), OpenDay = 7, CloseDay = 8
                }
            };

            InvestmentSimulator investmentSimulator = new InvestmentSimulator();
            var result   = investmentSimulator.Calculate(listDailyStock);
            var expected = 0m;

            Assert.AreEqual(expected, result);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var sw = new Stopwatch();

            sw.Start();
            log.Info("Reading data source...");
            IInvestmentSimulator indexSimulator = new InvestmentSimulator();
            IDataSource          dataSource     = new ExcelSource();
            IExporter            exporter       = new ExcelExporter();
            var list = dataSource.ExtractData();

            log.Info("Calculating...");
            var incomeList = indexSimulator.Calculate(list);

            log.Info($"Final Capital: {incomeList.FinalCapital}");
            log.Info($"Total Investment: {incomeList.TotalInvestment}");
            log.Info($"Total Gain: {incomeList.TotalGain}");
            log.Info("Exporting data to Excel...");
            exporter.Export(incomeList, @"ZaraCode.xlsx");
            sw.Stop();
            Console.WriteLine("Time elapsed: {0}", sw.Elapsed.ToString("hh\\:mm\\:ss\\.fff"));
            Console.ReadKey();
        }
        public void TestInvestmentNetProfitAmount(InvestmentParameter parameter, decimal netProfitAmount)
        {
            var actualResult = new InvestmentSimulator().Simulate(parameter);

            Assert.AreEqual(netProfitAmount, actualResult.NetAmountProfit);
        }
        public void TestInvestmentCalculations(InvestmentParameter parameter, InvestmentResult expectedResult)
        {
            var actualResult = new InvestmentSimulator().Simulate(parameter);

            CheckEquality(expectedResult, actualResult);
        }