Exemplo n.º 1
0
        //-------------------------------------------------------------------------
        public virtual void test_surfaceParameterSensitivity()
        {
            for (int i = 0; i < NB_EXPIRY; i++)
            {
                for (int j = 0; j < NB_STRIKE; ++j)
                {
                    double timeToExpiry = VOLS.relativeTime(TEST_EXPIRY[i]);
                    FxOptionSensitivity             sensi    = FxOptionSensitivity.of(VOLS.Name, CURRENCY_PAIR, timeToExpiry, TEST_STRIKE[j], FORWARD[i], GBP, 1d);
                    CurrencyParameterSensitivity    computed = VOLS.parameterSensitivity(sensi).Sensitivities.get(0);
                    IEnumerator <ParameterMetadata> itr      = computed.ParameterMetadata.GetEnumerator();
                    foreach (double value in computed.Sensitivity.toArray())
                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                        FxVolatilitySurfaceYearFractionParameterMetadata meta = ((FxVolatilitySurfaceYearFractionParameterMetadata)itr.next());
                        double nodeExpiry = meta.YearFraction;
                        double nodeDelta  = meta.Strike.Value;
                        double expected   = nodeSensitivity(VOLS, CURRENCY_PAIR, TEST_EXPIRY[i], TEST_STRIKE[j], FORWARD[i], nodeExpiry, nodeDelta);
                        assertEquals(value, expected, EPS);
                    }
                }
            }
        }
Exemplo n.º 2
0
        //-------------------------------------------------------------------------
        public virtual void test_putCallParity()
        {
            double df = RATES_PROVIDER.discountFactor(USD, PAY);
            PointSensitivityBuilder dfSensi = RATES_PROVIDER.discountFactors(USD).zeroRatePointSensitivity(PAY);

            for (int i = 0; i < NB_STRIKES; ++i)
            {
                CurrencyAmount          pvCall         = PRICER.presentValue(CALLS[i], RATES_PROVIDER, VOLS);
                PointSensitivityBuilder pvSensiCall    = PRICER.presentValueSensitivityRatesStickyStrike(CALLS[i], RATES_PROVIDER, VOLS);
                PointSensitivityBuilder pvSensiVolCall = PRICER.presentValueSensitivityModelParamsVolatility(CALLS[i], RATES_PROVIDER, VOLS);
                CurrencyAmount          pvPut          = PRICER.presentValue(PUTS[i], RATES_PROVIDER, VOLS);
                PointSensitivityBuilder pvSensiPut     = PRICER.presentValueSensitivityRatesStickyStrike(PUTS[i], RATES_PROVIDER, VOLS);
                PointSensitivityBuilder pvSensiVolPut  = PRICER.presentValueSensitivityModelParamsVolatility(PUTS[i], RATES_PROVIDER, VOLS);
                double forward = FX_PRICER.forwardFxRate(UNDERLYING[i], RATES_PROVIDER).fxRate(CURRENCY_PAIR);
                PointSensitivityBuilder forwardSensi = FX_PRICER.forwardFxRatePointSensitivity(UNDERLYING[i], RATES_PROVIDER);
                double strike = CALLS[i].Strike;
                assertEquals(pvCall.Amount + pvPut.Amount, df * (forward - strike) * NOTIONAL, TOL * NOTIONAL);
                assertTrue(pvSensiCall.combinedWith(pvSensiPut).build().normalized().equalWithTolerance(dfSensi.multipliedBy((forward - strike) * NOTIONAL).combinedWith(forwardSensi.multipliedBy(df * NOTIONAL)).build().normalized(), NOTIONAL * TOL));
                DoubleArray sensiVol = VOLS.parameterSensitivity(pvSensiVolCall.combinedWith(pvSensiVolPut).build()).Sensitivities.get(0).Sensitivity;
                assertTrue(DoubleArrayMath.fuzzyEquals(sensiVol.toArray(), new double[sensiVol.size()], NOTIONAL * TOL));
            }
        }