Esempio n. 1
0
 // fixed reference date, floating market data
 SwaptionVolatilityMatrix::SwaptionVolatilityMatrix(
                 const Date& refDate,
                 const Calendar& cal,
                 BusinessDayConvention bdc,
                 const std::vector<Period>& optionT,
                 const std::vector<Period>& swapT,
                 const std::vector<std::vector<Handle<Quote> > >& vols,
                 const DayCounter& dc,
                 const bool flatExtrapolation,
                 const std::vector<std::vector<Real> >& shifts)
 : SwaptionVolatilityDiscrete(optionT, swapT, refDate, cal, bdc, dc),
   volHandles_(vols), shiftValues_(shifts),
   volatilities_(vols.size(), vols.front().size()),
   shifts_(vols.size(), vols.front().size(), 0.0) {
     checkInputs(volatilities_.rows(), volatilities_.columns(),
                 shifts.size(), shifts.size() == 0 ? 0 : shifts.front().size());
     registerWithMarketData();
     if (flatExtrapolation) {
         interpolation_ =
             FlatExtrapolator2D(boost::make_shared<BilinearInterpolation>(
                 swapLengths_.begin(), swapLengths_.end(),
                 optionTimes_.begin(), optionTimes_.end(), volatilities_));
         interpolationShifts_ =
             FlatExtrapolator2D(boost::make_shared<BilinearInterpolation>(
                 swapLengths_.begin(), swapLengths_.end(),
                 optionTimes_.begin(), optionTimes_.end(), shifts_));
     } else {
         interpolation_ = BilinearInterpolation(
             swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(),
             optionTimes_.end(), volatilities_);
         interpolationShifts_ = BilinearInterpolation(
             swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(),
             optionTimes_.end(), shifts_);
     }
 }
Esempio n. 2
0
    // fixed reference date, fixed market data
    SwaptionVolatilityMatrix::SwaptionVolatilityMatrix(
                        const Date& refDate,
                        const Calendar& cal,
                        BusinessDayConvention bdc,
                        const std::vector<Period>& optionT,
                        const std::vector<Period>& swapT,
                        const Matrix& vols,
                        const DayCounter& dc,
                        const bool flatExtrapolation,
                        const VolatilityType type,
                        const Matrix& shifts)
    : SwaptionVolatilityDiscrete(optionT, swapT, refDate, cal, bdc, dc),
      volHandles_(vols.rows()), shiftValues_(vols.rows()),
      volatilities_(vols.rows(), vols.columns()),
      shifts_(shifts.rows(), shifts.columns(), 0.0), volatilityType_(type) {

        checkInputs(vols.rows(), vols.columns(), shifts.rows(), shifts.columns());

        // fill dummy handles to allow generic handle-based
        // computations later on
        for (Size i=0; i<vols.rows(); ++i) {
            volHandles_[i].resize(vols.columns());
            shiftValues_[i].resize(vols.columns());
            for (Size j=0; j<vols.columns(); ++j) {
                volHandles_[i][j] = Handle<Quote>(boost::shared_ptr<Quote>(new
                    SimpleQuote(vols[i][j])));
                shiftValues_[i][j] = shifts.rows() > 0 ? shifts[i][j] : 0.0;
            }
        }
        if (flatExtrapolation) {
            interpolation_ =
                FlatExtrapolator2D(boost::make_shared<BilinearInterpolation>(
                    swapLengths_.begin(), swapLengths_.end(),
                    optionTimes_.begin(), optionTimes_.end(), volatilities_));
            interpolationShifts_ =
                FlatExtrapolator2D(boost::make_shared<BilinearInterpolation>(
                    swapLengths_.begin(), swapLengths_.end(),
                    optionTimes_.begin(), optionTimes_.end(), shifts_));
        } else {
            interpolation_ = BilinearInterpolation(
                swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(),
                optionTimes_.end(), volatilities_);
            interpolationShifts_ = BilinearInterpolation(
                swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(),
                optionTimes_.end(), shifts_);
        }
    }