public double swaption(Swaption.Arguments arguments, double fixedRate, double range, int intervals) { Date settlement = termStructure().link.referenceDate(); DayCounter dayCounter = termStructure().link.dayCounter(); double start = dayCounter.yearFraction(settlement, arguments.floatingResetDates[0]); double w = (arguments.type == VanillaSwap.Type.Payer ? 1 : -1); List <double> fixedPayTimes = new InitializedList <double>(arguments.fixedPayDates.Count); for (int i = 0; i < fixedPayTimes.Count; ++i) { fixedPayTimes[i] = dayCounter.yearFraction(settlement, arguments.fixedPayDates[i]); } SwaptionPricingFunction function = new SwaptionPricingFunction(a(), sigma(), b(), eta(), rho(), w, start, fixedPayTimes, fixedRate, this); double upper = function.mux() + range * function.sigmax(); double lower = function.mux() - range * function.sigmax(); SegmentIntegral integrator = new SegmentIntegral(intervals); return(arguments.nominal * w * termStructure().link.discount(start) * integrator.value(function.value, lower, upper)); }
public override void setupArguments(IPricingEngineArguments args) { swap_.setupArguments(args); Swaption.Arguments arguments = args as Swaption.Arguments; if (arguments == null) { throw new ArgumentException("wrong argument type"); } arguments.swap = swap_; arguments.settlementType = settlementType_; arguments.exercise = exercise_; }
public override void addTimesTo(List <double> times) { calculate(); Swaption.Arguments args = new Swaption.Arguments(); swaption_.setupArguments(args); List <double> swaptionTimes = new DiscretizedSwaption(args, termStructure_.link.referenceDate(), termStructure_.link.dayCounter()).mandatoryTimes(); for (int i = 0; i < swaptionTimes.Count; i++) { times.Insert(times.Count, swaptionTimes[i]); } }
public DiscretizedSwaption(Swaption.Arguments args, Date referenceDate, DayCounter dayCounter) : base(new DiscretizedSwap(args, referenceDate, dayCounter), args.exercise.type(), new List <double>()) { arguments_ = args; exerciseTimes_ = new InitializedList <double>(arguments_.exercise.dates().Count); for (int i = 0; i < exerciseTimes_.Count; ++i) { exerciseTimes_[i] = dayCounter.yearFraction(referenceDate, arguments_.exercise.date(i)); } // Date adjustments can get time vectors out of synch. // Here, we try and collapse similar dates which could cause // a mispricing. for (int i = 0; i < arguments_.exercise.dates().Count; i++) { Date exerciseDate = arguments_.exercise.date(i); for (int j = 0; j < arguments_.fixedPayDates.Count; j++) { if (withinNextWeek(exerciseDate, arguments_.fixedPayDates[j]) // coupons in the future are dealt with below && arguments_.fixedResetDates[j] < referenceDate) { arguments_.fixedPayDates[j] = exerciseDate; } } for (int j = 0; j < arguments_.fixedResetDates.Count; j++) { if (withinPreviousWeek(exerciseDate, arguments_.fixedResetDates[j])) { arguments_.fixedResetDates[j] = exerciseDate; } } for (int j = 0; j < arguments_.floatingResetDates.Count; j++) { if (withinPreviousWeek(exerciseDate, arguments_.floatingResetDates[j])) { arguments_.floatingResetDates[j] = exerciseDate; } } } double lastFixedPayment = dayCounter.yearFraction(referenceDate, arguments_.fixedPayDates.Last()); double lastFloatingPayment = dayCounter.yearFraction(referenceDate, arguments_.floatingPayDates.Last()); lastPayment_ = Math.Max(lastFixedPayment, lastFloatingPayment); underlying_ = new DiscretizedSwap(arguments_, referenceDate, dayCounter); }