Ejemplo n.º 1
0
        public ImmutableList <RateAccrualPeriod> createAccrualPeriods(Schedule accrualSchedule, Schedule paymentSchedule, ReferenceData refData)
        {
            // avoid null stub definitions if there are stubs
            FixedRateStubCalculation  initialStub         = firstNonNull(this.initialStub, FixedRateStubCalculation.NONE);
            FixedRateStubCalculation  finalStub           = firstNonNull(this.finalStub, FixedRateStubCalculation.NONE);
            Optional <SchedulePeriod> scheduleInitialStub = accrualSchedule.InitialStub;
            Optional <SchedulePeriod> scheduleFinalStub   = accrualSchedule.FinalStub;
            // resolve data by schedule
            DoubleArray resolvedRates = rate.resolveValues(accrualSchedule);

            // build accrual periods
            ImmutableList.Builder <RateAccrualPeriod> accrualPeriods = ImmutableList.builder();
            for (int i = 0; i < accrualSchedule.size(); i++)
            {
                SchedulePeriod period       = accrualSchedule.getPeriod(i);
                double         yearFraction = period.yearFraction(dayCount, accrualSchedule);
                // handle stubs
                RateComputation rateComputation;
                if (scheduleInitialStub.Present && scheduleInitialStub.get() == period)
                {
                    rateComputation = initialStub.createRateComputation(resolvedRates.get(i));
                }
                else if (scheduleFinalStub.Present && scheduleFinalStub.get() == period)
                {
                    rateComputation = finalStub.createRateComputation(resolvedRates.get(i));
                }
                else
                {
                    rateComputation = FixedRateComputation.of(resolvedRates.get(i));
                }
                accrualPeriods.add(new RateAccrualPeriod(period, yearFraction, rateComputation));
            }
            return(accrualPeriods.build());
        }
Ejemplo n.º 2
0
        public virtual void test_rate_FixedRateComputation()
        {
            FixedRateComputation         ro   = FixedRateComputation.of(0.0123d);
            DispatchingRateComputationFn test = DispatchingRateComputationFn.DEFAULT;

            assertEquals(test.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV), 0.0123d, 0d);
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------------
        public virtual void test_explainRate_FixedRateComputation()
        {
            FixedRateComputation         ro      = FixedRateComputation.of(0.0123d);
            DispatchingRateComputationFn test    = DispatchingRateComputationFn.DEFAULT;
            ExplainMapBuilder            builder = ExplainMap.builder();

            assertEquals(test.explainRate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, builder), 0.0123d, 0d);
            ExplainMap built = builder.build();

            assertEquals(built.get(ExplainKey.FIXED_RATE), 0.0123d);
            assertEquals(built.get(ExplainKey.COMBINED_RATE), 0.0123d);
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates the {@code RateComputation} for the stub.
 /// </summary>
 /// <param name="defaultRate">  the default fixed rate </param>
 /// <returns> the rate computation </returns>
 internal RateComputation createRateComputation(double defaultRate)
 {
     if (FixedRate)
     {
         return(FixedRateComputation.of(fixedRate.Value));
     }
     else if (KnownAmount)
     {
         return(KnownAmountRateComputation.of(knownAmount));
     }
     else
     {
         return(FixedRateComputation.of(defaultRate));
     }
 }
