Пример #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 = 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_   = new_grid.Clone();
        }
 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 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));
        }
Пример #4
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_   = new_grid.Clone();
        }