示例#1
0
 public Cube clone(Cube o)
 {
     optionTimes_      = o.optionTimes_;
     swapLengths_      = o.swapLengths_;
     optionDates_      = o.optionDates_;
     swapTenors_       = o.swapTenors_;
     nLayers_          = o.nLayers_;
     extrapolation_    = o.extrapolation_;
     backwardFlat_     = o.backwardFlat_;
     transposedPoints_ = o.transposedPoints_;
     for (int k = 0; k < nLayers_; 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_.Add(new FlatExtrapolator2D(interpolation));
         interpolators_[k].enableExtrapolation();
     }
     setPoints(o.points_);
     return(this);
 }
示例#2
0
            public Cube(List <Date> optionDates,
                        List <Period> swapTenors,
                        List <double> optionTimes,
                        List <double> swapLengths,
                        int nLayers,
                        bool extrapolation = true,
                        bool backwardFlat  = false)
            {
                optionTimes_      = new List <double>(optionTimes);
                swapLengths_      = new List <double>(swapLengths);
                optionDates_      = new List <Date>(optionDates);
                swapTenors_       = new List <Period>(swapTenors);
                nLayers_          = nLayers;
                extrapolation_    = extrapolation;
                backwardFlat_     = backwardFlat;
                interpolators_    = new List <Interpolation2D>();
                transposedPoints_ = new List <Matrix>();

                Utils.QL_REQUIRE(optionTimes.Count > 1, () => "Cube::Cube(...): optionTimes.size()<2");
                Utils.QL_REQUIRE(swapLengths.Count > 1, () => "Cube::Cube(...): swapLengths.size()<2");

                Utils.QL_REQUIRE(optionTimes.Count == optionDates.Count, () => "Cube::Cube(...): optionTimes/optionDates mismatch");
                Utils.QL_REQUIRE(swapTenors.Count == swapLengths.Count, () => "Cube::Cube(...): swapTenors/swapLengths mismatch");

                List <Matrix> points = new InitializedList <Matrix>(nLayers_);

                for (int i = 0; i < nLayers; i++)
                {
                    points[i] = new Matrix(optionTimes_.Count, swapLengths_.Count, 0.0);
                }

                for (int k = 0; k < nLayers_; k++)
                {
                    Interpolation2D interpolation;
                    transposedPoints_.Add(Matrix.transpose(points[k]));
                    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_.Add(new FlatExtrapolator2D(interpolation));
                    interpolators_[k].enableExtrapolation();
                }
                setPoints(points);
            }
示例#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();
     }
 }