예제 #1
0
        public void GetHolidaysByYearTest()
        {
            var res = UsHolidays.GetHolidaysByYear(2020);

            foreach (var h in res)
            {
                if (h.Name == UsHolidays.Easter)
                {
                    Assert.AreEqual(new DateTime(2020, 04, 12), h.Date);
                }
            }
        }
예제 #2
0
        internal bool IsComplete()
        {
            if (!this.Complete || this.History.Count == 0)
            {
                return(false);
            }

            int      missing  = 0; // in the last 3 months
            var      holidays = new UsHolidays();
            DateTime workDay  = holidays.GetPreviousWorkDay(DateTime.Today.AddDays(1));
            DateTime stopDate = workDay.AddMonths(-3);
            int      count    = 0; // work days

            for (int i = this.History.Count - 1; i >= 0; i--)
            {
                count++;
                StockQuote quote = this.History[i];
                DateTime   date  = quote.Date.Date;
                if (date > workDay)
                {
                    continue; // might have duplicates?
                }
                if (workDay < stopDate)
                {
                    break;
                }
                if (date < workDay)
                {
                    if (!knownClosures.Contains(workDay))
                    {
                        missing++;
                    }
                    i++;
                }
                workDay = holidays.GetPreviousWorkDay(workDay);
            }
            // There are some random stock market closures which we can't keep track of easily, so
            // make sure we are not missing more than 1% of the history.
            return(missing < count * 0.01);
        }