public virtual void test_SAT_SUN_shift()
        {
            ImmutableHolidayCalendar equivalent = ImmutableHolidayCalendar.of(HolidayCalendarId.of("TEST-SAT-SUN"), ImmutableList.of(), ImmutableList.of(SATURDAY, SUNDAY));

            assertSatSun(equivalent);
            assertSatSun(HolidayCalendars.SAT_SUN);
        }
Beispiel #2
0
        private static HolidayCalendar parseHolidayCalendar(string calendarName, PropertySet section)
        {
            string            weekendStr = section.value(WEEKEND_KEY);
            ISet <DayOfWeek>  weekends   = parseWeekends(weekendStr);
            IList <LocalDate> holidays   = new List <LocalDate>();

            foreach (string key in section.keys())
            {
                if (key.Equals(WEEKEND_KEY))
                {
                    continue;
                }
                string value = section.value(key);
                if (key.Length == 4)
                {
                    int year = int.Parse(key);
                    ((IList <LocalDate>)holidays).AddRange(parseYearDates(year, value));
                }
                else
                {
                    holidays.Add(LocalDate.parse(key));
                }
            }
            // build result
            return(ImmutableHolidayCalendar.of(HolidayCalendarId.of(calendarName), holidays, weekends));
        }
Beispiel #3
0
        static GlobalHolidayCalendarLookup()
        {
            ImmutableMap.Builder <string, HolidayCalendar> builder = ImmutableMap.builder();
            ResourceLocator locator = ResourceLocator.ofClasspath("com/opengamma/strata/basics/date/GlobalHolidayCalendars.bin");

            try
            {
                using (Stream fis = locator.ByteSource.openStream())
                {
                    using (DataInputStream @in = new DataInputStream(fis))
                    {
                        if (@in.readByte() != 'H' || @in.readByte() != 'C' || @in.readByte() != 'a' || @in.readByte() != 'l')
                        {
                            Console.Error.WriteLine("ERROR: Corrupt holiday calendar data file");
                        }
                        else
                        {
                            short calSize = @in.readShort();
                            for (int i = 0; i < calSize; i++)
                            {
                                HolidayCalendar cal = ImmutableHolidayCalendar.readExternal(@in);
                                builder.put(cal.Id.Name, cal);
                            }
                        }
                    }
                }
            }
            catch (IOException ex)
            {
                Console.Error.WriteLine("ERROR: Unable to parse holiday calendar data file: " + ex.Message);
                Console.WriteLine(ex.ToString());
                Console.Write(ex.StackTrace);
            }
            MAP = builder.build();
        }
