public override double value(double zSpread) { zSpread_.setValue(zSpread); double NPV = CashFlows.npv(leg_, curve_, includeSettlementDateFlows_, settlementDate_, npvDate_); return(npv_ - NPV); }
//! 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); }
public override double value(double y) { InterestRate yield = new InterestRate(y, dayCounter_, compounding_, frequency_); double NPV = CashFlows.npv(leg_, yield, includeSettlementDateFlows_, settlementDate_, npvDate_); return(npv_ - NPV); }
//! 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); }
// 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); }
public static double dirtyPrice(Bond bond, InterestRate yield, 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); double dirtyPrice = CashFlows.npv(bond.cashflows(), yield, false, settlementDate) * 100.0 / bond.notional(settlementDate); return(dirtyPrice); }
public override void calculate() { // validate args for Black engine Utils.QL_REQUIRE(arguments_.putCallSchedule.Count == 1, () => "Must have exactly one call/put date to use Black Engine"); Date settle = arguments_.settlementDate; Date exerciseDate = arguments_.callabilityDates[0]; Utils.QL_REQUIRE(exerciseDate >= settle, () => "must have exercise Date >= settlement Date"); List <CashFlow> fixedLeg = arguments_.cashflows; double value = CashFlows.npv(fixedLeg, discountCurve_, false, settle); double npv = CashFlows.npv(fixedLeg, discountCurve_, false, discountCurve_.link.referenceDate()); double fwdCashPrice = (value - spotIncome()) / discountCurve_.link.discount(exerciseDate); double cashStrike = arguments_.callabilityPrices[0]; Option.Type type = (arguments_.putCallSchedule[0].type() == Callability.Type.Call ? Option.Type.Call : Option.Type.Put); double priceVol = forwardPriceVolatility(); double exerciseTime = volatility_.link.dayCounter().yearFraction( volatility_.link.referenceDate(), exerciseDate); double embeddedOptionValue = Utils.blackFormula(type, cashStrike, fwdCashPrice, priceVol * Math.Sqrt(exerciseTime)); if (type == Option.Type.Call) { results_.value = npv - embeddedOptionValue; results_.settlementValue = value - embeddedOptionValue; } else { results_.value = npv + embeddedOptionValue; results_.settlementValue = value + embeddedOptionValue; } }
public static double cleanPrice(Bond bond, YieldTermStructure discount, double zSpread, DayCounter dayCounter, Compounding compounding, Frequency frequency, 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); double dirtyPrice = CashFlows.npv(bond.cashflows(), discount, zSpread, dayCounter, compounding, frequency, false, settlementDate) * 100.0 / bond.notional(settlementDate); return(dirtyPrice - bond.accruedAmount(settlementDate)); }