예제 #1
0
        /**
         * Bootstrapper the credit curve from a single market CDS quote. Obviously the resulting credit (hazard)
         * curve will be flat.
         *
         * @param calibrationCDS The single market CDS - this is the reference instruments used to build the credit curve
         * @param marketQuote The market quote of the CDS
         * @param yieldCurve The yield (or discount) curve
         * @return The credit curve
         */
        public PiecewiseconstantHazardRate calibrateCreditCurve(
            CDS calibrationCDS,
            CdsQuoteConvention marketQuote,
            YieldTermStructure yieldCurve)
        {
            double puf    = 0.0;
            double coupon = 0.0;

            if (marketQuote is CdsParSpread)
            {
                puf    = 0.0;
                coupon = marketQuote.getCoupon();
            }
            else if (marketQuote is CdsQuotedSpread)
            {
                puf    = 0.0;
                coupon = ((CdsQuotedSpread)marketQuote).getQuotedSpread();
            }
            else if (marketQuote is PointsUpFront)
            {
                PointsUpFront temp = (PointsUpFront)marketQuote;
                puf    = temp.getPointsUpFront();
                coupon = temp.getCoupon();
            }

            return(calibrateCreditCurve(
                       new CDS[] { calibrationCDS }, new double[] { coupon }, yieldCurve, new double[] { puf }));
        }
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case -1321546630:         // template
                    this.template_Renamed = (CdsTemplate)newValue;
                    break;

                case 102727412:         // label
                    this.label_Renamed = (string)newValue;
                    break;

                case -518800962:         // observableId
                    this.observableId_Renamed = (ObservableId)newValue;
                    break;

                case 866287159:         // legalEntityId
                    this.legalEntityId_Renamed = (StandardId)newValue;
                    break;

                case 2049149709:         // quoteConvention
                    this.quoteConvention_Renamed = (CdsQuoteConvention)newValue;
                    break;

                case 747425396:         // fixedRate
                    this.fixedRate_Renamed = (double?)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
예제 #3
0
        /**
         * Put any CDS market quote into the form needed for the curve builder,
         * namely coupon and points up-front (which can be zero).
         *
         * @param calibrationCDS
         * @param marketQuote
         * @param yieldCurve
         * @return The market quotes in the form required by the curve builder
         */
        private double[] getStandardQuoteForm(
            CDS calibrationCDS,
            CdsQuoteConvention marketQuote,
            YieldTermStructure yieldCurve)
        {
            AnalyticalCdsPricer pricer = new AnalyticalCdsPricer();

            double[] res = new double[2];
            if (marketQuote is CdsParSpread)
            {
                res[0] = marketQuote.getCoupon();
            }
            else if (marketQuote is CdsQuotedSpread)
            {
                CdsQuotedSpread             temp    = (CdsQuotedSpread)marketQuote;
                double                      coupon  = temp.getCoupon();
                double                      qSpread = temp.getQuotedSpread();
                PiecewiseconstantHazardRate cc      = calibrateCreditCurve(
                    new CDS[] { calibrationCDS }, new double[] { qSpread }, yieldCurve, new double[1]);
                res[0] = coupon;
                res[1] = pricer.pv(calibrationCDS, yieldCurve, cc, coupon, CdsPriceType.CLEAN);
            }
            else if (marketQuote is PointsUpFront)
            {
                PointsUpFront temp = (PointsUpFront)marketQuote;
                res[0] = temp.getCoupon();
                res[1] = temp.getPointsUpFront();
            }
            return(res);
        }
 /// <summary>
 /// Restricted copy constructor. </summary>
 /// <param name="beanToCopy">  the bean to copy from, not null </param>
 internal Builder(CdsIsdaCreditCurveNode beanToCopy)
 {
     this.template_Renamed        = beanToCopy.Template;
     this.label_Renamed           = beanToCopy.Label;
     this.observableId_Renamed    = beanToCopy.ObservableId;
     this.legalEntityId_Renamed   = beanToCopy.LegalEntityId;
     this.quoteConvention_Renamed = beanToCopy.QuoteConvention;
     this.fixedRate_Renamed       = beanToCopy.fixedRate;
 }
 private CdsIsdaCreditCurveNode(CdsTemplate template, string label, ObservableId observableId, StandardId legalEntityId, CdsQuoteConvention quoteConvention, double?fixedRate)
 {
     JodaBeanUtils.notNull(template, "template");
     JodaBeanUtils.notEmpty(label, "label");
     JodaBeanUtils.notNull(observableId, "observableId");
     JodaBeanUtils.notNull(legalEntityId, "legalEntityId");
     JodaBeanUtils.notNull(quoteConvention, "quoteConvention");
     this.template        = template;
     this.label           = label;
     this.observableId    = observableId;
     this.legalEntityId   = legalEntityId;
     this.quoteConvention = quoteConvention;
     this.fixedRate       = fixedRate;
     validate();
 }
