Example #1
0
        //-------------------------------------------------------------------------
        public virtual void test_adjustDate()
        {
            Payment test     = Payment.ofReceive(GBP_P1000, DATE_2015_06_29);
            Payment expected = Payment.of(GBP_P1000, DATE_2015_06_29.plusDays(1));

            assertEquals(test.adjustDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(1))), expected);
        }
Example #2
0
        public virtual void test_of()
        {
            FixedCouponBondPaymentPeriod test = FixedCouponBondPaymentPeriod.builder().currency(USD).startDate(START_ADJUSTED).unadjustedStartDate(START).endDate(END_ADJUSTED).unadjustedEndDate(END).detachmentDate(DETACHMENT_DATE).notional(NOTIONAL).fixedRate(FIXED_RATE).yearFraction(YEAR_FRACTION).build();

            assertEquals(test.Currency, USD);
            assertEquals(test.UnadjustedStartDate, START);
            assertEquals(test.StartDate, START_ADJUSTED);
            assertEquals(test.UnadjustedEndDate, END);
            assertEquals(test.EndDate, END_ADJUSTED);
            assertEquals(test.PaymentDate, END_ADJUSTED);
            assertEquals(test.DetachmentDate, DETACHMENT_DATE);
            assertEquals(test.FixedRate, FIXED_RATE);
            assertEquals(test.Notional, NOTIONAL);
            assertEquals(test.YearFraction, YEAR_FRACTION);
            assertEquals(test.hasExCouponPeriod(), true);

            // the object is not changed
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), test);
            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(test.Currency, USD);
            assertEquals(test.UnadjustedStartDate, START);
            assertEquals(test.StartDate, START_ADJUSTED);
            assertEquals(test.UnadjustedEndDate, END);
            assertEquals(test.EndDate, END_ADJUSTED);
            assertEquals(test.PaymentDate, END_ADJUSTED);
            assertEquals(test.DetachmentDate, DETACHMENT_DATE);
            assertEquals(test.FixedRate, FIXED_RATE);
            assertEquals(test.Notional, NOTIONAL);
            assertEquals(test.YearFraction, YEAR_FRACTION);
            assertEquals(test.hasExCouponPeriod(), true);
        }
        //-------------------------------------------------------------------------
        public virtual void test_adjustPaymentDate()
        {
            KnownAmountSwapPaymentPeriod test     = KnownAmountSwapPaymentPeriod.builder().payment(PAYMENT_2014_10_01).startDate(DATE_2014_03_30).unadjustedStartDate(DATE_2014_03_30).endDate(DATE_2014_10_01).unadjustedEndDate(DATE_2014_09_30).build();
            KnownAmountSwapPaymentPeriod expected = KnownAmountSwapPaymentPeriod.builder().payment(PAYMENT_2014_10_03).startDate(DATE_2014_03_30).unadjustedStartDate(DATE_2014_03_30).endDate(DATE_2014_10_01).unadjustedEndDate(DATE_2014_09_30).build();

            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(0))), test);
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), expected);
        }
Example #4
0
        //-------------------------------------------------------------------------
        public virtual void test_adjustPaymentDate()
        {
            FxResetNotionalExchange test     = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA));
            FxResetNotionalExchange expected = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30.plusDays(2), FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA));

            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(0))), test);
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), expected);
        }
Example #5
0
        //-------------------------------------------------------------------------
        public virtual void test_adjustPaymentDate()
        {
            RatePaymentPeriod test     = RatePaymentPeriod.builder().paymentDate(DATE_2014_10_01).accrualPeriods(RAP2).dayCount(ACT_365F).currency(GBP).notional(1000d).compoundingMethod(CompoundingMethod.STRAIGHT).build();
            RatePaymentPeriod expected = RatePaymentPeriod.builder().paymentDate(DATE_2014_10_01.plusDays(2)).accrualPeriods(RAP2).dayCount(ACT_365F).currency(GBP).notional(1000d).compoundingMethod(CompoundingMethod.STRAIGHT).build();

            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(0))), test);
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), expected);
        }
        //-------------------------------------------------------------------------
        public virtual void test_adjustPaymentDate()
        {
            NotionalExchange test     = NotionalExchange.of(GBP_1000, DATE_2014_06_30);
            NotionalExchange expected = NotionalExchange.of(GBP_1000, DATE_2014_06_30.plusDays(2));

            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(0))), test);
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), expected);
        }
