public override void addTimesTo(List <double> times) { calculate(); CapFloor.Arguments args = new CapFloor.Arguments(); cap_.setupArguments(args); List <double> capTimes = new DiscretizedCapFloor(args, termStructure_.link.referenceDate(), termStructure_.link.dayCounter()).mandatoryTimes(); for (int i = 0; i < capTimes.Count; i++) { times.Insert(times.Count, capTimes[i]); } }
public DiscretizedCapFloor(CapFloor.Arguments args, Date referenceDate, DayCounter dayCounter) { arguments_ = args; startTimes_ = new InitializedList <double>(args.startDates.Count); for (int i = 0; i < startTimes_.Count; ++i) { startTimes_[i] = dayCounter.yearFraction(referenceDate, args.startDates[i]); } endTimes_ = new InitializedList <double>(args.endDates.Count); for (int i = 0; i < endTimes_.Count; ++i) { endTimes_[i] = dayCounter.yearFraction(referenceDate, args.endDates[i]); } }
public override void setupArguments(IPricingEngineArguments args) { CapFloor.Arguments arguments = args as CapFloor.Arguments; if (arguments == null) { throw new ArgumentException("wrong argument type"); } int n = floatingLeg_.Count; arguments.startDates = new InitializedList <Date>(n); arguments.fixingDates = new InitializedList <Date>(n); arguments.endDates = new InitializedList <Date>(n); arguments.accrualTimes = new InitializedList <double>(n); arguments.forwards = new InitializedList <double?>(n); arguments.nominals = new InitializedList <double>(n); arguments.gearings = new InitializedList <double>(n); arguments.capRates = new InitializedList <double?>(n); arguments.floorRates = new InitializedList <double?>(n); arguments.spreads = new InitializedList <double>(n); arguments.type = type_; Date today = Settings.evaluationDate(); for (int i = 0; i < n; ++i) { FloatingRateCoupon coupon = floatingLeg_[i] as FloatingRateCoupon; if (coupon == null) { throw new ArgumentException("non-FloatingRateCoupon given"); } arguments.startDates[i] = coupon.accrualStartDate(); arguments.fixingDates[i] = coupon.fixingDate(); arguments.endDates[i] = coupon.date(); // this is passed explicitly for precision arguments.accrualTimes[i] = coupon.accrualPeriod(); // this is passed explicitly for precision... if (arguments.endDates[i] >= today) { // ...but only if needed arguments.forwards[i] = coupon.adjustedFixing; } else { arguments.forwards[i] = null; } arguments.nominals[i] = coupon.nominal(); double spread = coupon.spread(); double gearing = coupon.gearing(); arguments.gearings[i] = gearing; arguments.spreads[i] = spread; if (type_ == CapFloorType.Cap || type_ == CapFloorType.Collar) { arguments.capRates[i] = (capRates_[i] - spread) / gearing; } else { arguments.capRates[i] = null; } if (type_ == CapFloorType.Floor || type_ == CapFloorType.Collar) { arguments.floorRates[i] = (floorRates_[i] - spread) / gearing; } else { arguments.floorRates[i] = null; } } }