// Basis-point sensitivity of the cash flows. // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according to the given term structure. public static double bps(List <CashFlow> cashflows, YieldTermStructure discountCurve, Date settlementDate = null, Date npvDate = null, int exDividendDays = 0) { if (cashflows.Count == 0) { return(0.0); } if (settlementDate == null) { settlementDate = discountCurve.referenceDate(); } BPSCalculator calc = new BPSCalculator(discountCurve, npvDate); for (int i = 0; i < cashflows.Count; i++) { if (!cashflows[i].hasOccurred(settlementDate + exDividendDays)) { cashflows[i].accept(calc); } } return(basisPoint_ * calc.result()); }
//@} //! NPV of the cash flows. The NPV is the sum of the cash flows, each discounted according to the given term structure. public static double npv(List <CashFlow> cashflows, YieldTermStructure discountCurve, Date settlementDate = null, Date npvDate = null, int exDividendDays = 0) { if (cashflows.Count == 0) { return(0.0); } if (settlementDate == null) { settlementDate = discountCurve.referenceDate(); } double totalNPV = cashflows.Where(x => !x.hasOccurred(settlementDate + exDividendDays)). Sum(c => c.amount() * discountCurve.discount(c.date())); if (npvDate == null) { return(totalNPV); } else { return(totalNPV / discountCurve.discount(npvDate)); } }
//! NPV of a single cash flows public static double npv(CashFlow cashflow, YieldTermStructure discountCurve, Date settlementDate = null, Date npvDate = null, int exDividendDays = 0) { double NPV = 0.0; if (cashflow == null) { return(0.0); } if (settlementDate == null) { settlementDate = discountCurve.referenceDate(); } if (!cashflow.hasOccurred(settlementDate + exDividendDays)) { NPV = cashflow.amount() * discountCurve.discount(cashflow.date()); } if (npvDate == null) { return(NPV); } else { return(NPV / discountCurve.discount(npvDate)); } }
public double atmRate(YieldTermStructure discountCurve) { bool includeSettlementDateFlows = false; Date settlementDate = discountCurve.referenceDate(); return(CashFlows.atmRate(floatingLeg_, discountCurve, includeSettlementDateFlows, settlementDate)); }
public override void initialize(FloatingRateCoupon coupon) { coupon_ = coupon as CmsCoupon; Utils.QL_REQUIRE( coupon_ != null, () => "CMS coupon needed" ); gearing_ = coupon_.gearing(); spread_ = coupon_.spread(); fixingDate_ = coupon_.fixingDate(); paymentDate_ = coupon_.date(); SwapIndex swapIndex = coupon_.swapIndex(); rateCurve_ = swapIndex.forwardingTermStructure().link; Date today = Settings.evaluationDate(); if (paymentDate_ > today) discount_ = rateCurve_.discount(paymentDate_); else discount_ = 1.0; spreadLegValue_ = spread_ * coupon_.accrualPeriod() * discount_; if (fixingDate_ > today) { swapTenor_ = swapIndex.tenor(); VanillaSwap swap = swapIndex.underlyingSwap(fixingDate_); swapRateValue_ = swap.fairRate(); double bp = 1.0e-4; annuity_ = (swap.floatingLegBPS() / bp); int q = (int)swapIndex.fixedLegTenor().frequency(); Schedule schedule = swap.fixedSchedule(); DayCounter dc = swapIndex.dayCounter(); //DayCounter dc = coupon.dayCounter(); double startTime = dc.yearFraction(rateCurve_.referenceDate(), swap.startDate()); double swapFirstPaymentTime = dc.yearFraction(rateCurve_.referenceDate(), schedule.date(1)); double paymentTime = dc.yearFraction(rateCurve_.referenceDate(), paymentDate_); double delta = (paymentTime - startTime) / (swapFirstPaymentTime - startTime); switch (modelOfYieldCurve_) { case GFunctionFactory.YieldCurveModel.Standard: gFunction_ = GFunctionFactory.newGFunctionStandard(q, delta, swapTenor_.length()); break; case GFunctionFactory.YieldCurveModel.ExactYield: gFunction_ = GFunctionFactory.newGFunctionExactYield(coupon_); break; case GFunctionFactory.YieldCurveModel.ParallelShifts: { Handle<Quote> nullMeanReversionQuote = new Handle<Quote>(new SimpleQuote(0.0)); gFunction_ = GFunctionFactory.newGFunctionWithShifts(coupon_, nullMeanReversionQuote); } break; case GFunctionFactory.YieldCurveModel.NonParallelShifts: gFunction_ = GFunctionFactory.newGFunctionWithShifts(coupon_, meanReversion_); break; default: throw new ApplicationException("unknown/illegal gFunction type"); } vanillaOptionPricer_ = new BlackVanillaOptionPricer(swapRateValue_, fixingDate_, swapTenor_, swaptionVolatility().link); } }
// Basis-point sensitivity of the cash flows. // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according to the given term structure. public static double bps(List<CashFlow> cashflows, YieldTermStructure discountCurve, Date settlementDate = null, Date npvDate = null, int exDividendDays = 0 ) { if (cashflows.Count == 0) return 0.0; if (settlementDate == null) settlementDate = discountCurve.referenceDate(); BPSCalculator calc = new BPSCalculator(discountCurve, npvDate); for (int i = 0; i < cashflows.Count; i++) if (!cashflows[i].hasOccurred(settlementDate + exDividendDays)) cashflows[i].accept(calc); return basisPoint_ * calc.result(); }
public virtual double atmRate(YieldTermStructure discountCurve) { return(CashFlows.atmRate(yoyLeg_, discountCurve, false, discountCurve.referenceDate())); }
//! NPV of a single cash flows public static double npv(CashFlow cashflow, YieldTermStructure discountCurve, Date settlementDate = null, Date npvDate = null, int exDividendDays = 0) { double NPV = 0.0; if (cashflow == null) return 0.0; if (settlementDate == null) settlementDate = discountCurve.referenceDate(); if (!cashflow.hasOccurred(settlementDate + exDividendDays)) NPV = cashflow.amount() * discountCurve.discount(cashflow.date()); if (npvDate == null) return NPV; else return NPV / discountCurve.discount(npvDate); }
//@} //! NPV of the cash flows. The NPV is the sum of the cash flows, each discounted according to the given term structure. public static double npv(List<CashFlow> cashflows, YieldTermStructure discountCurve, Date settlementDate = null,Date npvDate = null, int exDividendDays = 0) { if (cashflows.Count == 0) return 0.0; if (settlementDate == null) settlementDate = discountCurve.referenceDate(); double totalNPV = cashflows.Where(x => !x.hasOccurred(settlementDate + exDividendDays)). Sum(c => c.amount() * discountCurve.discount(c.date())); if (npvDate == null) return totalNPV; else return totalNPV / discountCurve.discount(npvDate); }
public Date initialDate(YieldTermStructure c) { return c.referenceDate(); }
public Date initialDate(YieldTermStructure c) { return(c.referenceDate()); } // start of curve data
public Date initialDate(YieldTermStructure c) { return c.referenceDate(); } // start of curve data