public void RiskyFlySimple() { //flat surface var origin = new DateTime(2017, 02, 07); var atms = new double[] { 0.3, 0.32, 0.34 }; var fwds = new double[] { 100, 102, 110 }; var maturities = new DateTime[] { new DateTime(2017, 04, 06), new DateTime(2017, 06, 07), new DateTime(2017, 08, 07) }; var wingDeltas = new[] { 0.1, 0.25 }; var riskies = new[] { new[] { 0.025, 0.015 }, new[] { 0.025, 0.015 }, new[] { 0.025, 0.015 } }; var flies = new[] { new[] { 0.0025, 0.0015 }, new[] { 0.0025, 0.0015 }, new[] { 0.0025, 0.0015 } }; var surface = new RiskyFlySurface( origin, atms, maturities, wingDeltas, riskies, flies, fwds, WingQuoteType.Simple, AtmVolType.ZeroDeltaStraddle, Interpolator1DType.Linear, Interpolator1DType.LinearInVariance); Assert.Equal(atms[1], surface.GetVolForDeltaStrike(0.5, maturities[1], fwds[1])); var cube = surface.ToCube(); Assert.Equal(fwds[0], cube.GetAllRows().First().Value); var recon = RiskyFlySurface.FromCube(cube, origin, Interpolator1DType.Linear, Interpolator1DType.LinearInVariance); Assert.Equal(surface.GetVolForDeltaStrike(0.5, maturities[1], fwds[1]), recon.GetVolForDeltaStrike(0.5, maturities[1], fwds[1])); var quotes = surface.DisplayQuotes(); Assert.Equal(maturities[0], (DateTime)quotes[1, 0]); }
public void SABRSurfaceRRBF() { //flat surface var origin = new DateTime(2017, 02, 07); var expiry = origin.AddYears(1); var t = (expiry - origin).TotalDays / 365.0; var fwd = 1.5; var vol = 0.32; var rr = new[] { new[] { 0.02, 0.03 } }; var bf = new[] { new[] { 0.005, 0.007 } }; Func <double, double> fwdCurve = (tt => { return(fwd); }); var surface = new SabrVolSurface(origin, new[] { vol }, new[] { expiry }, new[] { 0.25, 0.1 }, rr, bf, new[] { 100.0 }, WingQuoteType.Arithmatic, AtmVolType.ZeroDeltaStraddle, Math.Interpolation.Interpolator1DType.Linear); var gSurface = new RiskyFlySurface(origin, new[] { vol }, new[] { expiry }, new[] { 0.25, 0.1 }, rr, bf, new[] { 100.0 }, WingQuoteType.Arithmatic, AtmVolType.ZeroDeltaStraddle, Math.Interpolation.Interpolator1DType.Linear, Math.Interpolation.Interpolator1DType.Linear); var atmK = BlackFunctions.AbsoluteStrikefromDeltaKAnalytic(fwd, 0.5, 0.0, t, vol); Assert.Equal(vol, surface.GetVolForAbsoluteStrike(atmK, expiry, fwd), 2); var v25c = gSurface.GetVolForDeltaStrike(0.75, expiry, fwd); var v25p = gSurface.GetVolForDeltaStrike(0.25, expiry, fwd); var k25c = BlackFunctions.AbsoluteStrikefromDeltaKAnalytic(fwd, 0.25, 0.0, t, v25c); var k25p = BlackFunctions.AbsoluteStrikefromDeltaKAnalytic(fwd, -0.25, 0.0, t, v25p); var t25c = surface.GetVolForAbsoluteStrike(k25c, expiry, fwd); var t25p = surface.GetVolForAbsoluteStrike(k25p, expiry, fwd); Assert.Equal(rr[0][0], t25c - t25p, 2); }
public void RiskyFlySerialization() { var origin = new DateTime(2017, 02, 07); var atms = new double[] { 0.3, 0.32, 0.34 }; var fwds = new double[] { 100, 102, 110 }; var maturities = new DateTime[] { new DateTime(2017, 04, 06), new DateTime(2017, 06, 07), new DateTime(2017, 08, 07) }; var wingDeltas = new[] { 0.1, 0.25 }; var riskies = new[] { new[] { 0.025, 0.015 }, new[] { 0.025, 0.015 }, new[] { 0.025, 0.015 } }; var flies = new[] { new[] { 0.0025, 0.0015 }, new[] { 0.0025, 0.0015 }, new[] { 0.0025, 0.0015 } }; var surface = new RiskyFlySurface( origin, atms, maturities, wingDeltas, riskies, flies, fwds, WingQuoteType.Simple, AtmVolType.ZeroDeltaStraddle, Interpolator1DType.Linear, Interpolator1DType.LinearInVariance); Assert.Equal(atms[1], surface.GetVolForDeltaStrike(0.5, maturities[1], fwds[1])); var binSer = new BinarySerializer(); binSer.PrepareObjectGraph(surface); var span = binSer.SerializeObjectGraph(); var binDeser = new BinaryDeserializer(); var surface2 = (ObjectWithLists)binDeser.DeserializeObjectGraph(span); Assert.Equal(atms[1], surface.GetVolForDeltaStrike(0.5, maturities[1], fwds[1])); }