Ejemplo n.º 5
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            DispatchingRateComputationFn            test               = new DispatchingRateComputationFn(MOCK_IBOR_EMPTY, MOCK_IBOR_INT_EMPTY, MOCK_IBOR_AVE_EMPTY, MOCK_ON_CPD_EMPTY, MOCK_ON_AVE_EMPTY, MOCK_ON_AVE_DLY_EMPTY, MOCK_INF_MON_EMPTY, MOCK_INF_INT_EMPTY, MOCK_INF_BOND_MON_EMPTY, MOCK_INF_BOND_INT_EMPTY);
            FixedRateComputation                    @fixed             = FixedRateComputation.of(0.0123d);
            IborRateComputation                     ibor               = IborRateComputation.of(GBP_LIBOR_3M, FIXING_DATE, REF_DATA);
            IborInterpolatedRateComputation         iborInt            = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA);
            IborAveragedRateComputation             iborAvg            = IborAveragedRateComputation.of(ImmutableList.of(IborAveragedFixing.of(ibor.Observation)));
            OvernightCompoundedRateComputation      onCpd              = OvernightCompoundedRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, 0, REF_DATA);
            OvernightAveragedRateComputation        onAvg              = OvernightAveragedRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, 0, REF_DATA);
            OvernightAveragedDailyRateComputation   onAvgDly           = OvernightAveragedDailyRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, REF_DATA);
            InflationMonthlyRateComputation         inflationMonthly   = InflationMonthlyRateComputation.of(US_CPI_U, ACCRUAL_START_MONTH, ACCRUAL_END_MONTH);
            InflationInterpolatedRateComputation    inflationInterp    = InflationInterpolatedRateComputation.of(US_CPI_U, ACCRUAL_START_MONTH, ACCRUAL_END_MONTH, 0.3);
            InflationEndMonthRateComputation        inflationEndMonth  = InflationEndMonthRateComputation.of(US_CPI_U, 234d, ACCRUAL_END_MONTH);
            InflationEndInterpolatedRateComputation inflationEndInterp = InflationEndInterpolatedRateComputation.of(US_CPI_U, 1234d, ACCRUAL_END_MONTH, 0.3);

            RateComputation mock = mock(typeof(RateComputation));

            ignoreThrows(() => test.rateSensitivity(@fixed, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(ibor, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(iborInt, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(iborAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(onCpd, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(onAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(onAvgDly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(inflationMonthly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(inflationInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(inflationEndMonth, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(inflationEndInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));
            ignoreThrows(() => test.rateSensitivity(mock, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV));

            ExplainMapBuilder explain = ExplainMap.builder();

            ignoreThrows(() => test.explainRate(@fixed, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(ibor, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(iborInt, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(iborAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(onCpd, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(onAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(onAvgDly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(inflationMonthly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(inflationInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(inflationEndMonth, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(inflationEndInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
            ignoreThrows(() => test.explainRate(mock, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain));
        }
Ejemplo n.º 6
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates the {@code RateComputation} for the stub.
 /// </summary>
 /// <param name="fixingDate">  the fixing date </param>
 /// <param name="defaultIndex">  the default index to use if the stub has no rules </param>
 /// <param name="refData">  the reference data </param>
 /// <returns> the rate observation </returns>
 internal RateComputation createRateComputation(LocalDate fixingDate, IborIndex defaultIndex, ReferenceData refData)
 {
     if (Interpolated)
     {
         return(IborInterpolatedRateComputation.of(index, indexInterpolated, fixingDate, refData));
     }
     else if (FloatingRate)
     {
         return(IborRateComputation.of(index, fixingDate, refData));
     }
     else if (FixedRate)
     {
         return(FixedRateComputation.of(fixedRate.Value));
     }
     else if (KnownAmount)
     {
         return(KnownAmountRateComputation.of(knownAmount));
     }
     else
     {
         return(IborRateComputation.of(defaultIndex, fixingDate, refData));
     }
 }
Ejemplo n.º 7
0
        public virtual void test_resolve_unadjustedAccrualAdjustedPayment()
        {
            Swap test                  = Swap.builder().legs(RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(date(2016, 1, 3)).endDate(date(2016, 5, 3)).frequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, SAT_SUN)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, SAT_SUN)).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL)).calculation(FixedRateCalculation.of(RATE, ACT_360)).build()).build();
            RatePaymentPeriod pp1      = RatePaymentPeriod.builder().paymentDate(date(2016, 2, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 1, 3)).unadjustedStartDate(date(2016, 1, 3)).endDate(date(2016, 2, 3)).unadjustedEndDate(date(2016, 2, 3)).yearFraction(ACT_360.yearFraction(date(2016, 1, 3), date(2016, 2, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp2      = RatePaymentPeriod.builder().paymentDate(date(2016, 3, 7)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 2, 3)).unadjustedStartDate(date(2016, 2, 3)).endDate(date(2016, 3, 3)).unadjustedEndDate(date(2016, 3, 3)).yearFraction(ACT_360.yearFraction(date(2016, 2, 3), date(2016, 3, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp3      = RatePaymentPeriod.builder().paymentDate(date(2016, 4, 6)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 3, 3)).unadjustedStartDate(date(2016, 3, 3)).endDate(date(2016, 4, 3)).unadjustedEndDate(date(2016, 4, 3)).yearFraction(ACT_360.yearFraction(date(2016, 3, 3), date(2016, 4, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp4      = RatePaymentPeriod.builder().paymentDate(date(2016, 5, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 4, 3)).unadjustedStartDate(date(2016, 4, 3)).endDate(date(2016, 5, 3)).unadjustedEndDate(date(2016, 5, 3)).yearFraction(ACT_360.yearFraction(date(2016, 4, 3), date(2016, 5, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            ResolvedSwap      expected = ResolvedSwap.builder().legs(ResolvedSwapLeg.builder().paymentPeriods(pp1, pp2, pp3, pp4).payReceive(RECEIVE).type(FIXED).build()).build();

            assertEqualsBean(test.resolve(REF_DATA), expected);
        }