示例#1
0
        //! Conventional/standard upfront-to-spread conversion

        /*! Under a standard ISDA model and a set of standardised
         *  instrument characteristics, it is the running only quoted
         *  spread that will make a CDS contract have an NPV of 0 when
         *  quoted for that running only spread.  Refer to: "ISDA
         *  Standard CDS converter specification." May 2009.
         *
         *  The conventional recovery rate to apply in the calculation
         *  is as specified by ISDA, not necessarily equal to the
         *  market-quoted one.  It is typically 0.4 for SeniorSec and
         *  0.2 for subordinate.
         *
         *  \note The conversion employs a flat hazard rate. As a result,
         *        you will not recover the market quotes.
         *
         *  \note This method performs the calculation with the
         *        instrument characteristics. It will coincide with
         *        the ISDA calculation if your object has the standard
         *        characteristics. Notably:
         *        - The calendar should have no bank holidays, just
         *          weekends.
         *        - The yield curve should be LIBOR piecewise ant
         *          in fwd rates, with a discount factor of 1 on the
         *          calculation date, which coincides with the trade
         *          date.
         *        - Convention should be Following for yield curve and
         *          contract cashflows.
         *        - The CDS should pay accrued and mature on standard
         *          IMM dates, settle on trade date +1 and upfront
         *          settle on trade date +3.
         */
        public double?conventionalSpread(double conventionalRecovery,
                                         Handle <YieldTermStructure> discountCurve,
                                         DayCounter dayCounter)
        {
            double flatHazardRate = impliedHazardRate(0.0,
                                                      discountCurve,
                                                      dayCounter,
                                                      conventionalRecovery);

            Handle <DefaultProbabilityTermStructure> probability = new Handle <DefaultProbabilityTermStructure>(
                new FlatHazardRate(0, new WeekendsOnly(), flatHazardRate, dayCounter));

            MidPointCdsEngine engine = new MidPointCdsEngine(probability, conventionalRecovery, discountCurve, true);

            setupArguments(engine.getArguments());
            engine.calculate();
            CreditDefaultSwap.Results results = engine.getResults() as CreditDefaultSwap.Results;
            return(results.fairSpread);
        }
示例#2
0
        public double impliedHazardRate(double targetNPV,
                                        Handle <YieldTermStructure> discountCurve,
                                        DayCounter dayCounter,
                                        double recoveryRate = 0.4,
                                        double accuracy     = 1.0e-6)
        {
            SimpleQuote flatRate = new SimpleQuote(0.0);

            Handle <DefaultProbabilityTermStructure> probability = new Handle <DefaultProbabilityTermStructure>(
                new FlatHazardRate(0, new WeekendsOnly(), new Handle <Quote>(flatRate), dayCounter));

            MidPointCdsEngine engine = new MidPointCdsEngine(probability, recoveryRate, discountCurve);

            setupArguments(engine.getArguments());
            CreditDefaultSwap.Results results = engine.getResults() as CreditDefaultSwap.Results;

            ObjectiveFunction f     = new ObjectiveFunction(targetNPV, flatRate, engine, results);
            double            guess = 0.001;
            double            step  = guess * 0.1;

            return(new Brent().solve(f, accuracy, guess, step));
        }