示例#1
0
        private void presentValueSensitivityRawDataParallelSensitivity(SabrParametersSwaptionVolatilities sabrCalibrated, TenorRawOptionData dataRaw)
        {
            PointSensitivities             points = LEG_PRICER.presentValueSensitivityModelParamsSabr(FLOOR_LEG, MULTICURVE, sabrCalibrated).build();
            CurrencyParameterSensitivities sabrParametersSurfaceSensitivities = sabrCalibrated.parameterSensitivity(points);
            CurrencyParameterSensitivity   parallelSensitivitiesSurface       = RDSC.parallelSensitivity(sabrParametersSurfaceSensitivities, sabrCalibrated);
            DoubleArray sensitivityArray  = parallelSensitivitiesSurface.Sensitivity;
            double      fdShift           = 1.0E-6;
            int         surfacePointIndex = 0;

            for (int loopexpiry = 0; loopexpiry < EXPIRIES.size(); loopexpiry++)
            {
                for (int looptenor = 0; looptenor < TENORS.size(); looptenor++)
                {
                    Tenor tenor = TENORS.get(looptenor);
                    Pair <DoubleArray, DoubleArray> ds = dataRaw.getData(tenor).availableSmileAtExpiry(EXPIRIES.get(loopexpiry));
                    if (!ds.First.Empty)
                    {
                        double[] pv = new double[2];   // pv with shift up and down
                        for (int loopsign = 0; loopsign < 2; loopsign++)
                        {
                            TenorRawOptionData dataShifted = SabrSwaptionCalibratorSmileTestUtils.rawDataShiftSmile(TENORS, EXPIRIES, ValueType.SIMPLE_MONEYNESS, MONEYNESS, ValueType.NORMAL_VOLATILITY, DATA_ARRAY_FULL, looptenor, loopexpiry, (2 * loopsign - 1) * fdShift);
                            SabrParametersSwaptionVolatilities calibratedShifted = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(DEFINITION, CALIBRATION_TIME, dataShifted, MULTICURVE, BETA_SURFACE, SHIFT_SABR_SURFACE);
                            pv[loopsign] = LEG_PRICER.presentValue(FLOOR_LEG, MULTICURVE, calibratedShifted).Amount;
                        }
                        double sensitivityFd = (pv[1] - pv[0]) / (2 * fdShift);   // FD sensitivity computation
                        SabrSwaptionCalibratorSmileTestUtils.checkAcceptable(sensitivityFd, sensitivityArray.get(surfacePointIndex), 0.10, "Tenor/Expiry: " + TENORS.get(looptenor) + " / " + EXPIRIES.get(loopexpiry));
                        surfacePointIndex++;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Check that the sensitivities of parameters with respect to data is stored in the metadata.
        /// Compare the sensitivities to a finite difference approximation.
        /// This test is relatively slow as it calibrates the full surface multiple times.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void log_normal_cube_sensitivity()
        public virtual void log_normal_cube_sensitivity()
        {
            double  beta         = 1.0;
            Surface betaSurface  = ConstantSurface.of("Beta", beta).withMetadata(DefaultSurfaceMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).zValueType(ValueType.SABR_BETA).surfaceName("Beta").build());
            double  shift        = 0.0000;
            Surface shiftSurface = ConstantSurface.of("Shift", shift).withMetadata(DefaultSurfaceMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).surfaceName("Shift").build());
            SabrParametersSwaptionVolatilities calibrated = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(DEFINITION, CALIBRATION_TIME, DATA_SPARSE, MULTICURVE, betaSurface, shiftSurface);
            double fdShift = 1.0E-5;

            SurfaceMetadata alphaMetadata = calibrated.Parameters.AlphaSurface.Metadata;
            Optional <IList <ParameterMetadata> > alphaParameterMetadataOption = alphaMetadata.ParameterMetadata;

            assertTrue(alphaParameterMetadataOption.Present);
            IList <ParameterMetadata>             alphaParameterMetadata     = alphaParameterMetadataOption.get();
            IList <DoubleArray>                   alphaJacobian              = calibrated.DataSensitivityAlpha.get();
            SurfaceMetadata                       rhoMetadata                = calibrated.Parameters.RhoSurface.Metadata;
            Optional <IList <ParameterMetadata> > rhoParameterMetadataOption = rhoMetadata.ParameterMetadata;

            assertTrue(rhoParameterMetadataOption.Present);
            IList <ParameterMetadata>             rhoParameterMetadata      = rhoParameterMetadataOption.get();
            IList <DoubleArray>                   rhoJacobian               = calibrated.DataSensitivityRho.get();
            SurfaceMetadata                       nuMetadata                = calibrated.Parameters.NuSurface.Metadata;
            Optional <IList <ParameterMetadata> > nuParameterMetadataOption = nuMetadata.ParameterMetadata;

            assertTrue(nuParameterMetadataOption.Present);
            IList <ParameterMetadata> nuParameterMetadata = nuParameterMetadataOption.get();
            IList <DoubleArray>       nuJacobian          = calibrated.DataSensitivityNu.get();

            int surfacePointIndex = 0;

            for (int loopexpiry = 0; loopexpiry < EXPIRIES.Count; loopexpiry++)
            {
                for (int looptenor = 0; looptenor < TENORS.Count; looptenor++)
                {
                    Tenor         tenor                = TENORS[looptenor];
                    double        tenorYears           = tenor.get(ChronoUnit.YEARS);
                    LocalDate     expiry               = EUR_FIXED_1Y_EURIBOR_6M.FloatingLeg.StartDateBusinessDayAdjustment.adjust(CALIBRATION_DATE.plus(EXPIRIES[loopexpiry]), REF_DATA);
                    ZonedDateTime expiryDateTime       = expiry.atTime(11, 0).atZone(ZoneId.of("Europe/Berlin"));
                    double        time                 = calibrated.relativeTime(expiryDateTime);
                    Pair <DoubleArray, DoubleArray> ds = DATA_SPARSE.getData(tenor).availableSmileAtExpiry(EXPIRIES[loopexpiry]);
                    if (!ds.First.Empty)
                    {
                        int availableDataIndex = 0;

                        ParameterMetadata alphaPM = alphaParameterMetadata[surfacePointIndex];
                        assertTrue(alphaPM is SwaptionSurfaceExpiryTenorParameterMetadata);
                        SwaptionSurfaceExpiryTenorParameterMetadata pmAlphaSabr = (SwaptionSurfaceExpiryTenorParameterMetadata)alphaPM;
                        assertEquals(tenorYears, pmAlphaSabr.Tenor);
                        assertEquals(time, pmAlphaSabr.YearFraction, TOLERANCE_EXPIRY);
                        DoubleArray       alphaSensitivityToData = alphaJacobian[surfacePointIndex];
                        ParameterMetadata rhoPM = rhoParameterMetadata[surfacePointIndex];
                        assertTrue(rhoPM is SwaptionSurfaceExpiryTenorParameterMetadata);
                        SwaptionSurfaceExpiryTenorParameterMetadata pmRhoSabr = (SwaptionSurfaceExpiryTenorParameterMetadata)rhoPM;
                        assertEquals(tenorYears, pmRhoSabr.Tenor);
                        assertEquals(time, pmRhoSabr.YearFraction, TOLERANCE_EXPIRY);
                        DoubleArray       rhoSensitivityToData = rhoJacobian[surfacePointIndex];
                        ParameterMetadata nuPM = nuParameterMetadata[surfacePointIndex];
                        assertTrue(nuPM is SwaptionSurfaceExpiryTenorParameterMetadata);
                        SwaptionSurfaceExpiryTenorParameterMetadata pmNuSabr = (SwaptionSurfaceExpiryTenorParameterMetadata)nuPM;
                        assertEquals(tenorYears, pmNuSabr.Tenor);
                        assertEquals(time, pmNuSabr.YearFraction, TOLERANCE_EXPIRY);
                        DoubleArray nuSensitivityToData = nuJacobian[surfacePointIndex];

                        for (int loopmoney = 0; loopmoney < MONEYNESS.size(); loopmoney++)
                        {
                            if (!double.IsNaN(DATA_LOGNORMAL[looptenor][loopexpiry][loopmoney]))
                            {
                                double[] alphaShifted = new double[2];
                                double[] rhoShifted   = new double[2];
                                double[] nuShifted    = new double[2];
                                for (int loopsign = 0; loopsign < 2; loopsign++)
                                {
                                    TenorRawOptionData dataShifted = SabrSwaptionCalibratorSmileTestUtils.rawDataShiftPoint(TENORS, EXPIRIES, ValueType.SIMPLE_MONEYNESS, MONEYNESS, ValueType.BLACK_VOLATILITY, DATA_LOGNORMAL, looptenor, loopexpiry, loopmoney, (2 * loopsign - 1) * fdShift);
                                    SabrParametersSwaptionVolatilities calibratedShifted = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(DEFINITION, CALIBRATION_TIME, dataShifted, MULTICURVE, betaSurface, shiftSurface);
                                    alphaShifted[loopsign] = calibratedShifted.Parameters.AlphaSurface.zValue(time, tenorYears);
                                    rhoShifted[loopsign]   = calibratedShifted.Parameters.RhoSurface.zValue(time, tenorYears);
                                    nuShifted[loopsign]    = calibratedShifted.Parameters.NuSurface.zValue(time, tenorYears);
                                }
                                double alphaSensitivityComputed = alphaSensitivityToData.get(availableDataIndex);
                                double alphaSensitivityExpected = (alphaShifted[1] - alphaShifted[0]) / (2 * fdShift);
                                checkAcceptable(alphaSensitivityComputed, alphaSensitivityExpected, TOLERANCE_PARAM_SENSITIVITY, "Alpha: " + looptenor + " / " + loopexpiry + " / " + loopmoney);
                                double rhoSensitivityComputed = rhoSensitivityToData.get(availableDataIndex);
                                double rhoSensitivityExpected = (rhoShifted[1] - rhoShifted[0]) / (2 * fdShift);
                                checkAcceptable(rhoSensitivityComputed, rhoSensitivityExpected, TOLERANCE_PARAM_SENSITIVITY, "Rho: " + looptenor + " / " + loopexpiry + " / " + loopmoney);
                                double nuSensitivityComputed = nuSensitivityToData.get(availableDataIndex);
                                double nuSensitivityExpected = (nuShifted[1] - nuShifted[0]) / (2 * fdShift);
                                checkAcceptable(nuSensitivityComputed, nuSensitivityExpected, TOLERANCE_PARAM_SENSITIVITY, "Nu: " + looptenor + " / " + loopexpiry + " / " + loopmoney);
                                availableDataIndex++;
                            }
                        }
                        surfacePointIndex++;
                    }
                }
            }
        }