示例#1
0
        public void AppliesSplitAndDividendAtSameTime()
        {
            var reference     = new DateTime(2018, 08, 01);
            var exchangeHours = MarketHoursDatabase.FromDataFolder().GetExchangeHours(QuantConnect.Market.USA, Symbols.SPY, SecurityType.Equity);
            var expected      = GetTestFactorFile("AAPL", reference);

            // remove the last entry that contains a split and dividend at the same time
            var factorFile = new FactorFile("AAPL", expected.SortedFactorFileData.Where(kvp => kvp.Value.PriceFactor >= .8m).Select(kvp => kvp.Value));
            var actual     = factorFile.Apply(new List <BaseData>
            {
                new Split(Symbols.SPY, reference.AddDays(-364), 100m, 1 / 2m, SplitType.SplitOccurred),
                new Dividend(Symbols.SPY, reference.AddDays(-364), 12.5m, 100m)
            }, exchangeHours);

            foreach (var item in actual.Reverse().Zip(expected.Reverse(), (a, e) => new { actual = a, expected = e }))
            {
                Console.WriteLine($"expected: {item.expected} actual: {item.actual}  diff: {100 * (1 - item.actual.PriceFactor / item.expected.PriceFactor):0.0000}%");
                Assert.AreEqual(item.expected.Date, item.actual.Date);
                Assert.AreEqual(item.expected.ReferencePrice, item.actual.ReferencePrice);
                Assert.AreEqual(item.expected.SplitFactor, item.actual.SplitFactor);

                Assert.AreEqual(item.expected.PriceFactor.RoundToSignificantDigits(4), item.actual.PriceFactor.RoundToSignificantDigits(4));
            }
        }