예제 #6
0
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case 2049149709:         // quoteConvention
                    this.quoteConvention = (CdsQuoteConvention)newValue;
                    break;

                case 1218162921:         // quotedValue
                    this.quotedValue = (double?)newValue.Value;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
 private CdsIndexIsdaCreditCurveNode(CdsTemplate template, string label, ObservableId observableId, StandardId cdsIndexId, IList <StandardId> legalEntityIds, CdsQuoteConvention quoteConvention, double?fixedRate)
 {
     JodaBeanUtils.notNull(template, "template");
     JodaBeanUtils.notEmpty(label, "label");
     JodaBeanUtils.notNull(observableId, "observableId");
     JodaBeanUtils.notNull(cdsIndexId, "cdsIndexId");
     JodaBeanUtils.notNull(legalEntityIds, "legalEntityIds");
     JodaBeanUtils.notNull(quoteConvention, "quoteConvention");
     this.template        = template;
     this.label           = label;
     this.observableId    = observableId;
     this.cdsIndexId      = cdsIndexId;
     this.legalEntityIds  = ImmutableList.copyOf(legalEntityIds);
     this.quoteConvention = quoteConvention;
     this.fixedRate       = fixedRate;
     validate();
 }
 /// <summary>
 /// Sets the market quote convention.
 /// <para>
 /// The CDS is quoted in par spread, points upfront or quoted spread.
 /// See <seealso cref="CdsQuoteConvention"/> for detail.
 /// </para>
 /// </summary>
 /// <param name="quoteConvention">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder quoteConvention(CdsQuoteConvention quoteConvention)
 {
     JodaBeanUtils.notNull(quoteConvention, "quoteConvention");
     this.quoteConvention_Renamed = quoteConvention;
     return(this);
 }
예제 #9
0
 //-------------------------------------------------------------------------
 private System.Func <ResolvedCdsTrade, CdsQuote> createQuoteValueFunction(CreditRatesProvider ratesProviderNew, CdsQuoteConvention targetConvention, ReferenceData refData)
 {
     System.Func <ResolvedCdsTrade, CdsQuote> quoteValueFunction;
     if (targetConvention.Equals(CdsQuoteConvention.POINTS_UPFRONT))
     {
         quoteValueFunction = (ResolvedCdsTrade x) =>
         {
             double puf = pointsUpfront(x, ratesProviderNew, refData);
             return(CdsQuote.of(targetConvention, puf));
         };
     }
     else if (targetConvention.Equals(CdsQuoteConvention.QUOTED_SPREAD))
     {
         quoteValueFunction = (ResolvedCdsTrade x) =>
         {
             double puf = pointsUpfront(x, ratesProviderNew, refData);
             return(quotedSpreadFromPointsUpfront(x, CdsQuote.of(CdsQuoteConvention.POINTS_UPFRONT, puf), ratesProviderNew, refData));
         };
     }
     else
     {
         throw new System.ArgumentException("unsuported CDS quote convention");
     }
     return(quoteValueFunction);
 }
