MakeCapFloor::operator shared_ptr<CapFloor>() const { VanillaSwap swap = makeVanillaSwap_; Leg leg = swap.floatingLeg(); if (firstCapletExcluded_) leg.erase(leg.begin()); // only leaves the last coupon if (asOptionlet_ && leg.size() > 1) { Leg::iterator end = leg.end(); // Sun Studio needs an lvalue leg.erase(leg.begin(), --end); } std::vector<Rate> strikeVector(1, strike_); if (strike_ == Null<Rate>()) { // temporary patch... // should be fixed for every CapFloor::Engine shared_ptr<BlackCapFloorEngine> temp = dynamic_pointer_cast<BlackCapFloorEngine>(engine_); QL_REQUIRE(temp, "cannot calculate ATM without a BlackCapFloorEngine"); Handle<YieldTermStructure> discountCurve = temp->termStructure(); strikeVector[0] = CashFlows::atmRate(leg, **discountCurve, false, discountCurve->referenceDate()); } shared_ptr<CapFloor> capFloor(new CapFloor(capFloorType_, leg, strikeVector)); capFloor->setPricingEngine(engine_); return capFloor; }
MakeYoYInflationCapFloor::operator ext::shared_ptr<YoYInflationCapFloor>() const { Date startDate; if (effectiveDate_ != Date()) { startDate = effectiveDate_; } else { Date referenceDate = Settings::instance().evaluationDate(); Date spotDate = calendar_.advance(referenceDate, fixingDays_*Days); startDate = spotDate+forwardStart_; } Date endDate = calendar_.advance(startDate,length_*Years,Unadjusted); Schedule schedule(startDate, endDate, Period(Annual), calendar_, Unadjusted, Unadjusted, // ref periods & acc periods DateGeneration::Forward, false); Leg leg = yoyInflationLeg(schedule, calendar_, index_, observationLag_) .withPaymentAdjustment(roll_) .withPaymentDayCounter(dayCounter_) .withNotionals(nominal_) ; if (firstCapletExcluded_) leg.erase(leg.begin()); // only leaves the last coupon if (asOptionlet_ && leg.size() > 1) { Leg::iterator end = leg.end(); // Sun Studio needs an lvalue leg.erase(leg.begin(), --end); } std::vector<Rate> strikeVector(1, strike_); if (strike_ == Null<Rate>()) { // ATM on the forecasting curve Handle<YieldTermStructure> fc; if (!nominalTermStructure_.empty()) { fc = nominalTermStructure_; } else { QL_REQUIRE(!index_->yoyInflationTermStructure().empty(), "no forecasting yoy term structure set for " << index_->name()); fc = index_->yoyInflationTermStructure()->nominalTermStructure(); } strikeVector[0] = CashFlows::atmRate(leg,**fc, false, fc->referenceDate()); } ext::shared_ptr<YoYInflationCapFloor> capFloor(new YoYInflationCapFloor(capFloorType_, leg, strikeVector)); capFloor->setPricingEngine(engine_); return capFloor; }