Пример #1
0
        public static double atmRate(Leg leg, YieldTermStructure discountCurve, bool includeSettlementDateFlows)
        {
            double ret = NQuantLibcPINVOKE.CashFlows_atmRate__SWIG_3(Leg.getCPtr(leg), YieldTermStructure.getCPtr(discountCurve), includeSettlementDateFlows);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #2
0
        /**
         * Immediately prior to default, the CDS has some value V (to the protection buyer).
         * After default, the contract cancelled, so there is an immediate loss of -V (or a gain if V was negative).
         * The protection buyer pays the accrued interest A and receives 1-RR, so the full
         * Value on Default (VoD) is -V + (1-RR) (where the A has been absorbed as we use the clean price for V).
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @param coupon  the coupon of the CDS
         * @return the value on default or jump to default
         */
        public double valueOnDefault(
            CDS cds,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve,
            double coupon)
        {
            double pv = _pricer.pv(cds, yieldCurve, creditCurve, coupon);

            return(-pv + cds.getLGD());
        }
Пример #3
0
        public static double bps(Leg leg, YieldTermStructure discountCurve, bool includeSettlementDateFlows, Date settlementDate, Date npvDate)
        {
            double ret = NQuantLibcPINVOKE.CashFlows_bps__SWIG_0(Leg.getCPtr(leg), YieldTermStructure.getCPtr(discountCurve), includeSettlementDateFlows, Date.getCPtr(settlementDate), Date.getCPtr(npvDate));

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #4
0
        public static ZeroCurve as_zerocurve(YieldTermStructure curve)
        {
            ZeroCurve ret = new ZeroCurve(NQuantLibcPINVOKE.as_zerocurve(YieldTermStructure.getCPtr(curve)), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #5
0
        public static double cleanPriceFromZSpread(Bond bond, YieldTermStructure discountCurve, double zSpread, DayCounter dc, Compounding compounding, Frequency freq)
        {
            double ret = NQuantLibcPINVOKE.cleanPriceFromZSpread__SWIG_1(Bond.getCPtr(bond), YieldTermStructure.getCPtr(discountCurve), zSpread, DayCounter.getCPtr(dc), (int)compounding, (int)freq);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #6
0
        public static double npv(Leg leg, YieldTermStructure discountCurve, double zSpread, DayCounter dayCounter, Compounding compounding, Frequency frequency, bool includeSettlementDateFlows)
        {
            double ret = NQuantLibcPINVOKE.CashFlows_npv__SWIG_2(Leg.getCPtr(leg), YieldTermStructure.getCPtr(discountCurve), zSpread, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, includeSettlementDateFlows);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #7
0
        public static double zSpread(Leg leg, double npv, YieldTermStructure arg2, DayCounter dayCounter, Compounding compounding, Frequency frequency, bool includeSettlementDateFlows, Date settlementDate, Date npvDate, double accuracy, uint maxIterations)
        {
            double ret = NQuantLibcPINVOKE.CashFlows_zSpread__SWIG_1(Leg.getCPtr(leg), npv, YieldTermStructure.getCPtr(arg2), DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, includeSettlementDateFlows, Date.getCPtr(settlementDate), Date.getCPtr(npvDate), accuracy, maxIterations);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        //***************************************************************************************************************
        // bucketed CS01 of a CDS from single market quote of that CDS
        //***************************************************************************************************************

        public double[] bucketedCS01FromSpread(
            CDS cds,
            double coupon,
            YieldTermStructure yieldCurve,
            double marketSpread,
            CDS[] buckets)
        {
            PiecewiseconstantHazardRate cc = _curveBuilder.calibrateCreditCurve(cds, marketSpread, yieldCurve);

            return(bucketedCS01FromCreditCurve(cds, coupon, buckets, yieldCurve, cc));
        }
        public YieldTermStructure __deref__()
        {
            global::System.IntPtr cPtr = NQuantLibcPINVOKE.YieldTermStructureHandle___deref__(swigCPtr);
            YieldTermStructure    ret  = (cPtr == global::System.IntPtr.Zero) ? null : new YieldTermStructure(cPtr, true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        public double[][] bucketedCS01(
            CDS[] cds,
            double[] cdsCoupons,
            CDS[] pillarCDSs,
            CdsQuoteConvention[] marketQuotes,
            YieldTermStructure yieldCurve)
        {
            PiecewiseconstantHazardRate creditCurve = _curveBuilder.calibrateCreditCurve(pillarCDSs, marketQuotes, yieldCurve);

            return(bucketedCS01FromCreditCurve(cds, cdsCoupons, pillarCDSs, yieldCurve, creditCurve));
        }
        public double[] bucketedCS01FromParSpreads(
            CDS cds,
            double cdsCoupon,
            YieldTermStructure yieldCurve,
            CDS[] pillarCDSs,
            double[] spreads)
        {
            PiecewiseconstantHazardRate creditCurve = _curveBuilder.calibrateCreditCurve(pillarCDSs, spreads, yieldCurve);

            return(bucketedCS01FromCreditCurve(cds, cdsCoupon, pillarCDSs, yieldCurve, creditCurve));
        }
Пример #12
0
        public void testCashOrNothingEuropeanValues()
        {
            // Testing European cash-or-nothing digital option

            DigitalOptionData[] values =
            {
                // "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 - pag 88
                //        type, strike,  spot,    q,    r,    t,  vol,  value, tol
                new DigitalOptionData(Option.Type.Put, 80.00, 100.0, 0.06, 0.06, 0.75, 0.35, 2.6710, 1e-4, true)
            };

            DayCounter dc    = new Actual360();
            Date       today = Date.Today;

            SimpleQuote           spot  = new SimpleQuote(0.0);
            SimpleQuote           qRate = new SimpleQuote(0.0);
            YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
            SimpleQuote           rRate = new SimpleQuote(0.0);
            YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
            SimpleQuote           vol   = new SimpleQuote(0.0);
            BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

            for (int i = 0; i < values.Length; i++)
            {
                StrikedTypePayoff payoff = new CashOrNothingPayoff(values[i].type, values[i].strike, 10.0);

                Date     exDate   = today + Convert.ToInt32(values[i].t * 360 + 0.5);
                Exercise exercise = new EuropeanExercise(exDate);

                spot.setValue(values[i].s);
                qRate.setValue(values[i].q);
                rRate.setValue(values[i].r);
                vol.setValue(values[i].v);

                BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(new Handle <Quote>(spot),
                                                                                       new Handle <YieldTermStructure>(qTS),
                                                                                       new Handle <YieldTermStructure>(rTS),
                                                                                       new Handle <BlackVolTermStructure>(volTS));

                IPricingEngine engine = new AnalyticEuropeanEngine(stochProcess);

                VanillaOption opt = new VanillaOption(payoff, exercise);
                opt.setPricingEngine(engine);

                double calculated = opt.NPV();
                double error      = Math.Abs(calculated - values[i].result);
                if (error > values[i].tol)
                {
                    REPORT_FAILURE("value", payoff, exercise, values[i].s, values[i].q,
                                   values[i].r, today, values[i].v, values[i].result,
                                   calculated, error, values[i].tol, values[i].knockin);
                }
            }
        }
Пример #13
0
        /**
         * The par spread par spread for a given yield and credit (hazard rate/survival) curve).
         *
         * @param cds analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @return the par spread
         */
        public double parSpread(CDS cds, YieldTermStructure yieldCurve, PiecewiseconstantHazardRate creditCurve)
        {
            if (cds.getProtectionEnd() <= 0.0)
            { //short cut already Expired CDSs
            }

            double rpv01  = annuity(cds, yieldCurve, creditCurve, CdsPriceType.CLEAN, 0.0);
            double proLeg = protectionLeg(cds, yieldCurve, creditCurve, 0.0);

            return(proLeg / rpv01);
        }
        public void calculate()
        {
            FxTermStructure    fxForwardTS = under_.fxForwardTS_;
            YieldTermStructure discountTS  = engine_.disCountTS_;

            double tradedForward = instInfo_.fxForwardRate_;
            double marketForward = fxForwardTS.forwardRate(instInfo_.maturityDate_);

            unitValue_ = (tradedForward - marketForward) * discountTS.discount(instInfo_.payDate_);

            this.Value_ = Convert.ToInt64(unitValue_) * instInfo_.Notional_;
        }
        //public FxTermStructure fxForwardTS_ { get; set; }

        public FxUnderlying(CurrencyType baseCurrency,
                            YieldTermStructure baseCurrencyTS,
                            CurrencyType counterCurrency,
                            YieldTermStructure counterCurrencyTS,
                            double spotRate)
        {
            this.baseCurrency_      = baseCurrency;
            this.counterCurrency_   = counterCurrency;
            this.baseCurrencyTS_    = baseCurrencyTS;
            this.counterCurrencyTS_ = counterCurrencyTS;
            this.spotRate_          = spotRate;
        }
Пример #16
0
        //-------------------------------------------------------------------------

        /**
         * Hedge a CDS with other CDSs on the same underlying (single-name or index) at different maturities.
         * <p>
         * The hedge is such that the total portfolio (the CDS <b>minus</b> the hedging CDSs, with notionals of the
         * CDS notional times the computed hedge ratios) is insensitive to infinitesimal changes to the the credit curve.
         * <p>
         * Here the credit curve is built using the hedging CDSs as pillars.
         *
         * @param cds  the CDS to be hedged
         * @param coupon  the coupon of the CDS to be hedged
         * @param hedgeCDSs  the CDSs to hedge with - these are also used to build the credit curve
         * @param hedgeCDSCoupons  the coupons of the CDSs to hedge with/build credit curve
         * @param hegdeCDSPUF  the PUF of the CDSs to build credit curve
         * @param yieldCurve  the yield curve
         * @return the hedge ratios,
         *  since we use a unit notional, the ratios should be multiplied by -notional to give the hedge notional amounts
         */
        public double[] getHedgeRatios(
            CDS cds,
            double coupon,
            CDS[] hedgeCDSs,
            double[] hedgeCDSCoupons,
            double[] hegdeCDSPUF,
            YieldTermStructure yieldCurve)
        {
            PiecewiseconstantHazardRate cc = _builder.calibrateCreditCurve(hedgeCDSs, hedgeCDSCoupons, yieldCurve, hegdeCDSPUF);

            return(getHedgeRatios(cds, coupon, hedgeCDSs, hedgeCDSCoupons, cc, yieldCurve));
        }
Пример #17
0
 /**
  * Hedge a CDS with other CDSs on the same underlying (single-name or index) at different maturities.
  * <p>
  * The hedge is such that the total portfolio (the CDS <b>minus</b> the hedging CDSs, with notionals of the
  * CDS notional times the computed hedge ratios) is insensitive to infinitesimal changes to the the credit curve.
  * <p>
  * If the number of hedge-CDSs equals the number of credit-curve knots, the system is square
  * and is solved exactly (see below).<br>
  * If the number of hedge-CDSs is less than the number of credit-curve knots, the system is
  * solved in a least-square sense (i.e. is hedge is not exact).<br>
  * If the number of hedge-CDSs is greater than the number of credit-curve knots, the system
  * cannot be solved. <br>
  * The system may not solve if the maturities if the hedging CDSs and very different from the
  * knot times (i.e. the sensitivity matrix is singular).
  *
  * @param cds  the CDS to be hedged
  * @param coupon  the coupon of the CDS to be hedged
  * @param hedgeCDSs  the CDSs to hedge with - these are also used to build the credit curve
  * @param hedgeCDSCoupons  the coupons of the CDSs to hedge with/build credit curve
  * @param creditCurve The credit curve
  * @param yieldCurve the yield curve
  * @return the hedge ratios,
  *  since we use a unit notional, the ratios should be multiplied by -notional to give the hedge notional amounts
  */
 public double[] getHedgeRatios(
     CDS cds,
     double coupon,
     CDS[] hedgeCDSs,
     double[] hedgeCDSCoupons,
     PiecewiseconstantHazardRate creditCurve,
     YieldTermStructure yieldCurve)
 {
     double[] cdsSense = getCurveSensitivities(cds, coupon, creditCurve, yieldCurve);
     double[,] hedgeSense = getCurveSensitivities(hedgeCDSs, hedgeCDSCoupons, creditCurve, yieldCurve);
     return(getHedgeRatios(cdsSense, hedgeSense));
 }
        /**
         * The analytic CS01 (or credit DV01).
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param coupon  the of the traded CDS  (expressed as <b>fractions not basis points</b>)
         * @param yieldCurve  the yield (or discount) curve
         * @param puf  the points up-front (as a fraction)
         * @return the credit DV01
         */
        public double parallelCS01FromPUF(CDS cds, double coupon, YieldTermStructure yieldCurve, double puf)
        {
            PiecewiseconstantHazardRate cc = _curveBuilder.calibrateCreditCurve(cds, coupon, yieldCurve, puf);
            double a      = _pricer.protectionLeg(cds, yieldCurve, cc);
            double b      = _pricer.annuity(cds, yieldCurve, cc, CdsPriceType.CLEAN);
            double aPrime = _pricer.protectionLegCreditSensitivity(cds, yieldCurve, cc, 0);
            double bPrime = _pricer.pvPremiumLegCreditSensitivity(cds, yieldCurve, cc, 0);
            double s      = a / b;
            double dPVdh  = aPrime - coupon * bPrime;
            double dSdh   = (aPrime - s * bPrime) / b;

            return(dPVdh / dSdh);
        }
Пример #19
0
 public ProtectionLegElement(double start, double end, YieldTermStructure yieldCurve, int creditCurveKnot, double[] knots)
 {
     _knots = DoublesScheduleGenerator.truncateSetInclusive(start, end, knots);
     _n     = _knots.Length;
     _rt    = new double[_n];
     _p     = new double[_n];
     for (int i = 0; i < _n; i++)
     {
         _rt[i] = yieldCurve.getRT_(_knots[i]);
         _p[i]  = Math.Exp(-_rt[i]);
     }
     _creditCurveKnot = creditCurveKnot;
 }
Пример #20
0
        public static double bps(Bond bond, YieldTermStructure discountCurve, Date settlementDate = null)
        {
            if (settlementDate == null)
            {
                settlementDate = bond.settlementDate();
            }

            Utils.QL_REQUIRE(BondFunctions.isTradable(bond, settlementDate), () =>
                             "non tradable at " + settlementDate +
                             " (maturity being " + bond.maturityDate() + ")");

            return(CashFlows.bps(bond.cashflows(), discountCurve, false, settlementDate) * 100.0 / bond.notional(settlementDate));
        }
Пример #21
0
 public FdmQuantoHelper(
     YieldTermStructure rTS,
     YieldTermStructure fTS,
     BlackVolTermStructure fxVolTS,
     double equityFxCorrelation,
     double exchRateATMlevel)
 {
     rTS_                 = rTS;
     fTS_                 = fTS;
     fxVolTS_             = fxVolTS;
     equityFxCorrelation_ = equityFxCorrelation;
     exchRateATMlevel_    = exchRateATMlevel;
 }
Пример #22
0
        public void testValues()
        {
            // Testing Cliquet option values

            Date       today = Date.Today;
            DayCounter dc    = new Actual360();

            SimpleQuote           spot  = new SimpleQuote(60.0);
            SimpleQuote           qRate = new SimpleQuote(0.04);
            YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
            SimpleQuote           rRate = new SimpleQuote(0.08);
            YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
            SimpleQuote           vol   = new SimpleQuote(0.30);
            BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

            BlackScholesMertonProcess process = new BlackScholesMertonProcess(
                new Handle <Quote>(spot),
                new Handle <YieldTermStructure>(qTS),
                new Handle <YieldTermStructure>(rTS),
                new Handle <BlackVolTermStructure>(volTS));
            IPricingEngine engine = new AnalyticCliquetEngine(process);

            List <Date> reset = new List <Date>();

            reset.Add(today + 90);
            Date maturity = today + 360;

            Option.Type type      = Option.Type.Call;
            double      moneyness = 1.1;

            PercentageStrikePayoff payoff   = new PercentageStrikePayoff(type, moneyness);
            EuropeanExercise       exercise = new EuropeanExercise(maturity);

            CliquetOption option = new CliquetOption(payoff, exercise, reset);

            option.setPricingEngine(engine);

            double calculated = option.NPV();
            double expected   = 4.4064; // Haug, p.37
            double error      = Math.Abs(calculated - expected);
            double tolerance  = 1e-4;

            if (error > tolerance)
            {
                REPORT_FAILURE("value", payoff, exercise, spot.value(),
                               qRate.value(), rRate.value(), today,
                               vol.value(), expected, calculated,
                               error, tolerance);
            }
        }
Пример #23
0
        public double parSpreadCreditSensitivity(
            CDS cds,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve,
            int creditCurveNode)
        {
            double a      = protectionLeg(cds, yieldCurve, creditCurve);
            double b      = annuity(cds, yieldCurve, creditCurve, CdsPriceType.CLEAN);
            double spread = a / b;
            double dadh   = protectionLegCreditSensitivity(cds, yieldCurve, creditCurve, creditCurveNode);
            double dbdh   = pvPremiumLegCreditSensitivity(cds, yieldCurve, creditCurve, creditCurveNode);

            return(spread * (dadh / a - dbdh / b));
        }
Пример #24
0
        //-------------------------------------------------------------------------

        /**
         * The sensitivity of the PV of a CDS to the zero hazard rates at the knots of the credit curve.
         *
         * @param cds  the CDS
         * @param coupon  the coupon
         * @param creditCurve  the credit Curve
         * @param yieldCurve  the yield curve
         * @return vector of sensitivities
         */
        public double[] getCurveSensitivities(
            CDS cds,
            double coupon,
            PiecewiseconstantHazardRate creditCurve,
            YieldTermStructure yieldCurve)
        {
            int n = creditCurve.getNumberOfKnots();

            double[] CurveSen = new double[n];
            for (int i = 0; i < n; i++)
            {
                CurveSen[i] = _pricer.pvCreditSensitivity(cds, yieldCurve, creditCurve, coupon, i);
            }
            return(CurveSen);
        }
Пример #25
0
        public double pvPremiumLegCreditSensitivity(
            CDS cds,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve,
            int creditCurveNode)
        {
            if (cds.getProtectionEnd() <= 0.0)
            { //short cut already expired CDSs
                return(0.0);
            }

            int    n       = cds.getNumPayments();
            double pvSense = 0.0;

            for (int i = 0; i < n; i++)
            {
                CdsCoupon c             = cds.getCoupon(i);
                double    paymentTime   = c.getPaymentTime();
                double    creditObsTime = c.getEffEnd();
                double    dqdh          = creditCurve.getSingleNodeDiscountFactorSensitivity(creditObsTime, creditCurveNode);
                if (dqdh == 0)
                {
                    continue;
                }
                double p = Math.Exp(-yieldCurve.getRT_(paymentTime));
                pvSense += c.getYearFrac() * p * dqdh;
            }

            if (cds.isPayAccOnDefault())
            {
                double   start = cds.getNumPayments() == 1 ? cds.getEffectiveProtectionStart() : cds.getAccStart();
                double[] integrationSchedule = DoublesScheduleGenerator.getIntegrationsPoints(start, cds.getProtectionEnd(), yieldCurve, creditCurve);

                double accPVSense = 0.0;
                for (int i = 0; i < n; i++)
                {
                    accPVSense += calculateSinglePeriodAccrualOnDefaultCreditSensitivity(
                        cds.getCoupon(i),
                        cds.getEffectiveProtectionStart(), integrationSchedule, yieldCurve, creditCurve, creditCurveNode);
                }
                pvSense += accPVSense;
            }

            double df = Math.Exp(-yieldCurve.getRT_(cds.getCashSettleTime()));

            pvSense /= df;
            return(pvSense);
        }
Пример #26
0
        public void testFdValues()
        {
            //("Testing finite-difference engine for American options...");

            Date               today = Date.Today;
            DayCounter         dc    = new Actual360();
            SimpleQuote        spot  = new SimpleQuote(0.0);
            SimpleQuote        qRate = new SimpleQuote(0.0);
            YieldTermStructure qTS   = Utilities.flatRate(today, qRate, dc);

            SimpleQuote           rRate = new SimpleQuote(0.0);
            YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
            SimpleQuote           vol   = new SimpleQuote(0.0);
            BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

            double tolerance = 8.0e-2;

            for (int i = 0; i < juValues.Length; i++)
            {
                StrikedTypePayoff payoff = new PlainVanillaPayoff(juValues[i].type, juValues[i].strike);
                Date     exDate          = today + Convert.ToInt32(juValues[i].t * 360 + 0.5);
                Exercise exercise        = new AmericanExercise(today, exDate);

                spot.setValue(juValues[i].s);
                qRate.setValue(juValues[i].q);
                rRate.setValue(juValues[i].r);
                vol.setValue(juValues[i].v);

                BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(new Handle <Quote>(spot),
                                                                                       new Handle <YieldTermStructure>(qTS),
                                                                                       new Handle <YieldTermStructure>(rTS),
                                                                                       new Handle <BlackVolTermStructure>(volTS));

                IPricingEngine engine = new FDAmericanEngine(stochProcess, 100, 100);

                VanillaOption option = new VanillaOption(payoff, exercise);
                option.setPricingEngine(engine);

                double calculated = option.NPV();
                double error      = Math.Abs(calculated - juValues[i].result);
                if (error > tolerance)
                {
                    REPORT_FAILURE("value", payoff, exercise, juValues[i].s, juValues[i].q,
                                   juValues[i].r, today, juValues[i].v, juValues[i].result,
                                   calculated, error, tolerance);
                }
            }
        }
        public double parallelCS01FromCreditCurve(
            CDS cds,
            double cdsCoupon,
            CDS[] bucketCDSs,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve)
        {
            double[] temp = bucketedCS01FromCreditCurve(cds, cdsCoupon, bucketCDSs, yieldCurve, creditCurve);
            double   sum  = 0;

            foreach (double cs in temp)
            {
                sum += cs;
            }
            return(sum);
        }
Пример #28
0
        /**
         * Sensitivity of the present value (for the payer of premiums, i.e. the buyer of protection) to
         * the zero hazard rate of a given node (knot) of the credit curve. This is per unit of notional.
         *
         * @param cds  the analytic description of a CDS traded at a certain time
         * @param yieldCurve  the yield (or discount) curve
         * @param creditCurve  the credit (or survival) curve
         * @param fractionalSpread  the <b>fraction</b> spread
         * @param creditCurveNode  the credit curve node
         * @return PV sensitivity to one node (knot) on the credit (hazard rate/survival) curve
         */
        public double pvCreditSensitivity(
            CDS cds,
            YieldTermStructure yieldCurve,
            PiecewiseconstantHazardRate creditCurve,
            double fractionalSpread,
            int creditCurveNode)
        {
            if (cds.getProtectionEnd() <= 0.0)
            { //short cut already expired CDSs
                return(0.0);
            }
            double rpv01Sense  = pvPremiumLegCreditSensitivity(cds, yieldCurve, creditCurve, creditCurveNode);
            double proLegSense = protectionLegCreditSensitivity(cds, yieldCurve, creditCurve, creditCurveNode);

            return(proLegSense - fractionalSpread * rpv01Sense);
        }
Пример #29
0
        // par-rate approximation
        public static double parRate(YieldTermStructure yts, List <Date> dates, DayCounter resultDayCounter)
        {
            Utils.QL_REQUIRE(dates.Count >= 2, () => "at least two dates are required");
            double sum = 0.0;
            double dt;

            for (int i = 1; i < dates.Count; ++i)
            {
                dt = resultDayCounter.yearFraction(dates[i - 1], dates[i]);
                Utils.QL_REQUIRE(dt >= 0.0, () => "unsorted dates");
                sum += yts.discount(dates[i]) * dt;
            }
            double result = yts.discount(dates.First()) - yts.discount(dates.Last());

            return(result / sum);
        }
Пример #30
0
        public override IborIndex Clone(YieldTermStructure forwardingCurve)
        {
            if (Impl.QlObj is not global::QuantLib.OvernightIndex iborIdx)
            {
                throw new InvalidOperationException(
                          $"Implementation object reference is of type {Impl.QlObj.GetType().FullName} which is not derived from {nameof(global::QuantLib.OvernightIndex)}");
            }
            var qlObj = iborIdx.clone(forwardingCurve.GetHandle());

            if (qlObj is global::QuantLib.OvernightIndex onIdx)
            {
                return(new OvernightIndex(onIdx));
            }

            // This should never happen
            return(new IborIndex(qlObj));
        }
Пример #31
0
 public static double bps(Leg leg, YieldTermStructure discountCurve, bool includeSettlementDateFlows, Date settlementDate, Date npvDate) {
   double ret = NQuantLibcPINVOKE.CashFlows_bps__SWIG_0(Leg.getCPtr(leg), YieldTermStructure.getCPtr(discountCurve), includeSettlementDateFlows, Date.getCPtr(settlementDate), Date.getCPtr(npvDate));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Пример #32
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(YieldTermStructure obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Пример #33
0
 public static double cleanPriceFromZSpread(Bond bond, YieldTermStructure discountCurve, double zSpread, DayCounter dc, Compounding compounding, Frequency freq) {
   double ret = NQuantLibcPINVOKE.cleanPriceFromZSpread__SWIG_1(Bond.getCPtr(bond), YieldTermStructure.getCPtr(discountCurve), zSpread, DayCounter.getCPtr(dc), (int)compounding, (int)freq);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Пример #34
0
 public YieldTermStructure __deref__() {
   YieldTermStructure ret = new YieldTermStructure(NQuantLibcPINVOKE.YieldTermStructureHandle___deref__(swigCPtr), true);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Пример #35
0
 public static double atmRate(Bond bond, YieldTermStructure discountCurve) {
   double ret = NQuantLibcPINVOKE.BondFunctions_atmRate__SWIG_2(Bond.getCPtr(bond), YieldTermStructure.getCPtr(discountCurve));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Пример #36
0
 public static double atmRate(Bond bond, YieldTermStructure discountCurve, Date settlementDate, double cleanPrice) {
   double ret = NQuantLibcPINVOKE.BondFunctions_atmRate__SWIG_0(Bond.getCPtr(bond), YieldTermStructure.getCPtr(discountCurve), Date.getCPtr(settlementDate), cleanPrice);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public RelinkableYieldTermStructureHandle(YieldTermStructure arg0) : this(NQuantLibcPINVOKE.new_RelinkableYieldTermStructureHandle__SWIG_0(YieldTermStructure.getCPtr(arg0)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Пример #38
0
 public static double atmRate(Leg leg, YieldTermStructure discountCurve, bool includeSettlementDateFlows) {
   double ret = NQuantLibcPINVOKE.CashFlows_atmRate__SWIG_3(Leg.getCPtr(leg), YieldTermStructure.getCPtr(discountCurve), includeSettlementDateFlows);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public void linkTo(YieldTermStructure arg0) {
   NQuantLibcPINVOKE.RelinkableYieldTermStructureHandle_linkTo(swigCPtr, YieldTermStructure.getCPtr(arg0));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Пример #40
0
 public static double zSpread(Leg leg, double npv, YieldTermStructure arg2, DayCounter dayCounter, Compounding compounding, Frequency frequency, bool includeSettlementDateFlows, Date settlementDate) {
   double ret = NQuantLibcPINVOKE.CashFlows_zSpread__SWIG_4(Leg.getCPtr(leg), npv, YieldTermStructure.getCPtr(arg2), DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, includeSettlementDateFlows, Date.getCPtr(settlementDate));
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Пример #41
0
 public static double npv(Leg leg, YieldTermStructure discountCurve, double zSpread, DayCounter dayCounter, Compounding compounding, Frequency frequency, bool includeSettlementDateFlows) {
   double ret = NQuantLibcPINVOKE.CashFlows_npv__SWIG_2(Leg.getCPtr(leg), YieldTermStructure.getCPtr(discountCurve), zSpread, DayCounter.getCPtr(dayCounter), (int)compounding, (int)frequency, includeSettlementDateFlows);
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }