InterpolatedYoYOptionletStripper<Interpolator1D>::
    ObjectiveFunction::ObjectiveFunction(
                   YoYInflationCapFloor::Type type,
                   Real slope,
                   Rate K,
                   Period &lag,
                   Natural fixingDays,
                   boost::shared_ptr<YoYInflationIndex> anIndex,
                   const boost::shared_ptr<YoYCapFloorTermPriceSurface> &surf,
                   const boost::shared_ptr<YoYInflationCapFloorEngine> &p,
                   Real priceToMatch)
    : slope_(slope), K_(K), frequency_(anIndex->frequency()),
      indexIsInterpolated_(anIndex->interpolated()),
      capfloor_(MakeYoYInflationCapFloor(type,
            (Size)std::floor(0.5+surf->timeFromReference(surf->minMaturity())),
                                         surf->calendar(), anIndex, lag, K)
                .withNominal(10000.0) ),
      priceToMatch_(priceToMatch), surf_(surf), p_(p) {

        tvec_ = std::vector<Time>(2);
        vvec_ = std::vector<Volatility>(2);
        dvec_ = std::vector<Date>(2);
        lag_ = surf_->observationLag();
        capfloor_ =
            MakeYoYInflationCapFloor(type,
                (Size)std::floor(0.5+surf->timeFromReference(surf->minMaturity())),
                                     surf->calendar(), anIndex, lag, K)
            .withNominal(10000.0) ;

        // shortest time available from price surface
        dvec_[0] = surf_->baseDate();
        dvec_[1] = surf_->minMaturity() +
                   Period(7, Days);
        tvec_[0] = surf_->dayCounter().yearFraction(surf_->referenceDate(),
                                                    dvec_[0] );
        tvec_[1] = surf_->dayCounter().yearFraction(surf_->referenceDate(),
                                                    dvec_[1]);

        Size n = (Size)std::floor(0.5 + surf->timeFromReference(surf_->minMaturity()));
        QL_REQUIRE( n > 0,
                    "first maturity in price surface not > 0: "
                    << n);

        capfloor_.setPricingEngine(p_);
        // pricer already setup just need to do the volatility surface each time
    }
    YoYOptionletHelper::YoYOptionletHelper(
                  const Handle<Quote>& price,
                  Real notional,
                  YoYInflationCapFloor::Type capFloorType,
                  Period &lag,
                  const DayCounter& yoyDayCounter,
                  const Calendar& paymentCalendar,
                  Natural fixingDays,
                  const ext::shared_ptr<YoYInflationIndex>& index,
                  Rate strike, Size n,
                  const ext::shared_ptr<YoYInflationCapFloorEngine> &pricer)
    : BootstrapHelper<YoYOptionletVolatilitySurface>(price),
      notional_(notional), capFloorType_(capFloorType), lag_(lag),
      fixingDays_(fixingDays), index_(index), strike_(strike), n_(n),
      yoyDayCounter_(yoyDayCounter), calendar_(paymentCalendar),
      pricer_(pricer) {

        // build the instrument to reprice (only need do this once)
        yoyCapFloor_ = ext::make_shared<YoYInflationCapFloor>(
                 
                     MakeYoYInflationCapFloor(capFloorType_, n_, calendar_,
                                              index_, lag_, strike_)
                    .withNominal(notional)
                    .withFixingDays(fixingDays_)
                    .withPaymentDayCounter(yoyDayCounter_)
                                          );
        // dates already build in lag of index/instrument
        // these are the dates of the values of the index
        // that fix the capfloor
          earliestDate_ = ext::dynamic_pointer_cast<YoYInflationCoupon>(
              yoyCapFloor_->yoyLeg().front())->fixingDate();
          latestDate_ = ext::dynamic_pointer_cast<YoYInflationCoupon>(
              yoyCapFloor_->yoyLeg().back())->fixingDate();

        // each reprice is resetting the inflation surf in the
        // pricer... so set the pricer
        yoyCapFloor_->setPricingEngine(pricer_);
        // haven't yet set the vol (term structure = surface)
    }