Beispiel #1
0
        public void regrid(Vector new_grid, Func <double, double> func)
        {
            Vector transformed_grid = new Vector(grid_.Count);

            for (int i = 0; i < grid_.Count; i++)
            {
                transformed_grid[i] = func(grid_[i]);
            }

            CubicInterpolation priceSpline = new CubicInterpolation(transformed_grid, transformed_grid.Count, values_,
                                                                    CubicInterpolation.DerivativeApprox.Spline, false,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);

            priceSpline.update();

            Vector newValues = (Vector)new_grid.Clone();

            for (int i = 0; i < grid_.Count; i++)
            {
                newValues[i] = func(newValues[i]);
            }

            for (int j = 0; j < grid_.Count; j++)
            {
                newValues[j] = priceSpline.value(newValues[j], true);
            }

            values_ = newValues;
            grid_   = (Vector)new_grid.Clone();
        }
Beispiel #2
0
 private void interpolate()
 {
     interpolation_ = new CubicInterpolation(optionTimes_, optionTimes_.Count, vols_,
                                             CubicInterpolation.DerivativeApprox.Spline, false,
                                             CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                             CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);
 }
 public Cubic(CubicInterpolation.DerivativeApprox da, bool monotonic, 
     CubicInterpolation.BoundaryCondition leftCondition, double leftConditionValue,
     CubicInterpolation.BoundaryCondition rightCondition, double rightConditionValue)
 {
     da_ = da;
     monotonic_ = monotonic;
     leftType_ = leftCondition;
     rightType_ = rightCondition;
     leftValue_ = leftConditionValue;
     rightValue_ = rightConditionValue;
 }
      public override double value(double x, double y) 
      {
         List<double> section = new InitializedList<double>( splines_.Count );
         for (int i=0; i<splines_.Count; i++)
            section[i]=splines_[i].value(x,true);

         CubicInterpolation spline = new CubicInterpolation(this.yBegin_, this.ySize_, section,
                                                            CubicInterpolation.DerivativeApprox.Spline, false,
                                                            CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                                            CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);
         return spline.value(y,true);
      }
        public override double value(double x, double y)
        {
            List <double> section = new InitializedList <double>(splines_.Count);

            for (int i = 0; i < splines_.Count; i++)
            {
                section[i] = splines_[i].value(x, true);
            }

            CubicInterpolation spline = new CubicInterpolation(this.yBegin_, this.ySize_, section,
                                                               CubicInterpolation.DerivativeApprox.Spline, false,
                                                               CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                                               CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);

            return(spline.value(y, true));
        }
Beispiel #6
0
        public void regrid(Vector new_grid)
        {
            CubicInterpolation priceSpline = new CubicInterpolation(grid_, grid_.Count, values_,
                                                                    CubicInterpolation.DerivativeApprox.Spline, false,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);

            priceSpline.update();
            Vector newValues = new Vector(new_grid.Count);

            for (int i = 0; i < new_grid.Count; i++)
            {
                newValues[i] = priceSpline.value(new_grid[i], true);
            }

            values_ = newValues;
            grid_   = (Vector)new_grid.Clone();
        }
        public CubicInterpolationImpl(List<double> xBegin, int size, List<double> yBegin,
            CubicInterpolation.DerivativeApprox da,
            bool monotonic,
            CubicInterpolation.BoundaryCondition leftCondition,
            double leftConditionValue,
            CubicInterpolation.BoundaryCondition rightCondition,
            double rightConditionValue)
            : base(xBegin, size, yBegin)
        {
            da_ = da;
            monotonic_ = monotonic;
            leftType_ = leftCondition;
            rightType_ = rightCondition;
            leftValue_ = leftConditionValue;
            rightValue_ = rightConditionValue;

            // coefficients
            primitiveConst_ = new InitializedList<double>(size - 1);
            a_ = new InitializedList<double>(size - 1);
            b_ = new InitializedList<double>(size - 1);
            c_ = new InitializedList<double>(size - 1);
            monotonicityAdjustments_ = new InitializedList<bool>(size);
        }
 // private CoefficientHolder coeffs_;
 public CubicInterpolation(List<double> xBegin, int size, List<double> yBegin,
     CubicInterpolation.DerivativeApprox da,
     bool monotonic,
     CubicInterpolation.BoundaryCondition leftCond,
     double leftConditionValue,
     CubicInterpolation.BoundaryCondition rightCond,
     double rightConditionValue)
 {
     impl_ = new CubicInterpolationImpl(xBegin, size, yBegin,
                                        da, monotonic,
                                        leftCond, leftConditionValue,
                                        rightCond, rightConditionValue);
     impl_.update();
     // coeffs_ = boost::dynamic_pointer_cast<detail::CoefficientHolder>(impl_);
 }
Beispiel #9
0
        public void regrid(Vector new_grid)
        {
            CubicInterpolation priceSpline = new CubicInterpolation(grid_, grid_.Count, values_,
                                                                    CubicInterpolation.DerivativeApprox.Spline, false,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);
            priceSpline.update();
            Vector newValues = new Vector(new_grid.Count);

            for (int i = 0; i < new_grid.Count; i++)
                newValues[i] = priceSpline.value(new_grid[i], true);

            values_ = newValues;
            grid_ = (Vector)new_grid.Clone();
        }
Beispiel #10
0
        public void regrid(Vector new_grid, Func<double, double> func)
        {
            Vector transformed_grid = new Vector(grid_.Count);

            for (int i = 0; i < grid_.Count; i++)
                transformed_grid[i] = func(grid_[i]);

            CubicInterpolation priceSpline = new CubicInterpolation(transformed_grid, transformed_grid.Count, values_,
                                                                    CubicInterpolation.DerivativeApprox.Spline, false,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                                                    CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);
            priceSpline.update();

            Vector newValues = (Vector)new_grid.Clone();

            for (int i = 0; i < grid_.Count; i++)
                newValues[i] = func(newValues[i]);

            for (int j = 0; j < grid_.Count; j++)
                newValues[j] = priceSpline.value(newValues[j], true);

            values_ = newValues;
            grid_ = (Vector)new_grid.Clone();
        }