//! Yield value of a basis point /*! The yield value of a one basis point change in price is * the derivative of the yield with respect to the price * multiplied by 0.01 */ public static double yieldValueBasisPoint(Leg leg, InterestRate yield, bool includeSettlementDateFlows, Date settlementDate = null, Date npvDate = null) { if (leg.empty()) { return(0.0); } if (settlementDate == null) { settlementDate = Settings.Instance.evaluationDate(); } if (npvDate == null) { npvDate = settlementDate; } double npv = CashFlows.npv(leg, yield, includeSettlementDateFlows, settlementDate, npvDate); double modifiedDuration = CashFlows.duration(leg, yield, Duration.Type.Modified, includeSettlementDateFlows, settlementDate, npvDate); double shift = 0.01; return((1.0 / (-npv * modifiedDuration)) * shift); }
//! Basis-point value /*! Obtained by setting dy = 0.0001 in the 2nd-order Taylor * series expansion. */ public static double basisPointValue(Leg leg, InterestRate yield, bool includeSettlementDateFlows, Date settlementDate = null, Date npvDate = null) { if (leg.empty()) { return(0.0); } if (settlementDate == null) { settlementDate = Settings.Instance.evaluationDate(); } if (npvDate == null) { npvDate = settlementDate; } double npv = CashFlows.npv(leg, yield, includeSettlementDateFlows, settlementDate, npvDate); double modifiedDuration = CashFlows.duration(leg, yield, Duration.Type.Modified, includeSettlementDateFlows, settlementDate, npvDate); double convexity = CashFlows.convexity(leg, yield, includeSettlementDateFlows, settlementDate, npvDate); double delta = -modifiedDuration * npv; double gamma = (convexity / 100.0) * npv; double shift = 0.0001; delta *= shift; gamma *= shift * shift; return(delta + 0.5 * gamma); }
public static double duration(Bond bond, InterestRate yield, Duration.Type type = Duration.Type.Modified, Date settlementDate = null) { if (settlementDate == null) { settlementDate = bond.settlementDate(); } Utils.QL_REQUIRE(BondFunctions.isTradable(bond, settlementDate), () => "non tradable at " + settlementDate + " (maturity being " + bond.maturityDate() + ")", QLNetExceptionEnum.NotTradableException); return(CashFlows.duration(bond.cashflows(), yield, type, false, settlementDate)); }
// converts the yield volatility into a forward price volatility private double forwardPriceVolatility() { Date bondMaturity = arguments_.redemptionDate; Date exerciseDate = arguments_.callabilityDates[0]; List <CashFlow> fixedLeg = arguments_.cashflows; // value of bond cash flows at option maturity double fwdNpv = CashFlows.npv(fixedLeg, discountCurve_, false, exerciseDate); DayCounter dayCounter = arguments_.paymentDayCounter; Frequency frequency = arguments_.frequency; // adjust if zero coupon bond (see also bond.cpp) if (frequency == Frequency.NoFrequency || frequency == Frequency.Once) { frequency = Frequency.Annual; } double fwdYtm = CashFlows.yield(fixedLeg, fwdNpv, dayCounter, Compounding.Compounded, frequency, false, exerciseDate); InterestRate fwdRate = new InterestRate(fwdYtm, dayCounter, Compounding.Compounded, frequency); double fwdDur = CashFlows.duration(fixedLeg, fwdRate, Duration.Type.Modified, false, exerciseDate); double cashStrike = arguments_.callabilityPrices[0]; dayCounter = volatility_.link.dayCounter(); Date referenceDate = volatility_.link.referenceDate(); double exerciseTime = dayCounter.yearFraction(referenceDate, exerciseDate); double maturityTime = dayCounter.yearFraction(referenceDate, bondMaturity); double yieldVol = volatility_.link.volatility(exerciseTime, maturityTime - exerciseTime, cashStrike); double fwdPriceVol = yieldVol * fwdDur * fwdYtm; return(fwdPriceVol); }