Beispiel #1
0
        //-------------------------------------------------------------------------
        public virtual void test_cloned()
        {
            IborCapletFloorletSabrSensitivity @base = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            IborCapletFloorletSabrSensitivity test  = @base.cloned();

            assertSame(test, @base);
        }
Beispiel #2
0
        //-------------------------------------------------------------------------
        public virtual void test_build()
        {
            IborCapletFloorletSabrSensitivity @base = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            PointSensitivities test = @base.build();

            assertEquals(test.Sensitivities, ImmutableList.of(@base));
        }
Beispiel #3
0
        //-------------------------------------------------------------------------
        public virtual void test_withSensitivity()
        {
            IborCapletFloorletSabrSensitivity @base    = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            IborCapletFloorletSabrSensitivity expected = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 20d);
            IborCapletFloorletSabrSensitivity test     = @base.withSensitivity(20d);

            assertEquals(test, expected);
        }
Beispiel #4
0
        //-------------------------------------------------------------------------
        public virtual void test_multipliedBy()
        {
            IborCapletFloorletSabrSensitivity @base    = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            IborCapletFloorletSabrSensitivity expected = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d * 3.5d);
            IborCapletFloorletSabrSensitivity test     = @base.multipliedBy(3.5d);

            assertEquals(test, expected);
        }
Beispiel #5
0
        //-------------------------------------------------------------------------
        public virtual void test_convertedTo()
        {
            FxRate rate = FxRate.of(GBP, USD, 1.5d);
            IborCapletFloorletSabrSensitivity @base    = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            IborCapletFloorletSabrSensitivity expected = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, USD, 32d * 1.5d);

            assertEquals(@base.convertedTo(USD, rate), expected);
            assertEquals(@base.convertedTo(GBP, rate), @base);
        }
Beispiel #6
0
 public int compareKey(PointSensitivity other)
 {
     if (other is IborCapletFloorletSabrSensitivity)
     {
         IborCapletFloorletSabrSensitivity otherSwpt = (IborCapletFloorletSabrSensitivity)other;
         return(ComparisonChain.start().compare(volatilitiesName, otherSwpt.volatilitiesName).compare(currency, otherSwpt.currency).compare(expiry, otherSwpt.expiry).compare(sensitivityType, otherSwpt.sensitivityType).result());
     }
     return(this.GetType().Name.CompareTo(other.GetType().Name));
 }
Beispiel #7
0
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            IborCapletFloorletSabrSensitivity test = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);

            assertEquals(test.VolatilitiesName, NAME);
            assertEquals(test.Expiry, EXPIRY);
            assertEquals(test.SensitivityType, SabrParameterType.ALPHA);
            assertEquals(test.Currency, GBP);
            assertEquals(test.Sensitivity, 32d);
        }
Beispiel #8
0
        public virtual void test_combinedWith_mutable()
        {
            IborCapletFloorletSabrSensitivity @base    = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            MutablePointSensitivities         expected = new MutablePointSensitivities();

            expected.add(@base);
            PointSensitivityBuilder test = @base.combinedWith(new MutablePointSensitivities());

            assertEquals(test, expected);
        }
Beispiel #9
0
        //-------------------------------------------------------------------------
        public virtual void test_withCurrency()
        {
            IborCapletFloorletSabrSensitivity @base = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);

            assertSame(@base.withCurrency(GBP), @base);

            IborCapletFloorletSabrSensitivity expected = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, USD, 32d);
            IborCapletFloorletSabrSensitivity test     = @base.withCurrency(USD);

            assertEquals(test, expected);
        }
Beispiel #10
0
        //-------------------------------------------------------------------------
        public virtual void test_combinedWith()
        {
            IborCapletFloorletSabrSensitivity base1    = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            IborCapletFloorletSabrSensitivity base2    = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 22d);
            MutablePointSensitivities         expected = new MutablePointSensitivities();

            expected.add(base1).add(base2);
            PointSensitivityBuilder test = base1.combinedWith(base2);

            assertEquals(test, expected);
        }
Beispiel #11
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            IborCapletFloorletSabrSensitivity test = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);

            coverImmutableBean(test);
            IborCapletFloorletSabrSensitivity test2 = IborCapletFloorletSabrSensitivity.of(NAME2, EXPIRY + 1, SabrParameterType.BETA, GBP, 2d);

            coverBeanEquals(test, test2);
            ZeroRateSensitivity test3 = ZeroRateSensitivity.of(USD, 0.5d, 2d);

            coverBeanEquals(test, test3);
        }
Beispiel #12
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         IborCapletFloorletSabrSensitivity other = (IborCapletFloorletSabrSensitivity)obj;
         return(JodaBeanUtils.equal(volatilitiesName, other.volatilitiesName) && JodaBeanUtils.equal(expiry, other.expiry) && JodaBeanUtils.equal(sensitivityType, other.sensitivityType) && JodaBeanUtils.equal(currency, other.currency) && JodaBeanUtils.equal(sensitivity, other.sensitivity));
     }
     return(false);
 }
