public virtual void test_accruedYearFraction()
        {
            double           eps             = 1.0e-15;
            ResolvedCdsIndex test            = ResolvedCdsIndex.builder().buySell(BUY).dayCount(ACT_360).cdsIndexId(INDEX_ID).legalEntityIds(LEGAL_ENTITIES).paymentOnDefault(ACCRUED_PREMIUM).protectionStart(BEGINNING).paymentPeriods(PAYMENTS).protectionEndDate(PAYMENTS[PAYMENTS.Count - 1].EffectiveEndDate).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build();
            double           accStart        = test.accruedYearFraction(START_DATE.minusDays(1));
            double           accNextMinusOne = test.accruedYearFraction(START_DATE.plusMonths(3).minusDays(1));
            double           accNext         = test.accruedYearFraction(START_DATE.plusMonths(3));
            double           accNextOne      = test.accruedYearFraction(START_DATE.plusMonths(3).plusDays(1));
            double           accMod          = test.accruedYearFraction(START_DATE.plusYears(1));
            double           accEnd          = test.accruedYearFraction(END_DATE);
            double           accEndOne       = test.accruedYearFraction(END_DATE.plusDays(1));

            assertEquals(accStart, 0d);
            assertEquals(accNext, 0d);
            assertEquals(accNextMinusOne, ACT_360.relativeYearFraction(START_DATE, START_DATE.plusMonths(3).minusDays(1)), eps);
            assertEquals(accNextOne, 1d / 360d, eps);
            // 2.x
            assertEquals(accMod, 0.24722222222222223, eps);
            assertEquals(accEnd, 0.25555555555555554, eps);
            assertEquals(accEndOne, 0.25833333333333336, eps);
        }
示例#2
0
        //-------------------------------------------------------------------------
        // creates a simple provider
        private SimpleRatesProvider createProvider(FxResetNotionalExchange ne)
        {
            LocalDate paymentDate = ne.PaymentDate;
            double    paymentTime = ACT_360.relativeYearFraction(VAL_DATE, paymentDate);
            Currency  currency    = ne.Currency;

            DiscountFactors mockDf = mock(typeof(DiscountFactors));

            when(mockDf.discountFactor(paymentDate)).thenReturn(DISCOUNT_FACTOR);
            ZeroRateSensitivity sens = ZeroRateSensitivity.of(currency, paymentTime, -DISCOUNT_FACTOR * paymentTime);

            when(mockDf.zeroRatePointSensitivity(paymentDate)).thenReturn(sens);
            FxIndexRates mockFxRates = mock(typeof(FxIndexRates));

            when(mockFxRates.rate(ne.Observation, ne.ReferenceCurrency)).thenReturn(FX_RATE);
            SimpleRatesProvider prov = new SimpleRatesProvider(VAL_DATE);

            prov.DiscountFactors = mockDf;
            prov.FxIndexRates    = mockFxRates;
            prov.DayCount        = ACT_360;
            return(prov);
        }
