30 bool withinPreviousWeek(
const Date& d1,
const Date& d2) {
return d2 >= d1 - 7 && d2 <= d1; }
32 bool withinNextWeek(
const Date& d1,
const Date& d2) {
return d2 >= d1 && d2 <= d1 + 7; }
34 bool withinOneWeek(
const Date& d1,
const Date& d2) {
35 return withinPreviousWeek(d1, d2) || withinNextWeek(d1, d2);
40 const Date& referenceDate,
50 std::vector<CouponAdjustment> fixedCouponAdjustments;
51 std::vector<CouponAdjustment> floatingCouponAdjustments;
54 fixedCouponAdjustments, floatingCouponAdjustments);
61 Time lastFixedPayment =
63 Time lastFloatingPayment =
65 lastPayment_ = std::max(lastFixedPayment, lastFloatingPayment);
68 ext::make_shared<DiscretizedSwap>(snappedArgs, referenceDate, dayCounter,
69 fixedCouponAdjustments, floatingCouponAdjustments);
79 const Date& referenceDate,
82 std::vector<CouponAdjustment>& fixedCouponAdjustments,
83 std::vector<CouponAdjustment>& floatingCouponAdjustments) {
85 std::vector<Date> fixedDates = args.
swap->fixedSchedule().dates();
86 std::vector<Date> floatDates = args.
swap->floatingSchedule().dates();
88 fixedCouponAdjustments.resize(args.
swap->fixedLeg().size(),
90 floatingCouponAdjustments.resize(args.
swap->floatingLeg().size(),
93 for (
const auto& exerciseDate : args.
exercise->dates()) {
94 for (
Size j = 0; j < fixedDates.size() - 1; j++) {
95 auto unadjustedDate = fixedDates[j];
96 if (exerciseDate != unadjustedDate && withinOneWeek(exerciseDate, unadjustedDate)) {
97 fixedDates[j] = exerciseDate;
98 if (withinPreviousWeek(exerciseDate, unadjustedDate))
103 for (
Size j = 0; j < floatDates.size() - 1; j++) {
104 auto unadjustedDate = floatDates[j];
105 if (exerciseDate != unadjustedDate && withinOneWeek(exerciseDate, unadjustedDate)) {
106 floatDates[j] = exerciseDate;
107 if (withinPreviousWeek(exerciseDate, unadjustedDate))
113 Schedule snappedFixedSchedule(fixedDates);
114 Schedule snappedFloatSchedule(floatDates);
116 auto snappedSwap = ext::make_shared<VanillaSwap>(
117 args.
swap->type(), args.
swap->nominal(), snappedFixedSchedule, args.
swap->fixedRate(),
118 args.
swap->fixedDayCount(), snappedFloatSchedule, args.
swap->iborIndex(),
119 args.
swap->spread(), args.
swap->floatingDayCount(), args.
swap->paymentConvention());
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Discretized asset class used by numerical methods.
const ext::shared_ptr< Lattice > & method() const
Discretized option on a given asset.
std::vector< Time > exerciseTimes_
void reset(Size size) override
ext::shared_ptr< DiscretizedAsset > underlying_
Swaption::arguments arguments_
DiscretizedSwaption(const Swaption::arguments &, const Date &referenceDate, const DayCounter &dayCounter)
static void prepareSwaptionWithSnappedDates(const Swaption::arguments &args, const Date &referenceDate, const DayCounter &dayCounter, PricingEngine::arguments &snappedArgs, std::vector< CouponAdjustment > &fixedCouponAdjustments, std::vector< CouponAdjustment > &floatingCouponAdjustments)
void reset(Size size) override
std::vector< Date > fixedPayDates
std::vector< Date > floatingPayDates
ext::shared_ptr< Exercise > exercise
Arguments for swaption calculation
ext::shared_ptr< FixedVsFloatingSwap > swap
Settlement::Method settlementMethod
Settlement::Type settlementType
void setupArguments(PricingEngine::arguments *) const override
Discretized swaption class.
Coupon paying a fixed annual rate.
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container