Beispiel #13
0
        //-------------------------------------------------------------------------
        public virtual void test_compareKey()
        {
            IborCapletFloorletSabrSensitivity a1 = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            IborCapletFloorletSabrSensitivity a2 = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);
            IborCapletFloorletSabrSensitivity b  = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, USD, 32d);
            IborCapletFloorletSabrSensitivity c  = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY + 1, SabrParameterType.ALPHA, GBP, 32d);
            ZeroRateSensitivity other            = ZeroRateSensitivity.of(GBP, 2d, 32d);

            assertEquals(a1.compareKey(a2), 0);
            assertEquals(a1.compareKey(b) < 0, true);
            assertEquals(a1.compareKey(b) < 0, true);
            assertEquals(a1.compareKey(c) < 0, true);
            assertEquals(a1.compareKey(other) < 0, true);
            assertEquals(other.compareKey(a1) > 0, true);
        }
 private void assertSensitivity(PointSensitivities points, SabrParameterType type, double expected, double tol)
 {
     foreach (PointSensitivity point in points.Sensitivities)
     {
         IborCapletFloorletSabrSensitivity sens = (IborCapletFloorletSabrSensitivity)point;
         assertEquals(sens.Currency, EUR);
         assertEquals(sens.VolatilitiesName, VOLS.Name);
         if (sens.SensitivityType == type)
         {
             assertEquals(sens.Sensitivity, expected, NOTIONAL * tol);
             return;
         }
     }
     fail("Did not find sensitivity: " + type + " in " + points);
 }
Beispiel #15
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value sensitivity to the SABR model parameters of the Ibor caplet/floorlet.
        /// <para>
        /// The sensitivity of the present value to the SABR model parameters, alpha, beta, rho and nu.
        ///
        /// </para>
        /// </summary>
        /// <param name="period">  the Ibor caplet/floorlet period </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="volatilities">  the volatilities </param>
        /// <returns> the point sensitivity to the SABR model parameters </returns>
        public virtual PointSensitivityBuilder presentValueSensitivityModelParamsSabr(IborCapletFloorletPeriod period, RatesProvider ratesProvider, SabrIborCapletFloorletVolatilities volatilities)
        {
            double expiry = volatilities.relativeTime(period.FixingDateTime);

            if (expiry < 0d)
            {     // option expired already
                return(PointSensitivityBuilder.none());
            }
            Currency         currency               = period.Currency;
            PutCall          putCall                = period.PutCall;
            double           strike                 = period.Strike;
            double           indexRate              = ratesProvider.iborIndexRates(period.Index).rate(period.IborRate.Observation);
            double           factor                 = period.Notional * period.YearFraction;
            ValueDerivatives volatilityAdj          = volatilities.volatilityAdjoint(expiry, strike, indexRate);
            DoubleArray      derivative             = volatilityAdj.Derivatives;
            double           df                     = ratesProvider.discountFactor(currency, period.PaymentDate);
            double           vega                   = df * factor * volatilities.priceVega(expiry, putCall, strike, indexRate, volatilityAdj.Value);
            IborCapletFloorletVolatilitiesName name = volatilities.Name;

            return(PointSensitivityBuilder.of(IborCapletFloorletSabrSensitivity.of(name, expiry, ALPHA, currency, vega * derivative.get(2)), IborCapletFloorletSabrSensitivity.of(name, expiry, BETA, currency, vega * derivative.get(3)), IborCapletFloorletSabrSensitivity.of(name, expiry, RHO, currency, vega * derivative.get(4)), IborCapletFloorletSabrSensitivity.of(name, expiry, NU, currency, vega * derivative.get(5))));
        }
        public virtual void test_parameterSensitivity_multi()
        {
            double[] points1 = new double[] { 2.24, 3.45, -2.12, -0.56 };
            double[] points2 = new double[] { -0.145, 1.01, -5.0, -11.0 };
            double[] points3 = new double[] { 1.3, -4.32, 2.1, -7.18 };
            SabrParametersIborCapletFloorletVolatilities prov = SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);
            double expiryTime0 = prov.relativeTime(TEST_OPTION_EXPIRY[0]);
            double expiryTime3 = prov.relativeTime(TEST_OPTION_EXPIRY[3]);

            for (int i = 0; i < NB_TEST; i++)
            {
                PointSensitivities             sensi1   = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, ALPHA, EUR, points1[0]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, BETA, EUR, points1[1]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, RHO, EUR, points1[2]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, NU, EUR, points1[3]));
                PointSensitivities             sensi2   = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, ALPHA, EUR, points2[0]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, BETA, EUR, points2[1]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, RHO, EUR, points2[2]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, NU, EUR, points2[3]));
                PointSensitivities             sensi3   = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, ALPHA, EUR, points3[0]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, BETA, EUR, points3[1]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, RHO, EUR, points3[2]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, NU, EUR, points3[3]));
                PointSensitivities             sensis   = sensi1.combinedWith(sensi2).combinedWith(sensi3).normalized();
                CurrencyParameterSensitivities computed = prov.parameterSensitivity(sensis);
                CurrencyParameterSensitivities expected = prov.parameterSensitivity(sensi1).combinedWith(prov.parameterSensitivity(sensi2)).combinedWith(prov.parameterSensitivity(sensi3));
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.AlphaCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.AlphaCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.BetaCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.BetaCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.RhoCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.RhoCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.NuCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.NuCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
            }
        }
