/// <summary> /// Sets the interpolated curve. /// </summary> public void SetInterpolatedCurve() { int n1 = NodalExpiries.Length; if (n1 == 0) { return; } int n2 = NodalExpiries[0].Strikes.Length; if (n2 <= 1) { return; } var rows = new double[n1]; var cols = new double[n2]; var vols = new double[n1, n2]; PopulateArrays(ref rows, ref cols, ref vols); var mvols = new Matrix(vols); var linInterp = new LinearInterpolation(); var qrWing = new WingModelInterpolation(); var interpCurve = new ExtendedInterpolatedSurface(rows, cols, mvols, linInterp, qrWing); InterpCurve = interpCurve; }
public void TestExtendedWingInterpolatedSurface2() { var interpCurve = new ExtendedInterpolatedSurface(_rows, _strikes, VVols, new LinearInterpolation(), new WingModelInterpolation()) { Forward = 3.50, Spot = 3.50 }; IPoint point2D = new Point2D(0.1, 0.2); Console.WriteLine(interpCurve.Value(point2D)); point2D = new Point2D(0.2, 0.4); Console.WriteLine(interpCurve.Value(point2D)); point2D = new Point2D(0.35, 0.6); Console.WriteLine(interpCurve.Value(point2D)); }
/// <summary> /// Fits this instance. /// </summary> public void Fit(VolatilitySurface surface, double strike, DateTime expiry) { // fit in expiry direction double y = strike; double x = (expiry.Subtract(surface.Date)).Days / 365.0; ExtendedInterpolatedSurface interpCurve = surface.InterpCurve; IPoint point = new Point2D(x, y); interpCurve.Value(point); IInterpolation model = interpCurve.GetYAxisInterpolatingFunction(); var wing = (WingModelInterpolation)model; //Assign params; WingParams = wing.WingParameters; }
/// <summary> /// Gets the vol at. /// </summary> /// <param name="stock"></param> /// <param name="expiry">The expiry.</param> /// <param name="moneyness">The moneyness.</param> /// <returns></returns> public double GetVolAt(IStock stock, DateTime expiry, double moneyness) { DateTime date0 = ((Stock)stock).Date; double fwd = ((Stock)stock).GetForward(date0, expiry); double y = fwd * moneyness; double x = expiry.Subtract(date0).Days / 365.0; IPoint point = new Point2D(x, y); stock.VolatilitySurface.SetInterpolatedCurve(); ExtendedInterpolatedSurface interpCurve = stock.VolatilitySurface.GetInterpolatedCurve(); interpCurve.Forward = fwd; interpCurve.Spot = Convert.ToDouble(((Stock)stock).Spot); var vol = interpCurve.Value(point); return(vol); }
public void TestExtendedInterpolatedSurface2() { var interpCurve = new ExtendedInterpolatedSurface(_rows, _pointCoords, VMatrix, new LinearInterpolation(), new LinearInterpolation()); for (int i = 0; i < interpCurve.GetDiscreteSpace().GetPointList().Count; i++) { IPoint point = interpCurve.GetDiscreteSpace().GetPointList()[i]; var val = interpCurve.Value(point); Console.WriteLine(point.FunctionValue); } IPoint point2d = new Point2D(0.1, 0.2); Console.WriteLine(interpCurve.Value(point2d)); point2d = new Point2D(0.2, 0.4); Console.WriteLine(interpCurve.Value(point2d)); point2d = new Point2D(0.35, 0.6); Console.WriteLine(interpCurve.Value(point2d)); }