예제 #10
0
        /// <summary>
        /// The par spread quotes are converted to points upfronts or quoted spreads.
        /// <para>
        /// The relevant discount curve and recovery rate curve must be stored in {@code ratesProvider}.
        /// The credit curve is internally calibrated to par spread values.
        /// </para>
        /// <para>
        /// {@code trades} must be sorted in ascending order in maturity and coherent to {@code quotes}.
        /// </para>
        /// <para>
        /// The resultant quote is specified by {@code targetConvention}.
        ///
        /// </para>
        /// </summary>
        /// <param name="trades">  the trades </param>
        /// <param name="quotes">  the quotes </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="targetConvention">  the target convention </param>
        /// <param name="refData">  the reference data </param>
        /// <returns> the quotes </returns>
        public virtual IList <CdsQuote> quotesFromParSpread(IList <ResolvedCdsTrade> trades, IList <CdsQuote> quotes, CreditRatesProvider ratesProvider, CdsQuoteConvention targetConvention, ReferenceData refData)
        {
            ArgChecker.noNulls(trades, "trades");
            ArgChecker.noNulls(quotes, "quotes");
            ArgChecker.notNull(ratesProvider, "ratesProvider");
            ArgChecker.notNull(targetConvention, "targetConvention");
            ArgChecker.notNull(refData, "refData");

            int nNodes = trades.Count;

            ArgChecker.isTrue(quotes.Count == nNodes, "trades and quotes must be the same size");
            quotes.ForEach(q => ArgChecker.isTrue(q.QuoteConvention.Equals(CdsQuoteConvention.PAR_SPREAD), "quote must be par spread"));
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IEnumerator <StandardId> legalEntities = trades.Select(t => t.Product.LegalEntityId).collect(Collectors.toSet()).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            StandardId legalEntityId = legalEntities.next();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ArgChecker.isFalse(legalEntities.hasNext(), "legal entity must be common to trades");
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IEnumerator <Currency> currencies = trades.Select(t => t.Product.Currency).collect(Collectors.toSet()).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Currency currency = currencies.next();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ArgChecker.isFalse(currencies.hasNext(), "currency must be common to trades");

            LocalDate             valuationDate    = ratesProvider.ValuationDate;
            CreditDiscountFactors discountFactors  = ratesProvider.discountFactors(currency);
            RecoveryRates         recoveryRates    = ratesProvider.recoveryRates(legalEntityId);
            NodalCurve            creditCurve      = calibrator.calibrate(trades, DoubleArray.of(nNodes, q => quotes[q].QuotedValue), DoubleArray.filled(nNodes), CurveName.of("temp"), valuationDate, discountFactors, recoveryRates, refData);
            CreditRatesProvider   ratesProviderNew = ratesProvider.toImmutableCreditRatesProvider().toBuilder().creditCurves(ImmutableMap.of(Pair.of(legalEntityId, currency), LegalEntitySurvivalProbabilities.of(legalEntityId, IsdaCreditDiscountFactors.of(currency, valuationDate, creditCurve)))).build();

            System.Func <ResolvedCdsTrade, CdsQuote> quoteValueFunction = createQuoteValueFunction(ratesProviderNew, targetConvention, refData);
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ImmutableList <CdsQuote> result = trades.Select(c => quoteValueFunction(c)).collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList.copyOf));

            return(result);
        }
예제 #11
0
 private CdsQuote(CdsQuoteConvention quoteConvention, double quotedValue)
 {
     JodaBeanUtils.notNull(quoteConvention, "quoteConvention");
     this.quoteConvention = quoteConvention;
     this.quotedValue     = quotedValue;
 }