Beispiel #17
0
        public virtual void test_serialization()
        {
            IborCapletFloorletSabrSensitivity test = IborCapletFloorletSabrSensitivity.of(NAME, EXPIRY, SabrParameterType.ALPHA, GBP, 32d);

            assertSerialization(test);
        }
        public virtual void test_parameterSensitivity()
        {
            double alphaSensi = 2.24, betaSensi = 3.45, rhoSensi = -2.12, nuSensi = -0.56, shiftSensi = 2.5;
            SabrParametersIborCapletFloorletVolatilities prov = SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);

            for (int i = 0; i < NB_TEST; i++)
            {
                double                         expiryTime             = prov.relativeTime(TEST_OPTION_EXPIRY[i]);
                PointSensitivities             point                  = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, ALPHA, EUR, alphaSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, BETA, EUR, betaSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, RHO, EUR, rhoSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, NU, EUR, nuSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, SHIFT, EUR, shiftSensi));
                CurrencyParameterSensitivities sensiComputed          = prov.parameterSensitivity(point);
                UnitParameterSensitivity       alphaSensitivities     = prov.Parameters.AlphaCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       betaSensitivities      = prov.Parameters.BetaCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       rhoSensitivities       = prov.Parameters.RhoCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       nuSensitivities        = prov.Parameters.NuCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       shiftSensitivities     = prov.Parameters.ShiftCurve.yValueParameterSensitivity(expiryTime);
                CurrencyParameterSensitivity   alphaSensiObj          = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_ALPHA.CurveName, EUR);
                CurrencyParameterSensitivity   betaSensiObj           = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_BETA.CurveName, EUR);
                CurrencyParameterSensitivity   rhoSensiObj            = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_RHO.CurveName, EUR);
                CurrencyParameterSensitivity   nuSensiObj             = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_NU.CurveName, EUR);
                CurrencyParameterSensitivity   shiftSensiObj          = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_SHIFT.CurveName, EUR);
                DoubleArray                    alphaNodeSensiComputed = alphaSensiObj.Sensitivity;
                DoubleArray                    betaNodeSensiComputed  = betaSensiObj.Sensitivity;
                DoubleArray                    rhoNodeSensiComputed   = rhoSensiObj.Sensitivity;
                DoubleArray                    nuNodeSensiComputed    = nuSensiObj.Sensitivity;
                DoubleArray                    shiftNodeSensiComputed = shiftSensiObj.Sensitivity;
                assertEquals(alphaSensitivities.Sensitivity.size(), alphaNodeSensiComputed.size());
                assertEquals(betaSensitivities.Sensitivity.size(), betaNodeSensiComputed.size());
                assertEquals(rhoSensitivities.Sensitivity.size(), rhoNodeSensiComputed.size());
                assertEquals(nuSensitivities.Sensitivity.size(), nuNodeSensiComputed.size());
                assertEquals(shiftSensitivities.Sensitivity.size(), shiftNodeSensiComputed.size());
                for (int k = 0; k < alphaNodeSensiComputed.size(); ++k)
                {
                    assertEquals(alphaNodeSensiComputed.get(k), alphaSensitivities.Sensitivity.get(k) * alphaSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < betaNodeSensiComputed.size(); ++k)
                {
                    assertEquals(betaNodeSensiComputed.get(k), betaSensitivities.Sensitivity.get(k) * betaSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < rhoNodeSensiComputed.size(); ++k)
                {
                    assertEquals(rhoNodeSensiComputed.get(k), rhoSensitivities.Sensitivity.get(k) * rhoSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < nuNodeSensiComputed.size(); ++k)
                {
                    assertEquals(nuNodeSensiComputed.get(k), nuSensitivities.Sensitivity.get(k) * nuSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < shiftNodeSensiComputed.size(); ++k)
                {
                    assertEquals(shiftNodeSensiComputed.get(k), shiftSensitivities.Sensitivity.get(k) * shiftSensi, TOLERANCE_VOL);
                }
            }
        }