Esempio n. 1
0
        //! fixed reference date, floating market data
        public SwaptionVolatilityMatrix(
            Date referenceDate,
            Calendar calendar,
            BusinessDayConvention bdc,
            List <Period> optionTenors,
            List <Period> swapTenors,
            List <List <Handle <Quote> > > vols,
            DayCounter dayCounter,
            bool flatExtrapolation       = false,
            VolatilityType type          = VolatilityType.ShiftedLognormal,
            List <List <double> > shifts = null)
            : base(optionTenors, swapTenors, referenceDate, calendar, bdc, dayCounter)
        {
            volHandles_     = vols;
            shiftValues_    = shifts;
            volatilities_   = new Matrix(vols.Count, vols.First().Count);
            shifts_         = new Matrix(vols.Count, vols.First().Count, 0.0);
            volatilityType_ = type;
            checkInputs(volatilities_.rows(), volatilities_.columns(), shifts_.rows(), shifts_.columns());
            registerWithMarketData();

            // fill dummy handles to allow generic handle-based
            if (shiftValues_ == null)
            {
                shiftValues_ = new InitializedList <List <double> >(volatilities_.rows());
                for (int i = 0; i < volatilities_.rows(); ++i)
                {
                    shiftValues_[i] = new InitializedList <double>(volatilities_.columns());
                    for (int j = 0; j < volatilities_.columns(); ++j)
                    {
                        shiftValues_[i][j] = shifts_.rows() > 0 ? shifts_[i, j] : 0.0;
                    }
                }
            }

            if (flatExtrapolation)
            {
                interpolation_ = new FlatExtrapolator2D(new BilinearInterpolation(
                                                            swapLengths_, swapLengths_.Count,
                                                            optionTimes_, optionTimes_.Count, volatilities_));

                interpolationShifts_ = new FlatExtrapolator2D(new BilinearInterpolation(
                                                                  swapLengths_, swapLengths_.Count,
                                                                  optionTimes_, optionTimes_.Count, shifts_));
            }
            else
            {
                interpolation_ = new BilinearInterpolation(
                    swapLengths_, swapLengths_.Count,
                    optionTimes_, optionTimes_.Count,
                    volatilities_);

                interpolationShifts_ = new BilinearInterpolation(
                    swapLengths_, swapLengths_.Count,
                    optionTimes_, optionTimes_.Count,
                    shifts_);
            }
        }
Esempio n. 2
0
        //! floating reference date, fixed market data
        public SwaptionVolatilityMatrix(
            Calendar calendar,
            BusinessDayConvention bdc,
            List <Period> optionTenors,
            List <Period> swapTenors,
            Matrix vols,
            DayCounter dayCounter,
            bool flatExtrapolation = false,
            VolatilityType type    = VolatilityType.ShiftedLognormal,
            Matrix shifts          = null)

            : base(optionTenors, swapTenors, 0, calendar, bdc, dayCounter)
        {
            volHandles_     = new InitializedList <List <Handle <Quote> > >(vols.rows());
            shiftValues_    = new InitializedList <List <double> >(vols.rows());
            volatilities_   = new Matrix(vols.rows(), vols.columns());
            shifts_         = shifts ?? new Matrix(vols.rows(), vols.columns(), 0.0);
            volatilityType_ = type;
            checkInputs(volatilities_.rows(), volatilities_.columns(), shifts_.rows(), shifts_.columns());

            // fill dummy handles to allow generic handle-based
            // computations later on
            for (int i = 0; i < vols.rows(); ++i)
            {
                volHandles_[i]  = new InitializedList <Handle <Quote> >(vols.columns());
                shiftValues_[i] = new InitializedList <double>(vols.columns());
                for (int j = 0; j < vols.columns(); ++j)
                {
                    volHandles_[i][j] = new Handle <Quote>((new
                                                            SimpleQuote(vols[i, j])));
                }
            }

            if (flatExtrapolation)
            {
                interpolation_ = new FlatExtrapolator2D(new BilinearInterpolation(
                                                            swapLengths_, swapLengths_.Count,
                                                            optionTimes_, optionTimes_.Count, volatilities_));

                interpolationShifts_ = new FlatExtrapolator2D(new BilinearInterpolation(
                                                                  swapLengths_, swapLengths_.Count,
                                                                  optionTimes_, optionTimes_.Count, shifts_));
            }
            else
            {
                interpolation_ = new BilinearInterpolation(
                    swapLengths_, swapLengths_.Count,
                    optionTimes_, optionTimes_.Count,
                    volatilities_);

                interpolationShifts_ = new BilinearInterpolation(
                    swapLengths_, swapLengths_.Count,
                    optionTimes_, optionTimes_.Count,
                    shifts_);
            }
        }
Esempio n. 3
0
 public void updateInterpolators()
 {
     for (int k = 0; k < nLayers_; ++k)
     {
         transposedPoints_[k] = Matrix.transpose(points_[k]);
         Interpolation2D interpolation;
         if (k <= 4 && backwardFlat_)
         {
             interpolation = new BackwardflatLinearInterpolation(
                 optionTimes_, optionTimes_.Count,
                 swapLengths_, swapLengths_.Count,
                 transposedPoints_[k]);
         }
         else
         {
             interpolation = new BilinearInterpolation(
                 optionTimes_, optionTimes_.Count,
                 swapLengths_, swapLengths_.Count,
                 transposedPoints_[k]);
         }
         interpolators_[k] = new FlatExtrapolator2D(interpolation);
         interpolators_[k].enableExtrapolation();
     }
 }