Example #7
0
            public override LocalDate previous(LocalDate date, Frequency periodicFrequency)
            {
                ArgChecker.notNull(date, "date");
                ArgChecker.notNull(periodicFrequency, "periodicFrequency");
                LocalDate calculated = date.minus(periodicFrequency);

                return(calculated.with(TemporalAdjusters.previousOrSame(day)));
            }
        public virtual void test_methods()
        {
            CapitalIndexedBondPaymentPeriod test = CapitalIndexedBondPaymentPeriod.builder().currency(USD).notional(NOTIONAL).detachmentDate(DETACHMENT).startDate(START).endDate(END).unadjustedStartDate(START_UNADJ).unadjustedEndDate(END_UNADJ).rateComputation(COMPUTE_INTERP).realCoupon(REAL_COUPON).build();

            assertEquals(test.PaymentDate, END);
            assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), test);
            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            ImmutableSet <Index> set = builder.build();

            assertEquals(set.size(), 1);
            assertEquals(set.asList().get(0), US_CPI_U);

            LocalDate bondStart      = LocalDate.of(2003, 1, 13);
            LocalDate bondStartUnadj = LocalDate.of(2003, 1, 12);
            CapitalIndexedBondPaymentPeriod expected = CapitalIndexedBondPaymentPeriod.builder().currency(USD).notional(NOTIONAL).detachmentDate(END).startDate(bondStart).endDate(END).unadjustedStartDate(bondStartUnadj).unadjustedEndDate(END_UNADJ).rateComputation(COMPUTE_INTERP).realCoupon(1d).build();

            assertEquals(test.withUnitCoupon(bondStart, bondStartUnadj), expected);
        }
Example #9
0
 internal static LocalDate TruncateTo(LocalDate value, TemporalUnit unit)
 {
     if (unit == ChronoUnit.MILLENNIA)
     {
         return(value.with(Neo4JTemporalField.YearOfMillennium, 0));
     }
     else if (unit == ChronoUnit.CENTURIES)
     {
         return(value.with(Neo4JTemporalField.YearOfCentury, 0));
     }
     else if (unit == ChronoUnit.DECADES)
     {
         return(value.with(Neo4JTemporalField.YearOfDecade, 0));
     }
     else if (unit == ChronoUnit.YEARS)
     {
         return(value.with(TemporalAdjusters.firstDayOfYear()));
     }
     else if (unit == IsoFields.WEEK_BASED_YEARS)
     {
         return(value.with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 1).with(ChronoField.DAY_OF_WEEK, 1));
     }
     else if (unit == IsoFields.QUARTER_YEARS)
     {
         return(value.with(IsoFields.DAY_OF_QUARTER, 1));
     }
     else if (unit == ChronoUnit.MONTHS)
     {
         return(value.with(TemporalAdjusters.firstDayOfMonth()));
     }
     else if (unit == ChronoUnit.WEEKS)
     {
         return(value.with(TemporalAdjusters.previousOrSame(DayOfWeek.Monday)));
     }
     else if (unit == ChronoUnit.DAYS)
     {
         return(value);
     }
     else
     {
         throw new UnsupportedTemporalUnitException("Unit too small for truncation: " + unit);
     }
 }
Example #10
0
        public virtual void test_adjustDate_noChange()
        {
            Payment test = Payment.ofReceive(GBP_P1000, DATE_2015_06_29);

            assertSame(test.adjustDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(1).minusDays(1))), test);
        }
 /// <summary>
 /// Returns the last in month adjuster, which returns a new date
 /// in the same month with the last matching day-of-week.
 /// This is used for expressions like 'last Tuesday in March'.
 /// <para>
 /// The ISO calendar system behaves as follows:<br>
 /// The input 2011-12-15 for (MONDAY) will return 2011-12-26.<br>
 /// The input 2011-12-15 for (FRIDAY) will return 2011-12-30.<br>
 /// </para>
 /// <para>
 /// The behavior is suitable for use with most calendar systems.
 /// It uses the {@code DAY_OF_WEEK} and {@code DAY_OF_MONTH} fields
 /// and the {@code DAYS} unit, and assumes a seven day week.
 ///
 /// </para>
 /// </summary>
 /// <param name="dayOfWeek">  the day-of-week, not null </param>
 /// <returns> the first in month adjuster, not null </returns>
 public static TemporalAdjuster LastInMonth(DayOfWeek dayOfWeek)
 {
     return(TemporalAdjusters.DayOfWeekInMonth(-1, dayOfWeek));
 }
Example #12
0
 public virtual void test_ofDayOfWeek_previous_oneDay()
 {
     foreach (DayOfWeek dow in DayOfWeek.values())
     {
         RollConvention test = RollConvention.ofDayOfWeek(dow);
         assertEquals(test.previous(date(2014, AUGUST, 14), P1D), date(2014, AUGUST, 13).with(TemporalAdjusters.previousOrSame(dow)));
     }
 }
Example #13
0
 public virtual void test_ofDayOfWeek_next_oneMonth()
 {
     foreach (DayOfWeek dow in DayOfWeek.values())
     {
         RollConvention test = RollConvention.ofDayOfWeek(dow);
         assertEquals(test.next(date(2014, AUGUST, 14), P1W), date(2014, AUGUST, 21).with(TemporalAdjusters.nextOrSame(dow)));
     }
 }
Example #14
0
 public LocalDate adjust(LocalDate date)
 {
     ArgChecker.notNull(date, "date");
     return(date.with(TemporalAdjusters.nextOrSame(day)));
 }