Beispiel #1
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            IborRateSensitivity test = IborRateSensitivity.of(GBP_LIBOR_3M_OBSERVATION, 32d);

            coverImmutableBean(test);
            IborRateSensitivity test2 = IborRateSensitivity.of(IborIndexObservation.of(USD_LIBOR_3M, DATE2, REF_DATA), USD, 16d);

            coverBeanEquals(test, test2);
        }
        public virtual double rate(IborIndexObservation observation)
        {
            LocalDate fixingDate = observation.FixingDate;

            if (fixingDate.Equals(valuationDate) && fixings.containsDate(fixingDate))
            {
                return(fixings.get(fixingDate).Value);
            }
            return(rates.get(fixingDate).Value);
        }
        //-------------------------------------------------------------------------
        public virtual double rate(IborInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider)
        {
            IborIndexObservation obs1   = computation.ShortObservation;
            IborIndexObservation obs2   = computation.LongObservation;
            IborIndexRates       rates1 = provider.iborIndexRates(obs1.Index);
            IborIndexRates       rates2 = provider.iborIndexRates(obs2.Index);

            double      rate1   = rates1.rate(obs1);
            double      rate2   = rates2.rate(obs2);
            DoublesPair weights = this.weights(obs1, obs2, endDate);

            return(((rate1 * weights.First) + (rate2 * weights.Second)) / (weights.First + weights.Second));
        }
        // computes the weights related to the two indices
        private DoublesPair weights(IborIndexObservation obs1, IborIndexObservation obs2, LocalDate endDate)
        {
            // weights: linear interpolation on the number of days between the fixing date and the maturity dates of the
            //   actual coupons on one side and the maturity dates of the underlying deposit on the other side.
            long   fixingEpochDay = obs1.FixingDate.toEpochDay();
            double days1          = obs1.MaturityDate.toEpochDay() - fixingEpochDay;
            double days2          = obs2.MaturityDate.toEpochDay() - fixingEpochDay;
            double daysN          = endDate.toEpochDay() - fixingEpochDay;
            double weight1        = (days2 - daysN) / (days2 - days1);
            double weight2        = (daysN - days1) / (days2 - days1);

            return(DoublesPair.of(weight1, weight2));
        }
