public YearOnYearInflationSwap( Type type, double nominal, Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount, Schedule yoySchedule, YoYInflationIndex yoyIndex, Period observationLag, double spread, DayCounter yoyDayCount, Calendar paymentCalendar, // inflation index does not have a calendar BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing) : base(2) { type_ = type; nominal_ = nominal; fixedSchedule_ = fixedSchedule; fixedRate_ = fixedRate; fixedDayCount_ = fixedDayCount; yoySchedule_ = yoySchedule; yoyIndex_ = yoyIndex; observationLag_ = observationLag; spread_ = spread; yoyDayCount_ = yoyDayCount; paymentCalendar_ = paymentCalendar; paymentConvention_ = paymentConvention; // N.B. fixed leg gets its calendar from the schedule! List<CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule_) .withCouponRates(fixedRate_, fixedDayCount_) // Simple compounding by default .withNotionals(nominal_) .withPaymentAdjustment(paymentConvention_); List<CashFlow> yoyLeg = new yoyInflationLeg(yoySchedule_, paymentCalendar_, yoyIndex_, observationLag_) .withSpreads(spread_) .withPaymentDayCounter(yoyDayCount_) .withNotionals(nominal_) .withPaymentAdjustment(paymentConvention_); yoyLeg.ForEach((i, x) => x.registerWith(update)); legs_[0] = fixedLeg; legs_[1] = yoyLeg; if (type_ == Type.Payer) { payer_[0] = -1.0; payer_[1] = +1.0; } else { payer_[0] = +1.0; payer_[1] = -1.0; } }
public List<CashFlow> makeYoYCapFlooredLeg(int which, Date startDate, int length, List<double> caps, List<double> floors, double volatility, double gearing = 1.0, double spread = 0.0) { Handle<YoYOptionletVolatilitySurface> vol = new Handle<YoYOptionletVolatilitySurface>( new ConstantYoYOptionletVolatility(volatility, settlementDays, calendar, convention, dc, observationLag, frequency, iir.interpolated())); YoYInflationCouponPricer pricer = null; switch (which) { case 0: pricer = new BlackYoYInflationCouponPricer(vol); break; case 1: pricer = new UnitDisplacedBlackYoYInflationCouponPricer(vol); break; case 2: pricer = new BachelierYoYInflationCouponPricer(vol); break; default: Assert.Fail("unknown coupon pricer request: which = "+which +"should be 0=Black,1=DD,2=Bachelier"); break; } InitializedList<double> gearingVector = new InitializedList<double>(length, gearing); InitializedList<double> spreadVector = new InitializedList<double>(length, spread); YoYInflationIndex ii = iir as YoYInflationIndex; Date endDate = calendar.advance(startDate,new Period(length,TimeUnit.Years),BusinessDayConvention.Unadjusted); Schedule schedule = new Schedule(startDate, endDate, new Period(frequency), calendar, BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,// ref periods & acc periods DateGeneration.Rule.Forward, false); List<CashFlow> yoyLeg = new yoyInflationLeg(schedule, calendar, ii, observationLag) .withPaymentDayCounter(dc) .withGearings(gearingVector) .withSpreads(spreadVector) .withCaps(caps) .withFloors(floors) .withNotionals(nominals) .withPaymentAdjustment(convention); for(int i=0; i<yoyLeg.Count; i++) { ((YoYInflationCoupon)(yoyLeg[i])).setPricer(pricer); } //setCouponPricer(iborLeg, pricer); return yoyLeg; }