public double rpv01(PiecewiseconstantHazardRate creditCurve, CdsPriceType cleanOrDirty) { double pv = 0.0; for (int i = 0; i < _nPayments; i++) { CdsCoupon c = _cds.getCoupon(i); double q = Math.Exp(-creditCurve.getRT_(c.getEffEnd())); pv += c.getYearFrac() * _paymentDF[i] * q; } if (_cds.isPayAccOnDefault()) { double accPV = 0.0; for (int i = 0; i < _nPayments; i++) { accPV += calculateSinglePeriodAccrualOnDefault(i, creditCurve); } pv += accPV; } pv /= _valuationDF; if (cleanOrDirty == CdsPriceType.CLEAN) { pv -= _cds.getAccruedYearFraction(); } return(pv); }
/** * The value of the annuity (or RPV01 - the premium leg per unit of coupon) at a specified valuation time. * The actual value of the leg is this multiplied by the notional and the fractional coupon (i.e. coupon * in basis points divided by 10,000). * <p> * If this is a spot starting CDS (effective protection start = 0) then cash flows from premium payments * and accrual-on-default are risky discounted to t=0 ('today'), then rolled forward (risk-free) to the * valuation time; if the annuity is requested clean, the accrued premium (paid at the cash-settle time) is * rolled (again risk-free) to the valuation time; the absolute value of this amount is subtracted from the * other cash flows to give the clean annuity. * <p> * If this is a forward starting CDS (effective protection start > 0), then the premium payments are again * risky discounted to t=0; if the annuity is requested clean, the accrued premium is risk-free discounted * to the effective protection start, then risky discounted to t=0 - this gives the t=0 value of the annuity * including the chance that a default occurs before protection starts. * <p> * If valuationTime > 0, the value of the annuity is rolled forward (risk-free) to that time. * To compute the Expected value of the annuity conditional on no default before the valuationTime, * one must divide this number by the survival probability to the valuationTime (for unit coupon). * * @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 cleanOrDirty the clean or dirty price * @param valuationTime the valuation time * @return 10,000 times the RPV01 (on a notional of 1) */ public double Annuity(CDS cds, PiecewiseconstantHazardRate hazard, YieldTermStructure yt, CdsPriceType cleanOrDirt) { List <CashFlow> cf = cds.FixLeg; DateTime tradedate = cds.tradedate; DateTime settlementDate = tradedate.AddDays(cds.Cashsettlement); double recoveryrate = cds.Recovery; DateTime Stepindate = tradedate.AddDays(1); OMLib.Conventions.DayCount.Actual360 dc = new OMLib.Conventions.DayCount.Actual360(); double notional = cds.Notional; double coupon = cds.PremiumRate; DateTime lastpayment = cds.formerpaymentdate; if (cf.Count() == 0) { return(0.0); } double ita = (double)365 / 360; double totalNPV = 0.0; for (int i = 0; i < cf.Count; ++i) { totalNPV += cf[i].Amount * cf[i].DiscountFactor * cf[i].Survivalprobability; } double accrualpaidondefault = calculateSinglePeriodAccrualOnDefault(cds, yt, hazard); totalNPV += ita * coupon * accrualpaidondefault * notional / yt.discount(tradedate.AddDays(3)); Calendar calendar = new UnitedStates(); return(totalNPV / yt.discount(settlementDate)); }
/** * The intrinsic annuity of a CDS portfolio (index) for a unit (initial) notional. * The value of the premium leg is this multiplied by the <b> initial</b> notional of the index * and the index coupon (as a fraction). * * @param indexCDS representation of the index cashflows (seen from today). * @param yieldCurve The current yield curves * @param intrinsicData credit curves, weights and recovery rates of the intrinsic names * @param priceType Clean or dirty * @return The normalised intrinsic annuity of a CDS portfolio (index) */ public double indexAnnuity( CDS indexCDS, YieldTermStructure yieldCurve, IntrinsicIndexDataBundle intrinsicData, CdsPriceType priceType) { return(indexAnnuity(indexCDS, yieldCurve, intrinsicData, priceType, indexCDS.getCashSettleTime())); }
/** * This is the present value of the premium leg per unit coupon, seen at the cash-settlement date. * It is equal to 10,000 times the RPV01 (Risky PV01). The actual PV of the leg is this multiplied by the * notional and the fractional spread (i.e. coupon in basis points divided by 10,000). * * @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 cleanOrDirty the clean or dirty price * @return 10,000 times the RPV01 (on a notional of 1) * @see #annuity * @see #dirtyAnnuity */ public double annuity( CDS cds, YieldTermStructure yieldCurve, PiecewiseconstantHazardRate creditCurve, CdsPriceType cleanOrDirty) { return(annuity(cds, yieldCurve, creditCurve, cleanOrDirty, cds.getCashSettleTime())); }
/** * Intrinsic (normalised) price an index from the credit curves of the individual single names. * To get the actual index value, this multiplied by the <b>initial</b> notional of the index. * * @param indexCDS analytic description of a CDS traded at a certain time * @param indexCoupon The coupon of the index (as a fraction) * @param yieldCurve The yield curve * @param intrinsicData credit curves, weights and recovery rates of the intrinsic names * @param priceType Clean or dirty price * @return The index value for a unit notional. */ public double indexPV( CDS indexCDS, double indexCoupon, YieldTermStructure yieldCurve, IntrinsicIndexDataBundle intrinsicData, CdsPriceType priceType) { double prot = indexProtLeg(indexCDS, yieldCurve, intrinsicData); double annuity = indexAnnuity(indexCDS, yieldCurve, intrinsicData, priceType); return(prot - indexCoupon * annuity); }
/** * CDS value for the payer of premiums (i.e. the buyer of protection) at the cash-settle date. * * @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 cleanOrDirty the clean or dirty price * @return the value of a unit notional payer CDS on the cash-settle date */ public double pv( CDS cds, YieldTermStructure yieldCurve, PiecewiseconstantHazardRate creditCurve, double fractionalSpread, CdsPriceType cleanOrDirty) { if (cds.getProtectionEnd() <= 0.0) { //short cut already Expired CDSs return(0.0); } // TODO check for any repeat calculations double rpv01 = annuity(cds, yieldCurve, creditCurve, cleanOrDirty); double proLeg = protectionLeg(cds, yieldCurve, creditCurve); return(proLeg - fractionalSpread * rpv01); }
/** * CDS value for the payer of premiums (i.e. the buyer of protection) at the specified valuation time. * * @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 * @param fractionalSpread the <b>fraction</b> spread * @param cleanOrDirty the clean or dirty price * @param valuationTime the valuation time, if time is zero, leg is valued today, * value often quoted for cash-settlement date * @return the value of a unit notional payer CDS at the specified valuation time */ public double pv( CDS cds, YieldTermStructure yieldCurve, PiecewiseconstantHazardRate creditCurve, double fractionalSpread, CdsPriceType cleanOrDirty, double valuationTime) { if (cds.getProtectionEnd() <= 0.0) { //short cut already Expired CDSs return(0.0); } double rpv01 = annuity(cds, yieldCurve, creditCurve, cleanOrDirty, 0.0); double proLeg = protectionLeg(cds, yieldCurve, creditCurve, 0.0); double df = Math.Exp(-yieldCurve.getRT_(valuationTime)); return((proLeg - fractionalSpread * rpv01) / df); }
/** * The intrinsic annuity of a CDS portfolio (index) for a unit (initial) notional. * The value of the premium leg is this multiplied by the <b> initial</b> notional of the index * and the index coupon (as a fraction). * * @param indexCDS representation of the index cashflows (seen from today). * @param yieldCurve The current yield curves * @param intrinsicData credit curves, weights and recovery rates of the intrinsic names * @param priceType Clean or dirty * @param valuationTime Valuation time. The leg value is calculated for today (t=0), * then rolled forward (using the risk free yield curve) to the valuation time. * This is because cash payments occur on the cash-settlement-date, which is usually * three working days after the trade date (today) * @return The intrinsic annuity of a CDS portfolio (index) */ public double indexAnnuity( CDS indexCDS, YieldTermStructure yieldCurve, IntrinsicIndexDataBundle intrinsicData, CdsPriceType priceType, double valuationTime) { int n = intrinsicData.getIndexSize(); double a = 0; for (int i = 0; i < n; i++) { if (!intrinsicData.isDefaulted(i)) { a += intrinsicData.getWeight(i) * _pricer.annuity(indexCDS, yieldCurve, intrinsicData.getCreditCurve(i), priceType, 0); } } a /= Math.Exp(-yieldCurve.getRT_(valuationTime)); return(a); }
/** * Compute the present value of the protection leg with a notional of 1, which is given by the integral * $\frac{1-R}{P(T_{v})} \int_{T_a} ^{T_b} P(t) \frac{dQ(t)}{dt} dt$ where $P(t)$ and $Q(t)$ are the discount * and survival curves respectively, $T_a$ and $T_b$ are the start and end of the protection respectively, * $T_v$ is the valuation time (all measured from $t = 0$, 'today') and $R$ is the recovery rate. * * @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 valuationTime the valuation time, if time is zero, leg is valued today, * value often quoted for cash-settlement date * @return the value of the protection leg (on a unit notional) */ public double annuity( CDS cds, YieldTermStructure yieldCurve, PiecewiseconstantHazardRate creditCurve, CdsPriceType cleanOrDirty, double valuationTime) { double pv = dirtyAnnuity(cds, yieldCurve, creditCurve); double valDF = Math.Exp(-yieldCurve.getRT_(valuationTime)); if (cleanOrDirty == CdsPriceType.CLEAN) { double csTime = cds.getCashSettleTime(); double protStart = cds.getEffectiveProtectionStart(); double csDF = valuationTime == csTime ? valDF :Math.Exp(-yieldCurve.getRT_(csTime)); double q = protStart == 0 ? 1.0 : Math.Exp(-creditCurve.getRT_(protStart)); double acc = cds.getAccruedYearFraction(); pv -= acc * csDF * q; //subtract the accrued risky discounted to today } pv /= valDF; //roll forward to valuation date return(pv); }