Beispiel #5
0
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            IborRateComputation  test     = IborRateComputation.of(USD_LIBOR_3M, date(2016, 2, 18), REF_DATA);
            IborIndexObservation obs      = IborIndexObservation.of(USD_LIBOR_3M, date(2016, 2, 18), REF_DATA);
            IborRateComputation  expected = IborRateComputation.of(obs);

            assertEquals(test, expected);
            assertEquals(test.Currency, USD);
            assertEquals(test.Index, obs.Index);
            assertEquals(test.FixingDate, obs.FixingDate);
            assertEquals(test.EffectiveDate, obs.EffectiveDate);
            assertEquals(test.MaturityDate, obs.MaturityDate);
            assertEquals(test.YearFraction, obs.YearFraction);
        }
        public virtual double explainRate(IborInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider, ExplainMapBuilder builder)
        {
            IborIndexObservation obs1    = computation.ShortObservation;
            IborIndexObservation obs2    = computation.LongObservation;
            DoublesPair          weights = this.weights(obs1, obs2, endDate);
            IborIndexRates       rates1  = provider.iborIndexRates(obs1.Index);
            IborIndexRates       rates2  = provider.iborIndexRates(obs2.Index);

            rates1.explainRate(obs1, builder, child => child.put(ExplainKey.WEIGHT, weights.First));
            rates2.explainRate(obs2, builder, child => child.put(ExplainKey.WEIGHT, weights.Second));
            double rate = this.rate(computation, startDate, endDate, provider);

            builder.put(ExplainKey.COMBINED_RATE, rate);
            return(rate);
        }
        public virtual PointSensitivityBuilder rateSensitivity(IborInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider)
        {
            // computes the dates related to the underlying deposits associated to the indices
            IborIndexObservation obs1    = computation.ShortObservation;
            IborIndexObservation obs2    = computation.LongObservation;
            DoublesPair          weights = this.weights(obs1, obs2, endDate);
            double totalWeight           = weights.First + weights.Second;

            IborIndexRates          ratesIndex1 = provider.iborIndexRates(obs1.Index);
            PointSensitivityBuilder sens1       = ratesIndex1.ratePointSensitivity(obs1).multipliedBy(weights.First / totalWeight);
            IborIndexRates          ratesIndex2 = provider.iborIndexRates(obs2.Index);
            PointSensitivityBuilder sens2       = ratesIndex2.ratePointSensitivity(obs2).multipliedBy(weights.Second / totalWeight);

            return(sens1.combinedWith(sens2));
        }
        public virtual void test_expand_initialStubAndResetPeriods_weighted_firstFixed()
        {
            IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_360).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).resetPeriods(ResetSchedule.builder().resetFrequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).resetMethod(WEIGHTED).build()).firstRegularRate(0.028d).initialStub(IborRateStubCalculation.ofFixedRate(0.030d)).build();

            SchedulePeriod accrual1 = SchedulePeriod.of(DATE_02_05, DATE_04_07, DATE_02_05, DATE_04_05);
            SchedulePeriod accrual2 = SchedulePeriod.of(DATE_04_07, DATE_07_07, DATE_04_05, DATE_07_05);
            Schedule       schedule = Schedule.builder().periods(accrual1, accrual2).frequency(P3M).rollConvention(DAY_5).build();

            RateAccrualPeriod    rap1 = RateAccrualPeriod.builder(accrual1).yearFraction(accrual1.yearFraction(ACT_360, schedule)).rateComputation(FixedRateComputation.of(0.030d)).build();
            IborIndexObservation obs4 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_04_03, REF_DATA);
            IborIndexObservation obs5 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_05_01, REF_DATA);
            IborIndexObservation obs6 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_06_03, REF_DATA);
            ImmutableList <IborAveragedFixing> fixings2 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs4, DATE_04_07, DATE_05_06, 0.028d), IborAveragedFixing.ofDaysInResetPeriod(obs5, DATE_05_06, DATE_06_05), IborAveragedFixing.ofDaysInResetPeriod(obs6, DATE_06_05, DATE_07_07));
            RateAccrualPeriod rap2 = RateAccrualPeriod.builder(accrual2).yearFraction(accrual2.yearFraction(ACT_360, schedule)).rateComputation(IborAveragedRateComputation.of(fixings2)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2));
        }
Beispiel #9
0
        //-------------------------------------------------------------------------
        public virtual void test_compareKey()
        {
            CreditCurveZeroRateSensitivity a1    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity a2    = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity b     = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, GBP, 10d, 32d);
            CreditCurveZeroRateSensitivity c     = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, 32d);
            CreditCurveZeroRateSensitivity d     = CreditCurveZeroRateSensitivity.of(LEGAL_ENTITY, USD, YEAR_FRACTION, GBP, 32d);
            IborRateSensitivity            other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2014, 6, 30), REF_DATA), 32d);

            assertEquals(a1.compareKey(a2), 0);
            assertEquals(a1.compareKey(b) < 0, true);
            assertEquals(b.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(c) < 0, true);
            assertEquals(a1.compareKey(d) < 0, true);
            assertEquals(c.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) < 0, true);
            assertEquals(other.compareKey(a1) > 0, true);
        }
        public virtual void test_compareKey()
        {
            IssuerCurveZeroRateSensitivity a1    = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity a2    = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity b     = IssuerCurveZeroRateSensitivity.of(GBP, YEARFRAC, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity c     = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC2, GROUP, VALUE);
            IssuerCurveZeroRateSensitivity d     = IssuerCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, LegalEntityGroup.of("ISSUER2"), VALUE);
            IborRateSensitivity            other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2015, 8, 27), REF_DATA), 32d);

            assertEquals(a1.compareKey(a2), 0);
            assertEquals(a1.compareKey(b) > 0, true);
            assertEquals(b.compareKey(a1) < 0, true);
            assertEquals(a1.compareKey(c) < 0, true);
            assertEquals(c.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(d) < 0, true);
            assertEquals(d.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) > 0, true);
            assertEquals(other.compareKey(a1) < 0, true);
        }
