Exemplo n.º 1
0
        public Curve2D(TRow[] x, TCol[] y, double[,] valueOnGrids, Func <TRow, double> x2DoubleFunc, Func <TCol, double> y2DoubleFunc, Interpolation2D interpolation2D)
        {
            RowGrid      = x;
            ColGrid      = y;
            ValueOnGrids = valueOnGrids;

            _x2DoubleFunc = x2DoubleFunc;
            _y2DoubleFunc = y2DoubleFunc;
            _interpolator = interpolation2D.GetInterpolator(RowGrid.Select(_x2DoubleFunc).ToArray(), ColGrid.Select(_y2DoubleFunc).ToArray(), ValueOnGrids);
        }
Exemplo n.º 2
0
        public ImpliedVolSurface(Date valuationDate, Date[] dates, double[] strikes, double[,] values, Interpolation2D interp, String dcConvention = "Bus244", VolSurfaceType volSurfaceType = VolSurfaceType.StrikeVol)
            : base(dates, strikes, values, x => x.ToOADate(), x => x, interp)
        {
            _valuationDate = valuationDate;
            _interp        = interp;
            _surfType      = volSurfaceType;
            _dcConvention  = dcConvention;
            _dc            = dcConvention.ToDayCountImpl();

            if ((dates as ICollection <Date>).Count != values.GetLength(0) || (strikes as ICollection <double>).Count != values.GetLength(1))
            {
                throw new PricingLibraryException(string.Format("Size error for the implied volatility surface defintion"));
            }

            double[] maturityFractions = dates.Select((v, i) => _dc.CalcDayCountFraction(valuationDate, v)).ToArray();
            _interpolator = _interp.GetInterpolator(maturityFractions, strikes.Select((v, i) => v).ToArray(), ValueOnGrids);
        }