Beispiel #4
0
        // split out for hotspot inlining
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private <T> T tryDefaultValue(com.opengamma.strata.basics.ReferenceDataId<T> id)
        private T tryDefaultValue <T>(ReferenceDataId <T> id)
        {
            if (id is HolidayCalendarId)
            {
                return((T)ImmutableHolidayCalendar.of((HolidayCalendarId)id, ImmutableList.of(), WEEKEND_DAYS));
            }
            return(null);
        }
        public virtual void test_nearest()
        {
            HolidayCalendar cal = ImmutableHolidayCalendar.of(HolidayCalendarId.of("Test"), ImmutableList.of(MON_2014_07_14), SATURDAY, SUNDAY);

            assertEquals(NEAREST.adjust(FRI_2014_07_11, cal), FRI_2014_07_11);
            assertEquals(NEAREST.adjust(SAT_2014_07_12, cal), FRI_2014_07_11);
            assertEquals(NEAREST.adjust(SUN_2014_07_13, cal), TUE_2014_07_15);
            assertEquals(NEAREST.adjust(MON_2014_07_14, cal), TUE_2014_07_15);
        }
        public virtual void test_ofBusinessDays3_adjust()
        {
            ImmutableHolidayCalendar cal     = ImmutableHolidayCalendar.of(WED_THU, ImmutableList.of(), WEDNESDAY, THURSDAY);
            ReferenceData            refData = ImmutableReferenceData.of(ImmutableMap.of(WED_THU, cal)).combinedWith(REF_DATA);
            DaysAdjustment           test    = DaysAdjustment.ofBusinessDays(3, SAT_SUN, BDA_FOLLOW_WED_THU);
            LocalDate @base = date(2014, 8, 15);                                  // Fri

            assertEquals(test.adjust(@base, refData), date(2014, 8, 22));         // Fri (3 days gives Wed, following moves to Fri)
            assertEquals(test.resolve(refData).adjust(@base), date(2014, 8, 22)); // Fri (3 days gives Wed, following moves to Fri)
        }
        /// <summary>
        /// Obtains a combined holiday calendar instance.
        /// <para>
        /// This combines the two input calendars.
        /// It is intended for up-front occasional use rather than continuous use, as it can be relatively slow.
        ///
        /// </para>
        /// </summary>
        /// <param name="cal1">  the first calendar </param>
        /// <param name="cal2">  the second calendar </param>
        /// <returns> the combined calendar </returns>
        public static ImmutableHolidayCalendar combined(ImmutableHolidayCalendar cal1, ImmutableHolidayCalendar cal2)
        {
            // do not override combinedWith(), as this is too slow
            if (cal1 == cal2)
            {
                return(ArgChecker.notNull(cal1, "cal1"));
            }
            HolidayCalendarId newId = cal1.id.combinedWith(cal2.id);

            // use slow version if lookup arrays do not overlap
            int endYear1 = cal1.startYear + cal1.lookup.Length / 12;
            int endYear2 = cal2.startYear + cal2.lookup.Length / 12;

            if (endYear1 < cal2.startYear || endYear2 < cal1.startYear)
            {
                ImmutableSortedSet <LocalDate> newHolidays = ImmutableSortedSet.copyOf(Iterables.concat(cal1.Holidays, cal2.Holidays));
                ImmutableSet <DayOfWeek>       newWeekends = ImmutableSet.copyOf(Iterables.concat(cal1.WeekendDays, cal2.WeekendDays));
                return(of(newId, newHolidays, newWeekends));
            }

            // merge calendars using bitwise operations
            // figure out which has the lower start year and use that as the base
            bool cal1Lower = cal1.startYear <= cal2.startYear;

            int[] lookup1        = cal1Lower ? cal1.lookup : cal2.lookup;
            int[] lookup2        = cal1Lower ? cal2.lookup : cal1.lookup;
            int   newStartYear   = cal1Lower ? cal1.startYear : cal2.startYear;
            int   otherStartYear = cal1Lower ? cal2.startYear : cal1.startYear;
            // copy base array and map data from the other on top
            int newSize = Math.Max(lookup1.Length, lookup2.Length + (otherStartYear - newStartYear) * 12);
            int offset  = (otherStartYear - newStartYear) * 12;

            int[] newLookup = Arrays.copyOf(lookup1, newSize);
            for (int i = 0; i < lookup2.Length; i++)
            {
                newLookup[i + offset] &= lookup2[i];         // use & because 1 = business day (not holiday)
            }
            int newWeekends = cal1.weekends | cal2.weekends; // use | because 1 = weekend day

            return(new ImmutableHolidayCalendar(newId, newWeekends, newStartYear, newLookup, false));
        }
        public override object build <T1>(Type beanType, BeanBuilder <T1> builder)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.ConcurrentMap<org.joda.beans.MetaProperty<?>, Object> buffer = ((org.joda.beans.impl.BufferingBeanBuilder<?>) builder).getBuffer();
            ConcurrentMap <MetaProperty <object>, object> buffer = ((BufferingBeanBuilder <object>)builder).Buffer;
            HolidayCalendarId id = builder.get(ID);

            if (buffer.containsKey(HOLIDAYS) && buffer.containsKey(WEEKEND_DAYS))
            {
                ISet <LocalDate> holidays    = builder.get(HOLIDAYS);
                ISet <DayOfWeek> weekendDays = builder.get(WEEKEND_DAYS);
                return(ImmutableHolidayCalendar.of(id, holidays, weekendDays));
            }
            else
            {
                int   weekends  = builder.get(WEEKENDS);
                int   startYear = builder.get(START_YEAR);
                int[] lookup    = builder.get(LOOKUP);
                return(new ImmutableHolidayCalendar(id, weekends, startYear, lookup, false));
            }
        }