Beispiel #11
0
        public virtual void test_compareKey()
        {
            RepoCurveZeroRateSensitivity a1    = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity a2    = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity b     = RepoCurveZeroRateSensitivity.of(GBP, YEARFRAC, GROUP, VALUE);
            RepoCurveZeroRateSensitivity c     = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC2, GROUP, VALUE);
            RepoCurveZeroRateSensitivity d     = RepoCurveZeroRateSensitivity.of(CURRENCY, YEARFRAC, RepoGroup.of("ISSUER1 BND 3Y"), VALUE);
            IborRateSensitivity          other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2014, 6, 30), REF_DATA), 32d);

            assertEquals(a1.compareKey(a2), 0);
            assertEquals(a1.compareKey(b) > 0, true);
            assertEquals(b.compareKey(a1) < 0, true);
            assertEquals(a1.compareKey(c) < 0, true);
            assertEquals(c.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(d) < 0, true);
            assertEquals(d.compareKey(a1) > 0, true);
            assertEquals(a1.compareKey(other) > 0, true);
            assertEquals(other.compareKey(a1) < 0, true);
        }
        public virtual void test_expand_resetPeriods_weighted_firstFixingDateOffset()
        {
            // only the fixing date of the first reset period is changed, everything else stays the same
            IborRateCalculation test = IborRateCalculation.builder().dayCount(ACT_365F).index(GBP_LIBOR_3M).fixingDateOffset(MINUS_TWO_DAYS).resetPeriods(ResetSchedule.builder().resetFrequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).resetMethod(WEIGHTED).build()).firstFixingDateOffset(MINUS_ONE_DAY).build();

            SchedulePeriod accrual1 = SchedulePeriod.of(DATE_01_06, DATE_04_07, DATE_01_05, DATE_04_05);
            SchedulePeriod accrual2 = SchedulePeriod.of(DATE_04_07, DATE_07_07, DATE_04_05, DATE_07_05);
            Schedule       schedule = Schedule.builder().periods(accrual1, accrual2).frequency(P3M).rollConvention(DAY_5).build();

            IborIndexObservation obs1 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_01_03, REF_DATA);
            IborIndexObservation obs2 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_02_03, REF_DATA);
            IborIndexObservation obs3 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_03_03, REF_DATA);
            ImmutableList <IborAveragedFixing> fixings1 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs1, DATE_01_06, DATE_02_05), IborAveragedFixing.ofDaysInResetPeriod(obs2, DATE_02_05, DATE_03_05), IborAveragedFixing.ofDaysInResetPeriod(obs3, DATE_03_05, DATE_04_07));
            RateAccrualPeriod rap1 = RateAccrualPeriod.builder(accrual1).yearFraction(accrual1.yearFraction(ACT_365F, schedule)).rateComputation(IborAveragedRateComputation.of(fixings1)).build();

            IborIndexObservation obs4 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_04_03, REF_DATA);
            IborIndexObservation obs5 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_05_01, REF_DATA);
            IborIndexObservation obs6 = IborIndexObservation.of(GBP_LIBOR_3M, DATE_06_03, REF_DATA);
            ImmutableList <IborAveragedFixing> fixings2 = ImmutableList.of(IborAveragedFixing.ofDaysInResetPeriod(obs4, DATE_04_07, DATE_05_06), IborAveragedFixing.ofDaysInResetPeriod(obs5, DATE_05_06, DATE_06_05), IborAveragedFixing.ofDaysInResetPeriod(obs6, DATE_06_05, DATE_07_07));
            RateAccrualPeriod rap2 = RateAccrualPeriod.builder(accrual2).yearFraction(accrual2.yearFraction(ACT_365F, schedule)).rateComputation(IborAveragedRateComputation.of(fixings2)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(schedule, schedule, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2));
        }
 public virtual PointSensitivityBuilder ratePointSensitivity(IborIndexObservation observation)
 {
     return(sens);
 }
 public virtual PointSensitivityBuilder rateIgnoringFixingsPointSensitivity(IborIndexObservation observation)
 {
     throw new System.NotSupportedException();
 }
 public virtual double rateIgnoringFixings(IborIndexObservation observation)
 {
     throw new System.NotSupportedException();
 }