示例#3
0
        public virtual void test_volatilities()
        {
            BlackFxOptionSmileVolatilitiesSpecification @base = BlackFxOptionSmileVolatilitiesSpecification.builder().name(VOL_NAME).currencyPair(EUR_GBP).dayCount(ACT_360).nodes(NODES).timeInterpolator(PCHIP).strikeInterpolator(PCHIP).build();
            LocalDate     date       = LocalDate.of(2017, 9, 25);
            ZonedDateTime dateTime   = date.atStartOfDay().atZone(ZoneId.of("Europe/London"));
            DoubleArray   parameters = DoubleArray.of(0.05, -0.05, 0.15, 0.25, 0.1, -0.1);
            BlackFxOptionSmileVolatilities computed = @base.volatilities(dateTime, parameters, REF_DATA);
            LocalDate               spotDate        = SPOT_OFFSET.adjust(dateTime.toLocalDate(), REF_DATA);
            DaysAdjustment          expOffset       = DaysAdjustment.ofBusinessDays(-2, TA_LO);
            DoubleArray             expiries        = DoubleArray.of(ACT_360.relativeYearFraction(date, expOffset.adjust(BUS_ADJ.adjust(spotDate.plus(Tenor.TENOR_3M), REF_DATA), REF_DATA)), ACT_360.relativeYearFraction(date, expOffset.adjust(BUS_ADJ.adjust(spotDate.plus(Tenor.TENOR_1Y), REF_DATA), REF_DATA)));
            SmileDeltaTermStructure smiles          = InterpolatedStrikeSmileDeltaTermStructure.of(expiries, DoubleArray.of(0.1), DoubleArray.of(0.25, 0.15), DoubleMatrix.ofUnsafe(new double[][]
            {
                new double[] { -0.1 },
                new double[] { -0.05 }
            }), DoubleMatrix.ofUnsafe(new double[][]
            {
                new double[] { 0.1 },
                new double[] { 0.05 }
            }), ACT_360, PCHIP, FLAT, FLAT, PCHIP, FLAT, FLAT);
            BlackFxOptionSmileVolatilities expected = BlackFxOptionSmileVolatilities.of(VOL_NAME, EUR_GBP, dateTime, smiles);

            assertEquals(computed, expected);
        }
        static ResolvedCdsIndexTest()
        {
            int nDates = 44;

            LocalDate[] dates = new LocalDate[nDates];
            for (int i = 0; i < nDates; ++i)
            {
                dates[i] = START_DATE.plusMonths(3 * i);
            }
            for (int i = 0; i < nDates - 2; ++i)
            {
                LocalDate start = i == 0 ? dates[i] : BUSS_ADJ.adjust(dates[i], REF_DATA);
                LocalDate end   = BUSS_ADJ.adjust(dates[i + 1], REF_DATA);
                PAYMENTS.Add(CreditCouponPaymentPeriod.builder().startDate(start).endDate(end).effectiveStartDate(start.minusDays(1)).effectiveEndDate(end.minusDays(1)).paymentDate(end).currency(USD).notional(NOTIONAL).fixedRate(COUPON).yearFraction(ACT_360.relativeYearFraction(start, end)).build());
            }
            LocalDate start = BUSS_ADJ.adjust(dates[nDates - 2], REF_DATA);
            LocalDate end   = dates[nDates - 1];

            PAYMENTS.Add(CreditCouponPaymentPeriod.builder().startDate(start).endDate(end.plusDays(1)).effectiveStartDate(start.minusDays(1)).effectiveEndDate(end).paymentDate(BUSS_ADJ.adjust(end, REF_DATA)).currency(USD).notional(NOTIONAL).fixedRate(COUPON).yearFraction(ACT_360.relativeYearFraction(start, end.plusDays(1))).build());
        }
        public virtual void test_resolve()
        {
            BusinessDayAdjustment bussAdj = BusinessDayAdjustment.of(FOLLOWING, SAT_SUN);
            ResolvedCds           test    = PRODUCT_STD.resolve(REF_DATA);
            int nDates = 44;

            LocalDate[] dates = new LocalDate[nDates];
            for (int i = 0; i < nDates; ++i)
            {
                dates[i] = START_DATE.plusMonths(3 * i);
            }
            IList <CreditCouponPaymentPeriod> payments = new List <CreditCouponPaymentPeriod>(nDates - 1);

            for (int i = 0; i < nDates - 2; ++i)
            {
                LocalDate start = i == 0 ? dates[i] : bussAdj.adjust(dates[i], REF_DATA);
                LocalDate end   = bussAdj.adjust(dates[i + 1], REF_DATA);
                payments.Add(CreditCouponPaymentPeriod.builder().startDate(start).endDate(end).unadjustedStartDate(dates[i]).unadjustedEndDate(dates[i + 1]).effectiveStartDate(start.minusDays(1)).effectiveEndDate(end.minusDays(1)).paymentDate(end).currency(USD).notional(NOTIONAL).fixedRate(COUPON).yearFraction(ACT_360.relativeYearFraction(start, end)).build());
            }
            LocalDate start = bussAdj.adjust(dates[nDates - 2], REF_DATA);
            LocalDate end   = dates[nDates - 1];

            payments.Add(CreditCouponPaymentPeriod.builder().startDate(start).endDate(end.plusDays(1)).unadjustedStartDate(dates[nDates - 2]).unadjustedEndDate(end).effectiveStartDate(start.minusDays(1)).effectiveEndDate(end).paymentDate(bussAdj.adjust(end, REF_DATA)).currency(USD).notional(NOTIONAL).fixedRate(COUPON).yearFraction(ACT_360.relativeYearFraction(start, end.plusDays(1))).build());
            ResolvedCds expected = ResolvedCds.builder().buySell(BUY).legalEntityId(LEGAL_ENTITY).dayCount(ACT_360).paymentOnDefault(ACCRUED_PREMIUM).paymentPeriods(payments).protectionStart(BEGINNING).protectionEndDate(END_DATE).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build();

            assertEquals(test, expected);
        }
