コード例 #1
0
 static IsdaHomogenousCdsIndexTradePricerTest()
 {
     ImmutableList.Builder <StandardId> builder = ImmutableList.builder();
     for (int i = 0; i < 97; ++i)
     {
         builder.add(StandardId.of("OG", i.ToString()));
     }
     LEGAL_ENTITIES = builder.build();
 }
コード例 #2
0
 static FxOptionVolatilitiesDefinitionTest()
 {
     ImmutableList.Builder <FxOptionVolatilitiesNode> builder = ImmutableList.builder();
     ImmutableList.Builder <QuoteId> quoteBuilder             = ImmutableList.builder();
     for (int i = 0; i < TENORS.size(); ++i)
     {
         QuoteId id = QuoteId.of(StandardId.of("OG", TENORS.get(i).ToString() + "_" + DELTAS.get(i).ToString() + "_" + QUOTE_TYPE.get(i).ToString()));
         builder.add(FxOptionVolatilitiesNode.of(EUR_GBP, SPOT_OFFSET, BUS_ADJ, QUOTE_TYPE.get(i), id, TENORS.get(i), DeltaStrike.of(DELTAS.get(i))));
         quoteBuilder.add(id);
     }
     NODES     = builder.build();
     QUOTE_IDS = quoteBuilder.build();
 }
コード例 #3
0
        static CreditDataSet()
        {
            ImmutableList.Builder <StandardId> builder = ImmutableList.builder();
            for (int i = 0; i < 97; ++i)
            {
                builder.add(StandardId.of("OG", i.ToString()));
            }
            LEGAL_ENTITIES = builder.build();
            double flatRate = 0.05;
            double t        = 20.0;
            IsdaCreditDiscountFactors yieldCurve = IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, CurveName.of("discount"), DoubleArray.of(t), DoubleArray.of(flatRate), ACT_365F);

            DISCOUNT_CURVE = yieldCurve.Curve;
            RecoveryRates recoveryRate = ConstantRecoveryRates.of(LEGAL_ENTITY, VALUATION_DATE, RECOVERY_RATE);
            // create the curve nodes and input market quotes
            ImmutableMarketDataBuilder marketQuoteBuilder = ImmutableMarketData.builder(VALUATION_DATE);

            ImmutableList.Builder <CdsIsdaCreditCurveNode>         nodesBuilder            = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsMetadataBuilder      = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsIndexMetadataBuilder = ImmutableList.builder();
            for (int i = 0; i < NUM_MARKET_CDS; i++)
            {
                QuoteId quoteId             = QuoteId.of(StandardId.of("OG", PAR_SPD_DATES[i].ToString()));
                CdsIsdaCreditCurveNode node = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(VALUATION_DATE, PAR_SPD_DATES[i], CDS_CONV), quoteId, LEGAL_ENTITY);
                MARKET_CDS[i]       = CdsTrade.builder().product(Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                MARKET_CDS_INDEX[i] = CdsIndexTrade.builder().product(CdsIndex.of(BuySell.BUY, INDEX_ID, LEGAL_ENTITIES, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                marketQuoteBuilder.addValue(quoteId, PAR_SPREADS[i] * ONE_BP);
                nodesBuilder.add(node);
                cdsMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS[i], MARKET_CDS[i].Product.ProtectionEndDate.ToString()));
                cdsIndexMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS_INDEX[i], MARKET_CDS_INDEX[i].Product.ProtectionEndDate.ToString()));
            }
            ImmutableMarketData marketQuotes             = marketQuoteBuilder.build();
            ImmutableList <CdsIsdaCreditCurveNode> nodes = nodesBuilder.build();

            CDS_METADATA       = cdsMetadataBuilder.build();
            CDS_INDEX_METADATA = cdsIndexMetadataBuilder.build();
            ImmutableCreditRatesProvider rates      = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, recoveryRate)).discountCurves(ImmutableMap.of(USD, yieldCurve)).build();
            IsdaCreditCurveDefinition    definition = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, nodes, true, true);
            // calibrate
            LegalEntitySurvivalProbabilities calibrated = BUILDER.calibrate(definition, marketQuotes, rates, REF_DATA);
            NodalCurve underlyingCurve = ((IsdaCreditDiscountFactors)calibrated.SurvivalProbabilities).Curve;

            CDS_CREDIT_CURVE    = underlyingCurve;
            INDEX_CREDIT_CURVE  = underlyingCurve.withMetadata(underlyingCurve.Metadata.withInfo(CurveInfoType.CDS_INDEX_FACTOR, INDEX_FACTOR).withParameterMetadata(CDS_INDEX_METADATA));    // replace parameter metadata
            CDS_RECOVERY_RATE   = ConstantCurve.of(Curves.recoveryRates("CDS recovery rate", ACT_365F), RECOVERY_RATE);
            INDEX_RECOVERY_RATE = ConstantCurve.of(Curves.recoveryRates("Index recovery rate", ACT_365F), RECOVERY_RATE);
        }
        static SpreadSensitivityCalculatorTest()
        {
            double flatRate = 0.05;
            double t        = 20.0;

            YIELD_CURVE = IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, CurveName.of("discount"), DoubleArray.of(t), DoubleArray.of(flatRate), ACT_365F);
            ImmutableMarketDataBuilder dataBuilder = ImmutableMarketData.builder(VALUATION_DATE);

            ImmutableList.Builder <CdsIsdaCreditCurveNode>         nodesBuilder            = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsMetadataBuilder      = ImmutableList.builder();
            ImmutableList.Builder <ResolvedTradeParameterMetadata> cdsIndexMetadataBuilder = ImmutableList.builder();
            for (int i = 0; i < NUM_MARKET_CDS; i++)
            {
                QuoteId quoteId             = QuoteId.of(StandardId.of("OG", PAR_SPD_DATES[i].ToString()));
                CdsIsdaCreditCurveNode node = CdsIsdaCreditCurveNode.ofParSpread(DatesCdsTemplate.of(VALUATION_DATE, PAR_SPD_DATES[i], CDS_CONV), quoteId, LEGAL_ENTITY);
                MARKET_CDS[i]       = CdsTrade.builder().product(Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                MARKET_CDS_INDEX[i] = CdsIndexTrade.builder().product(CdsIndex.of(BuySell.BUY, INDEX_ID, LEGAL_ENTITIES, USD, NOTIONAL, VALUATION_DATE, PAR_SPD_DATES[i], P3M, SAT_SUN, PAR_SPREADS[i] * ONE_BP)).info(TradeInfo.of(VALUATION_DATE)).build().resolve(REF_DATA);
                dataBuilder.addValue(quoteId, PAR_SPREADS[i] * ONE_BP);
                nodesBuilder.add(node);
                cdsMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS[i], MARKET_CDS[i].Product.ProtectionEndDate.ToString()));
                cdsIndexMetadataBuilder.add(ResolvedTradeParameterMetadata.of(MARKET_CDS_INDEX[i], MARKET_CDS_INDEX[i].Product.ProtectionEndDate.ToString()));
            }
            ImmutableMarketData marketData = dataBuilder.build();
            ImmutableList <CdsIsdaCreditCurveNode> nodes = nodesBuilder.build();

            CDS_METADATA       = cdsMetadataBuilder.build();
            CDS_INDEX_METADATA = cdsIndexMetadataBuilder.build();
            ImmutableCreditRatesProvider rates      = ImmutableCreditRatesProvider.builder().valuationDate(VALUATION_DATE).recoveryRateCurves(ImmutableMap.of(LEGAL_ENTITY, RECOVERY_CURVE)).discountCurves(ImmutableMap.of(USD, YIELD_CURVE)).build();
            IsdaCreditCurveDefinition    definition = IsdaCreditCurveDefinition.of(CREDIT_CURVE_NAME, USD, VALUATION_DATE, ACT_365F, nodes, true, true);

            CREDIT_CURVE = BUILDER.calibrate(definition, marketData, rates, REF_DATA);
            NodalCurve underlyingCurve = ((IsdaCreditDiscountFactors)CREDIT_CURVE.SurvivalProbabilities).Curve;
            NodalCurve curveWithFactor = underlyingCurve.withMetadata(underlyingCurve.Metadata.withInfo(CurveInfoType.CDS_INDEX_FACTOR, INDEX_FACTOR).withParameterMetadata(CDS_INDEX_METADATA));     // replace parameter metadata

            CREDIT_CURVE_INDEX = LegalEntitySurvivalProbabilities.of(INDEX_ID, IsdaCreditDiscountFactors.of(USD, VALUATION_DATE, curveWithFactor));
        }