예제 #12
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates an instance.
 /// </summary>
 /// <param name="quoteConvention"> the quote convention </param>
 /// <param name="quotedValue">  the quoted value </param>
 /// <returns> the instance </returns>
 public static CdsQuote of(CdsQuoteConvention quoteConvention, double quotedValue)
 {
     return(new CdsQuote(quoteConvention, quotedValue));
 }
        //***************************************************************************************************************
        // parallel CS01 of a CDS from single market quote of that CDS
        //***************************************************************************************************************

        /**
         * The CS01 (or credit DV01)  of a CDS - the sensitivity of the PV to a finite increase of market spread (on NOT the CDS's
         * coupon). If the CDS is quoted as points up-front, this is first converted to a quoted spread, and <b>this</b> is bumped.
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param quote  the market quote for the CDS - these can be ParSpread, PointsUpFront or QuotedSpread
         * @param yieldCurve  the yield (or discount) curve
         * @return the parallel CS01
         */
        public double parallelCS01(CDS cds, CdsQuoteConvention quote, YieldTermStructure yieldCurve)
        {
            return(parallelCS01(cds, quote.getCoupon(), new CDS[] { cds }, new CdsQuoteConvention[] { quote }, yieldCurve));
        }
        internal virtual LegalEntitySurvivalProbabilities calibrate(IList <CdsIsdaCreditCurveNode> curveNodes, CurveName name, MarketData marketData, ImmutableCreditRatesProvider ratesProvider, DayCount definitionDayCount, Currency definitionCurrency, bool computeJacobian, bool storeTrade, ReferenceData refData)
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IEnumerator <StandardId> legalEntities = curveNodes.Select(CdsIsdaCreditCurveNode::getLegalEntityId).collect(Collectors.toSet()).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            StandardId legalEntityId = legalEntities.next();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ArgChecker.isFalse(legalEntities.hasNext(), "legal entity must be common to curve nodes");
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IEnumerator <Currency> currencies = curveNodes.Select(n => n.Template.Convention.Currency).collect(Collectors.toSet()).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            Currency currency = currencies.next();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ArgChecker.isFalse(currencies.hasNext(), "currency must be common to curve nodes");
            ArgChecker.isTrue(definitionCurrency.Equals(currency), "curve definition currency must be the same as the currency of CDS");
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            IEnumerator <CdsQuoteConvention> quoteConventions = curveNodes.Select(n => n.QuoteConvention).collect(Collectors.toSet()).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            CdsQuoteConvention quoteConvention = quoteConventions.next();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            ArgChecker.isFalse(quoteConventions.hasNext(), "quote convention must be common to curve nodes");
            LocalDate valuationDate = marketData.ValuationDate;

            ArgChecker.isTrue(valuationDate.Equals(marketData.ValuationDate), "ratesProvider and marketDate must be based on the same valuation date");
            CreditDiscountFactors discountFactors = ratesProvider.discountFactors(currency);

            ArgChecker.isTrue(definitionDayCount.Equals(discountFactors.DayCount), "credit curve and discount curve must be based on the same day count convention");
            RecoveryRates recoveryRates = ratesProvider.recoveryRates(legalEntityId);

            int nNodes = curveNodes.Count;

            double[] coupons = new double[nNodes];
            double[] pufs    = new double[nNodes];
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] diag = new double[nNodes][nNodes];
            double[][] diag = RectangularArrays.ReturnRectangularDoubleArray(nNodes, nNodes);
            ImmutableList.Builder <ResolvedCdsTrade> tradesBuilder = ImmutableList.builder();
            for (int i = 0; i < nNodes; i++)
            {
                CdsCalibrationTrade tradeCalibration = curveNodes[i].trade(1d, marketData, refData);
                ResolvedCdsTrade    trade            = tradeCalibration.UnderlyingTrade.resolve(refData);
                tradesBuilder.add(trade);
                double[] temp = getStandardQuoteForm(trade, tradeCalibration.Quote, valuationDate, discountFactors, recoveryRates, computeJacobian, refData);
                coupons[i] = temp[0];
                pufs[i]    = temp[1];
                diag[i][i] = temp[2];
            }
            ImmutableList <ResolvedCdsTrade> trades = tradesBuilder.build();
            NodalCurve nodalCurve = calibrate(trades, DoubleArray.ofUnsafe(coupons), DoubleArray.ofUnsafe(pufs), name, valuationDate, discountFactors, recoveryRates, refData);

            if (computeJacobian)
            {
                LegalEntitySurvivalProbabilities            creditCurve      = LegalEntitySurvivalProbabilities.of(legalEntityId, IsdaCreditDiscountFactors.of(currency, valuationDate, nodalCurve));
                ImmutableCreditRatesProvider                ratesProviderNew = ratesProvider.toBuilder().creditCurves(ImmutableMap.of(Pair.of(legalEntityId, currency), creditCurve)).build();
                System.Func <ResolvedCdsTrade, DoubleArray> sensiFunc        = quoteConvention.Equals(CdsQuoteConvention.PAR_SPREAD) ? getParSpreadSensitivityFunction(ratesProviderNew, name, currency, refData) : getPointsUpfrontSensitivityFunction(ratesProviderNew, name, currency, refData);
                DoubleMatrix sensi = DoubleMatrix.ofArrayObjects(nNodes, nNodes, i => sensiFunc(trades.get(i)));
                sensi = (DoubleMatrix)MATRIX_ALGEBRA.multiply(DoubleMatrix.ofUnsafe(diag), sensi);
                JacobianCalibrationMatrix jacobian = JacobianCalibrationMatrix.of(ImmutableList.of(CurveParameterSize.of(name, nNodes)), MATRIX_ALGEBRA.getInverse(sensi));
                nodalCurve = nodalCurve.withMetadata(nodalCurve.Metadata.withInfo(CurveInfoType.JACOBIAN, jacobian));
            }

            ImmutableList <ParameterMetadata> parameterMetadata;

            if (storeTrade)
            {
                parameterMetadata = IntStream.range(0, nNodes).mapToObj(n => ResolvedTradeParameterMetadata.of(trades.get(n), curveNodes[n].Label)).collect(Guavate.toImmutableList());
            }
            else
            {
                parameterMetadata = IntStream.range(0, nNodes).mapToObj(n => curveNodes[n].metadata(trades.get(n).Product.ProtectionEndDate)).collect(Guavate.toImmutableList());
            }
            nodalCurve = nodalCurve.withMetadata(nodalCurve.Metadata.withParameterMetadata(parameterMetadata));

            return(LegalEntitySurvivalProbabilities.of(legalEntityId, IsdaCreditDiscountFactors.of(currency, valuationDate, nodalCurve)));
        }