示例#6
0
        public virtual void test_loadAllDates()
        {
            LocalDate sampleDate = ALL_DATES[3];     // 2017-04-21
            ImmutableList <LocalDate> expDates  = ImmutableList.of(LocalDate.of(2017, 0x7, 21), LocalDate.of(2017, 10, 0x7), LocalDate.of(2018, 4, 13), LocalDate.of(2019, 4, 12), LocalDate.of(2020, 3, 20), LocalDate.of(2021, 3, 19), LocalDate.of(2022, 3, 19), LocalDate.of(2023, 3, 17), LocalDate.of(2024, 6, 17), LocalDate.of(2025, 3, 18), LocalDate.of(2026, 3, 20), LocalDate.of(2027, 3, 20), LocalDate.of(2031, 12, 19), LocalDate.of(2037, 3, 17), LocalDate.of(2047, 3, 17), LocalDate.of(2056, 3, 17));
            ImmutableList <string>    expTenors = ImmutableList.of("3M", "6M", "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "15Y", "20Y", "30Y", "40Y");
            RepoGroup   repoGroup      = RepoGroup.of("JP-REPO");
            DoubleArray expRepoXValues = DoubleArray.of(3, n => ACT_365F.relativeYearFraction(sampleDate, expDates.get(n)));
            DoubleArray expRepoYValues = DoubleArray.of(-0.0019521, -0.0016021, -0.0022521);
            ImmutableList <LabelDateParameterMetadata> expRepoMetadata = IntStream.range(0, 3).mapToObj(n => LabelDateParameterMetadata.of(expDates.get(n), expTenors.get(n))).collect(Guavate.toImmutableList());
            LegalEntityGroup legalEntityGroup = LegalEntityGroup.of("JP-GOVT");
            DoubleArray      expIssuerXValues = DoubleArray.of(expDates.size(), n => ACT_365F.relativeYearFraction(sampleDate, expDates.get(n)));
            DoubleArray      expIssuerYValues = DoubleArray.of(-0.0019511690511744527, -0.001497422302092893, -0.0021798583657932176, -0.002215700360912938, -0.0021722324679574866, -0.001922059591219172, -0.0015461646763548528, -0.0014835851245462084, -0.001118669580570464, -5.476767138782941E-4, -2.2155596172855965E-4, 2.0333291172821893E-5, 0.00284500423293463, 0.005876533417933958, 0.007957581583531789, 0.009134630405512047);
            ImmutableList <LabelDateParameterMetadata> expIssuerMetadata = IntStream.range(0, expDates.size()).mapToObj(n => LabelDateParameterMetadata.of(expDates.get(n), expTenors.get(n))).collect(Guavate.toImmutableList());

            ImmutableListMultimap <LocalDate, LegalEntityCurveGroup> allCurves = LegalEntityRatesCurvesCsvLoader.loadAllDates(ResourceLocator.of(GROUPS), ResourceLocator.of(SETTINGS), ImmutableList.of(ResourceLocator.of(CURVES_1), ResourceLocator.of(CURVES_2)));

//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
            assertTrue(allCurves.Keys.containsAll(ALL_DATES));
            ImmutableList <LegalEntityCurveGroup> groups = allCurves.get(sampleDate);

            assertEquals(groups.size(), 2);
            // group 0
            LegalEntityCurveGroup group0 = groups.get(0);

            assertEquals(group0.Name, CurveGroupName.of("Default1"));
            // repo
            assertEquals(group0.RepoCurves.size(), 1);
            Curve repoCurve = group0.RepoCurves.get(Pair.of(repoGroup, JPY));
            InterpolatedNodalCurve expectedRepoCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-REPO-1"), ACT_365F, expRepoMetadata), expRepoXValues, expRepoYValues, CurveInterpolators.LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT);

            assertEquals(repoCurve, expectedRepoCurve);
            // issuer
            assertEquals(group0.IssuerCurves.size(), 2);
            Curve issuerCurve = group0.IssuerCurves.get(Pair.of(legalEntityGroup, JPY));
            InterpolatedNodalCurve expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-GOVT-1"), ACT_365F, expIssuerMetadata), expIssuerXValues, expIssuerYValues, CurveInterpolators.LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT);

            assertEquals(issuerCurve, expectedIssuerCurve);
            Curve usIssuerCurve = group0.IssuerCurves.get(Pair.of(LegalEntityGroup.of("US-GOVT"), USD));

            expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("US-GOVT"), ACT_360, expIssuerMetadata), DoubleArray.of(expDates.size(), n => ACT_360.relativeYearFraction(sampleDate, expDates.get(n))), expIssuerYValues, CurveInterpolators.NATURAL_SPLINE, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT);
            assertEquals(usIssuerCurve, expectedIssuerCurve);
            // group 1
            LegalEntityCurveGroup group1 = groups.get(1);

            assertEquals(group1.Name, CurveGroupName.of("Default2"));
            // repo
            repoCurve         = group1.RepoCurves.get(Pair.of(repoGroup, JPY));
            expectedRepoCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-REPO-2"), ACT_365F, expRepoMetadata), expRepoXValues, expRepoYValues, CurveInterpolators.DOUBLE_QUADRATIC, CurveExtrapolators.LINEAR, CurveExtrapolators.LINEAR);
            assertEquals(repoCurve, expectedRepoCurve);
            // issuer
            assertEquals(group1.IssuerCurves.size(), 1);
            issuerCurve         = group1.IssuerCurves.get(Pair.of(legalEntityGroup, JPY));
            expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-GOVT-2"), ACT_365F, expIssuerMetadata), expIssuerXValues, expIssuerYValues, CurveInterpolators.DOUBLE_QUADRATIC, CurveExtrapolators.LINEAR, CurveExtrapolators.LINEAR);
            assertEquals(issuerCurve, expectedIssuerCurve);
        }
