public override void setupArguments(IPricingEngineArguments args) { YoYInflationCapFloor.Arguments arguments = args as YoYInflationCapFloor.Arguments; Utils.QL_REQUIRE(arguments != null, () => "wrong argument type"); int n = yoyLeg_.Count; arguments.startDates = new List <Date>(n); arguments.fixingDates = new List <Date>(n); arguments.payDates = new List <Date>(n); arguments.accrualTimes = new List <double>(n); arguments.nominals = new List <double>(n); arguments.gearings = new List <double>(n); arguments.capRates = new List <double?>(n); arguments.floorRates = new List <double?>(n); arguments.spreads = new List <double>(n); arguments.type = type_; for (int i = 0; i < n; ++i) { YoYInflationCoupon coupon = yoyLeg_[i] as YoYInflationCoupon; Utils.QL_REQUIRE(coupon != null, () => "non-YoYInflationCoupon given"); arguments.startDates.Add(coupon.accrualStartDate()); arguments.fixingDates.Add(coupon.fixingDate()); arguments.payDates.Add(coupon.date()); // this is passed explicitly for precision arguments.accrualTimes.Add(coupon.accrualPeriod()); arguments.nominals.Add(coupon.nominal()); double spread = coupon.spread(); double gearing = coupon.gearing(); arguments.gearings.Add(gearing); arguments.spreads.Add(spread); if (type_ == CapFloorType.Cap || type_ == CapFloorType.Collar) { arguments.capRates.Add((capRates_[i] - spread) / gearing); } else { arguments.capRates.Add(null); } if (type_ == CapFloorType.Floor || type_ == CapFloorType.Collar) { arguments.floorRates.Add((floorRates_[i] - spread) / gearing); } else { arguments.floorRates.Add(null); } } }
// other public override void setupArguments(IPricingEngineArguments args) { base.setupArguments(args); YearOnYearInflationSwap.Arguments arguments = args as YearOnYearInflationSwap.Arguments; if (arguments == null) // it's a swap engine... { return; } arguments.type = type_; arguments.nominal = nominal_; List <CashFlow> fixedCoupons = fixedLeg(); arguments.fixedResetDates = arguments.fixedPayDates = new List <Date>(fixedCoupons.Count); arguments.fixedCoupons = new List <double>(fixedCoupons.Count); for (int i = 0; i < fixedCoupons.Count; ++i) { FixedRateCoupon coupon = fixedCoupons[i] as FixedRateCoupon; arguments.fixedPayDates.Add(coupon.date()); arguments.fixedResetDates.Add(coupon.accrualStartDate()); arguments.fixedCoupons.Add(coupon.amount()); } List <CashFlow> yoyCoupons = yoyLeg(); arguments.yoyResetDates = arguments.yoyPayDates = arguments.yoyFixingDates = new List <Date>(yoyCoupons.Count); arguments.yoyAccrualTimes = new List <double>(yoyCoupons.Count); arguments.yoySpreads = new List <double>(yoyCoupons.Count); arguments.yoyCoupons = new List <double?>(yoyCoupons.Count); for (int i = 0; i < yoyCoupons.Count; ++i) { YoYInflationCoupon coupon = yoyCoupons[i] as YoYInflationCoupon; arguments.yoyResetDates.Add(coupon.accrualStartDate()); arguments.yoyPayDates.Add(coupon.date()); arguments.yoyFixingDates.Add(coupon.fixingDate()); arguments.yoyAccrualTimes.Add(coupon.accrualPeriod()); arguments.yoySpreads.Add(coupon.spread()); try { arguments.yoyCoupons.Add(coupon.amount()); } catch (Exception) { arguments.yoyCoupons.Add(null); } } }
// we may watch an underlying coupon ... public CappedFlooredYoYInflationCoupon(YoYInflationCoupon underlying, double?cap = null, double?floor = null) : base(underlying.date(), underlying.nominal(), underlying.accrualStartDate(), underlying.accrualEndDate(), underlying.fixingDays(), underlying.yoyIndex(), underlying.observationLag(), underlying.dayCounter(), underlying.gearing(), underlying.spread(), underlying.referencePeriodStart, underlying.referencePeriodEnd) { underlying_ = underlying; isFloored_ = false; isCapped_ = false; setCommon(cap, floor); underlying.registerWith(update); }