コード例 #5
0
        //-------------------------------------------------------------------------
        public virtual double accruedInterest(RatePaymentPeriod period, RatesProvider provider)
        {
            LocalDate valDate = provider.ValuationDate;

            if (valDate.compareTo(period.StartDate) <= 0 || valDate.compareTo(period.EndDate) > 0)
            {
                return(0d);
            }
            ImmutableList.Builder <RateAccrualPeriod> truncated = ImmutableList.builder();
            foreach (RateAccrualPeriod rap in period.AccrualPeriods)
            {
                if (valDate.compareTo(rap.EndDate) > 0)
                {
                    truncated.add(rap);
                }
                else
                {
                    truncated.add(rap.toBuilder().endDate(provider.ValuationDate).unadjustedEndDate(provider.ValuationDate).yearFraction(period.DayCount.yearFraction(rap.StartDate, provider.ValuationDate)).build());
                    break;
                }
            }
            RatePaymentPeriod adjustedPaymentPeriod = period.toBuilder().accrualPeriods(truncated.build()).build();

            return(forecastValue(adjustedPaymentPeriod, provider));
        }
コード例 #6
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            BlackFxOptionSmileVolatilitiesSpecification test1 = BlackFxOptionSmileVolatilitiesSpecification.builder().name(VOL_NAME).currencyPair(EUR_GBP).dayCount(ACT_360).nodes(NODES).timeInterpolator(PCHIP).timeExtrapolatorLeft(LINEAR).timeExtrapolatorRight(LINEAR).strikeInterpolator(PCHIP).strikeExtrapolatorLeft(LINEAR).strikeExtrapolatorRight(LINEAR).build();

            coverImmutableBean(test1);
            CurrencyPair eurUsd = CurrencyPair.of(EUR, USD);

            ImmutableList.Builder <FxOptionVolatilitiesNode> builder = ImmutableList.builder();
            for (int i = 0; i < TENORS.size(); ++i)
            {
                QuoteId id = QuoteId.of(StandardId.of("OG", TENORS.get(i).ToString() + "_" + DELTAS.get(i).ToString() + "_" + QUOTE_TYPE.get(i).ToString()));
                builder.add(FxOptionVolatilitiesNode.of(eurUsd, DaysAdjustment.NONE, BusinessDayAdjustment.NONE, QUOTE_TYPE.get(i), id, TENORS.get(i), DeltaStrike.of(DELTAS.get(i))));
            }
            BlackFxOptionSmileVolatilitiesSpecification test2 = BlackFxOptionSmileVolatilitiesSpecification.builder().name(FxOptionVolatilitiesName.of("other")).currencyPair(eurUsd).dayCount(ACT_365F).nodes(builder.build()).timeInterpolator(DOUBLE_QUADRATIC).strikeInterpolator(DOUBLE_QUADRATIC).build();

            coverBeanEquals(test1, test2);
        }