示例#7
0
        public virtual void test_alphaAdjoint()
        {
            HullWhiteOneFactorPiecewiseConstantParametersProvider provider = HullWhiteOneFactorPiecewiseConstantParametersProvider.of(PARAMETERS, ACT_360, DATE_TIME);
            LocalDate        data1    = LocalDate.of(2015, 5, 20);
            LocalDate        data2    = LocalDate.of(2015, 8, 20);
            LocalDate        data3    = LocalDate.of(2015, 8, 20);
            LocalDate        data4    = LocalDate.of(2015, 8, 27);
            ValueDerivatives computed = provider.alphaAdjoint(data1, data2, data3, data4);
            ValueDerivatives expected = HullWhiteOneFactorPiecewiseConstantInterestRateModel.DEFAULT.alphaAdjoint(PARAMETERS, ACT_360.relativeYearFraction(VAL_DATE, data1), ACT_360.relativeYearFraction(VAL_DATE, data2), ACT_360.relativeYearFraction(VAL_DATE, data3), ACT_360.relativeYearFraction(VAL_DATE, data4));

            assertEquals(computed, expected);
        }
示例#8
0
        public virtual void test_futuresConvexityFactor()
        {
            HullWhiteOneFactorPiecewiseConstantParametersProvider provider = HullWhiteOneFactorPiecewiseConstantParametersProvider.of(PARAMETERS, ACT_360, DATE_TIME);
            LocalDate data1    = LocalDate.of(2015, 5, 14);
            LocalDate data2    = LocalDate.of(2015, 5, 20);
            LocalDate data3    = LocalDate.of(2015, 8, 20);
            double    computed = provider.futuresConvexityFactor(data1, data2, data3);
            double    expected = HullWhiteOneFactorPiecewiseConstantInterestRateModel.DEFAULT.futuresConvexityFactor(PARAMETERS, ACT_360.relativeYearFraction(VAL_DATE, data1), ACT_360.relativeYearFraction(VAL_DATE, data2), ACT_360.relativeYearFraction(VAL_DATE, data3));

            assertEquals(computed, expected);
        }