Exemple #1
0
        public static object SurfaceFromCube(
            [ExcelArgument(Description = "Output Surface name")] string SurfaceName,
            [ExcelArgument(Description = "Cube name")] string CubeName,
            [ExcelArgument(Description = "Build date")] DateTime BuildDate,
            [ExcelArgument(Description = "Currency")] string Currency,
            [ExcelArgument(Description = "Asset Id")] string AssetId,
            [ExcelArgument(Description = "Stike Interpolation - default GaussianKernel")] object StrikeInterpolation,
            [ExcelArgument(Description = "Time Interpolation - default LinearInVariance")] object TimeInterpolation)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var cube = ContainerStores.GetObjectCache <ICube>().GetObjectOrThrow(CubeName, $"Cube {CubeName} not found");
                var strikeInterpType = StrikeInterpolation.OptionalExcel("GaussianKernel");
                var timeInterpType = TimeInterpolation.OptionalExcel("LinearInVariance");

                if (!Enum.TryParse(strikeInterpType, out Interpolator1DType siType))
                {
                    return $"Could not parse strike interpolator type - {strikeInterpType}";
                }
                if (!Enum.TryParse(timeInterpType, out Interpolator1DType tiType))
                {
                    return $"Could not parse time interpolator type - {timeInterpType}";
                }

                var rrbf = RiskyFlySurface.FromCube(cube.Value, BuildDate, siType, tiType);
                rrbf.AssetId = AssetId;
                rrbf.Name = AssetId;
                if (!string.IsNullOrWhiteSpace(Currency))
                {
                    rrbf.Currency = ContainerStores.CurrencyProvider.GetCurrency(Currency);
                }

                return ExcelHelper.PushToCache <IVolSurface>(rrbf, SurfaceName);
            }));
        }
        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]);
        }