public OvernightIndexedSwap value() { Date startDate; if (effectiveDate_ != null) { startDate = effectiveDate_; } else { Date refDate = Settings.evaluationDate(); // if the evaluation date is not a business day // then move to the next business day refDate = calendar_.adjust(refDate); Date spotDate = calendar_.advance(refDate, new Period(settlementDays_, TimeUnit.Days)); startDate = spotDate + forwardStart_; if (forwardStart_.length() < 0) { startDate = calendar_.adjust(startDate, BusinessDayConvention.Preceding); } else { startDate = calendar_.adjust(startDate, BusinessDayConvention.Following); } } // OIS end of month default bool usedEndOfMonth = isDefaultEOM_ ? calendar_.isEndOfMonth(startDate) : endOfMonth_; Date endDate = terminationDate_; if (endDate == null) { if (usedEndOfMonth) { endDate = calendar_.advance(startDate, swapTenor_, BusinessDayConvention.ModifiedFollowing, usedEndOfMonth); } else { endDate = startDate + swapTenor_; } } Schedule schedule = new Schedule(startDate, endDate, new Period(paymentFrequency_), calendar_, BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing, rule_, usedEndOfMonth); double?usedFixedRate = fixedRate_; if (fixedRate_ == null) { OvernightIndexedSwap temp = new OvernightIndexedSwap(type_, nominal_, schedule, 0.0, // fixed rate fixedDayCount_, overnightIndex_, overnightSpread_); if (engine_ == null) { Handle <YieldTermStructure> disc = overnightIndex_.forwardingTermStructure(); Utils.QL_REQUIRE(!disc.empty(), () => "null term structure set to this instance of " + overnightIndex_.name()); bool includeSettlementDateFlows = false; IPricingEngine engine = new DiscountingSwapEngine(disc, includeSettlementDateFlows); temp.setPricingEngine(engine); } else { temp.setPricingEngine(engine_); } usedFixedRate = temp.fairRate(); } OvernightIndexedSwap ois = new OvernightIndexedSwap(type_, nominal_, schedule, usedFixedRate.Value, fixedDayCount_, overnightIndex_, overnightSpread_); if (engine_ == null) { Handle <YieldTermStructure> disc = overnightIndex_.forwardingTermStructure(); bool includeSettlementDateFlows = false; IPricingEngine engine = new DiscountingSwapEngine(disc, includeSettlementDateFlows); ois.setPricingEngine(engine); } else { ois.setPricingEngine(engine_); } return(ois); }
public override double swapletRate() { OvernightIndex index = coupon_.index() as OvernightIndex; List <Date> fixingDates = coupon_.fixingDates(); List <double> dt = coupon_.dt(); int n = dt.Count(); int i = 0; double compoundFactor = 1.0; // already fixed part Date today = Settings.evaluationDate(); while (fixingDates[i] < today && i < n) { // rate must have been fixed double pastFixing = IndexManager.instance().getHistory( index.name()).value()[fixingDates[i]]; if (pastFixing == default(double)) { throw new ApplicationException("Missing " + index.name() + " fixing for " + fixingDates[i].ToString()); } compoundFactor *= (1.0 + pastFixing * dt[i]); ++i; } // today is a border case if (fixingDates[i] == today && i < n) { // might have been fixed try { double pastFixing = IndexManager.instance().getHistory( index.name()).value()[fixingDates[i]]; if (pastFixing != default(double)) { compoundFactor *= (1.0 + pastFixing * dt[i]); ++i; } else { ; // fall through and forecast } } catch (Exception e) { ; // fall through and forecast } } // forward part using telescopic property in order // to avoid the evaluation of multiple forward fixings if (i < n) { Handle <YieldTermStructure> curve = index.forwardingTermStructure(); if (curve.empty()) { throw new ArgumentException("null term structure set to this instance of" + index.name()); } List <Date> dates = coupon_.valueDates(); double startDiscount = curve.link.discount(dates[i]); double endDiscount = curve.link.discount(dates[n]); compoundFactor *= startDiscount / endDiscount; } double rate = (compoundFactor - 1.0) / coupon_.accrualPeriod(); return(coupon_.gearing() * rate + coupon_.spread()); }
public OvernightIndexedSwap value() { Calendar calendar = overnightIndex_.fixingCalendar(); Date startDate; if (effectiveDate_ != null) { startDate = effectiveDate_; } else { Date referenceDate = Settings.evaluationDate(); Date spotDate = calendar.advance(referenceDate, new Period(fixingDays_, TimeUnit.Days)); startDate = spotDate + forwardStart_; } Date endDate; if (terminationDate_ != null) { endDate = terminationDate_; } else { if (endOfMonth_) { endDate = calendar.advance(startDate, swapTenor_, BusinessDayConvention.ModifiedFollowing, endOfMonth_); } else { endDate = startDate + swapTenor_; } } Schedule schedule = new Schedule(startDate, endDate, new Period(paymentFrequency_), calendar, BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing, rule_, endOfMonth_); double?usedFixedRate = fixedRate_; if (fixedRate_ == null) { if (overnightIndex_.forwardingTermStructure().empty()) { throw new ApplicationException("null term structure set to this instance of " + overnightIndex_.name()); } OvernightIndexedSwap temp = new OvernightIndexedSwap(type_, nominal_, schedule, 0.0, // fixed rate fixedDayCount_, overnightIndex_, overnightSpread_); // ATM on the forecasting curve //bool includeSettlementDateFlows = false; temp.setPricingEngine(new DiscountingSwapEngine( overnightIndex_.forwardingTermStructure())); usedFixedRate = temp.fairRate(); } OvernightIndexedSwap ois = new OvernightIndexedSwap(type_, nominal_, schedule, usedFixedRate.Value, fixedDayCount_, overnightIndex_, overnightSpread_); ois.setPricingEngine(engine_); return(ois); }