public List <CashFlow> cashFlows(double amount) { Date refDate = index_.forwardingTermStructure().link.referenceDate(); Schedule schedule = new Schedule(refDate, refDate + new Period(index_.tenor().length() * size_, index_.tenor().units()), index_.tenor(), index_.fixingCalendar(), index_.businessDayConvention(), index_.businessDayConvention(), DateGeneration.Rule.Forward, false); IborLeg cashflows = (IborLeg) new IborLeg(schedule, index_) .withFixingDays(index_.fixingDays()) .withPaymentDayCounter(index_.dayCounter()) .withNotionals(amount) .withPaymentAdjustment(index_.businessDayConvention()); return(cashflows.value()); }
public CapHelper(Period length, Handle <Quote> volatility, IborIndex index, // data for ATM swap-rate calculation Frequency fixedLegFrequency, DayCounter fixedLegDayCounter, bool includeFirstSwaplet, Handle <YieldTermStructure> termStructure, bool calibrateVolatility /*= false*/) : base(volatility, termStructure, calibrateVolatility) { Period indexTenor = index.tenor(); double fixedRate = 0.04; // dummy value Date startDate, maturity; if (includeFirstSwaplet) { startDate = termStructure.link.referenceDate(); maturity = termStructure.link.referenceDate() + length; } else { startDate = termStructure.link.referenceDate() + indexTenor; maturity = termStructure.link.referenceDate() + length; } IborIndex dummyIndex = new IborIndex("dummy", indexTenor, index.fixingDays(), index.currency(), index.fixingCalendar(), index.businessDayConvention(), index.endOfMonth(), termStructure.link.dayCounter(), termStructure); List <double> nominals = new InitializedList <double>(1, 1.0); Schedule floatSchedule = new Schedule(startDate, maturity, index.tenor(), index.fixingCalendar(), index.businessDayConvention(), index.businessDayConvention(), DateGeneration.Rule.Forward, false); List <CashFlow> floatingLeg; IborLeg iborLeg = (IborLeg) new IborLeg(floatSchedule, index) .withFixingDays(0) .withNotionals(nominals) .withPaymentAdjustment(index.businessDayConvention()); floatingLeg = iborLeg.value(); Schedule fixedSchedule = new Schedule(startDate, maturity, new Period(fixedLegFrequency), index.fixingCalendar(), BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted, DateGeneration.Rule.Forward, false); List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule) .withCouponRates(fixedRate, fixedLegDayCounter) .withNotionals(nominals) .withPaymentAdjustment(index.businessDayConvention()); Swap swap = new Swap(floatingLeg, fixedLeg); swap.setPricingEngine(new DiscountingSwapEngine(termStructure)); double bp = 1.0e-4; double fairRate = fixedRate - (double)(swap.NPV() / (swap.legBPS(1) / bp)); List <double> exerciceRate = new InitializedList <double>(1, fairRate); cap_ = new Cap(floatingLeg, exerciceRate); marketValue_ = blackPrice(volatility_.link.value()); }