コード例 #1
0
        //-------------------------------------------------------------------------
        private static CurrencyParameterSensitivity buildSensitivities(Curve bumpedCurve, ImmutableRatesProvider ratesProvider)
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            RatesProvider                  bumpedRatesProvider = ratesProvider.toBuilder().discountCurves(ratesProvider.DiscountCurves.Keys.collect(toImmutableMap(System.Func.identity(), k => bumpedCurve))).indexCurves(ratesProvider.IndexCurves.Keys.collect(toImmutableMap(System.Func.identity(), k => bumpedCurve))).build();
            PointSensitivities             pointSensitivities  = PRICER_SWAP.presentValueSensitivity(SWAP, bumpedRatesProvider).build();
            CurrencyParameterSensitivities paramSensitivities  = bumpedRatesProvider.parameterSensitivity(pointSensitivities);

            return(Iterables.getOnlyElement(paramSensitivities.Sensitivities));
        }
コード例 #2
0
        //-------------------------------------------------------------------------
        public virtual void semiParallelGammaValue()
        {
            ImmutableRatesProvider provider = SINGLE;
            Currency    curveCurrency       = SINGLE_CURRENCY;
            DoubleArray y             = USD_SINGLE_CURVE.YValues;
            int         nbNode        = y.size();
            DoubleArray gammaExpected = DoubleArray.of(nbNode, i =>
            {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][][] yBumped = new double[2][2][nbNode];
                double[][][] yBumped = RectangularArrays.ReturnRectangularDoubleArray(2, 2, nbNode);
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: double[][] pv = new double[2][2];
                double[][] pv = RectangularArrays.ReturnRectangularDoubleArray(2, 2);
                for (int pmi = 0; pmi < 2; pmi++)
                {
                    for (int pmP = 0; pmP < 2; pmP++)
                    {
                        yBumped[pmi][pmP]     = y.toArray();
                        yBumped[pmi][pmP][i] += (pmi == 0 ? 1.0 : -1.0) * FD_SHIFT;
                        for (int j = 0; j < nbNode; j++)
                        {
                            yBumped[pmi][pmP][j] += (pmP == 0 ? 1.0 : -1.0) * FD_SHIFT;
                        }
                        Curve curveBumped = USD_SINGLE_CURVE.withYValues(DoubleArray.copyOf(yBumped[pmi][pmP]));
                        ImmutableRatesProvider providerBumped = provider.toBuilder().discountCurves(provider.DiscountCurves.Keys.collect(toImmutableMap(Function.identity(), k => curveBumped))).indexCurves(provider.IndexCurves.Keys.collect(toImmutableMap(Function.identity(), k => curveBumped))).build();
                        pv[pmi][pmP] = PRICER_SWAP.presentValue(SWAP, providerBumped).getAmount(USD).Amount;
                    }
                }
                return((pv[1][1] - pv[1][0] - pv[0][1] + pv[0][0]) / (4 * FD_SHIFT * FD_SHIFT));
            });
            CurrencyParameterSensitivity sensitivityComputed = GAMMA_CAL.calculateSemiParallelGamma(USD_SINGLE_CURVE, curveCurrency, c => buildSensitivities(c, provider));

            assertEquals(sensitivityComputed.MarketDataName, USD_SINGLE_CURVE.Name);
            DoubleArray gammaComputed = sensitivityComputed.Sensitivity;

            assertTrue(gammaComputed.equalWithTolerance(gammaExpected, TOLERANCE_GAMMA));
        }