public virtual void test_zeroRatePointSensitivityWithSpread_smallYearFraction() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, 0d, -0d); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_VAL, SPREAD, CONTINUOUS, 0), expected); }
//------------------------------------------------------------------------- public virtual void test_cloned() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity test = @base.cloned(); assertSame(test, @base); }
//------------------------------------------------------------------------- public virtual void test_build() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); PointSensitivities test = @base.build(); assertEquals(test.Sensitivities, ImmutableList.of(@base)); }
//------------------------------------------------------------------------- // proper end-to-end FD tests are elsewhere public virtual void test_parameterSensitivity() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity point = ZeroRateSensitivity.of(GBP, 1d, 1d); assertEquals(test.parameterSensitivity(point).size(), 1); }
//------------------------------------------------------------------------- public virtual void test_withCurrency() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); assertSame(@base.withCurrency(GBP), @base); assertEquals(@base.withCurrency(USD), ZeroRateSensitivity.of(GBP, YEARFRAC, USD, 32d)); }
public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_smallYearFraction() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, 0d, USD, -0d); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_VAL, USD, SPREAD, PERIODIC, 2), expected); }
//------------------------------------------------------------------------- public virtual void test_mapSensitivity() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, YEARFRAC, 1 / 32d); ZeroRateSensitivity test = @base.mapSensitivity(s => 1 / s); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_multipliedBy() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d * 3.5d); ZeroRateSensitivity test = @base.multipliedBy(3.5d); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_withSensitivity() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, YEARFRAC, 20d); ZeroRateSensitivity test = @base.withSensitivity(20d); assertEquals(test, expected); }
public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_smallYearFraction() { ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, 0d, USD, 0.0d); ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_VAL, USD, SPREAD, CONTINUOUS, 0); assertTrue(computed.compareKey(expected) == 0); assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA_FD); }
//------------------------------------------------------------------------- public virtual void test_zeroRatePointSensitivity() { ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = Math.Exp(-relativeYearFraction * CURVE.yValue(relativeYearFraction)); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivity(DATE_AFTER), expected); }
//------------------------------------------------------------------------- public virtual void test_buildInto() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); MutablePointSensitivities combo = new MutablePointSensitivities(); MutablePointSensitivities test = @base.buildInto(combo); assertSame(test, combo); assertEquals(test.Sensitivities, ImmutableList.of(@base)); }
public virtual void test_of() { ZeroRateSensitivity test = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); assertEquals(test.Currency, GBP); assertEquals(test.YearFraction, YEARFRAC); assertEquals(test.Sensitivity, 32d); assertEquals(test.Currency, GBP); }
//------------------------------------------------------------------------- public virtual void test_zeroRatePointSensitivityWithSpread_continous() { ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = Math.Exp(-relativeYearFraction * (CURVE.yValue(relativeYearFraction) + SPREAD)); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0), expected); }
//------------------------------------------------------------------------- public virtual void coverage() { ZeroRateSensitivity test = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); coverImmutableBean(test); ZeroRateSensitivity test2 = ZeroRateSensitivity.of(USD, YEARFRAC2, 16d); coverBeanEquals(test, test2); }
public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_continuous() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = CURVE.yValue(relativeYearFraction) * Math.Exp(-SPREAD * relativeYearFraction); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, CONTINUOUS, 1), expected); }
public virtual void test_zeroRatePointSensitivity_sensitivityCurrency() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = CURVE.yValue(relativeYearFraction); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivity(DATE_AFTER, USD), expected); }
public virtual void test_combinedWith_mutable() { ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); MutablePointSensitivities expected = new MutablePointSensitivities(); expected.add(@base); PointSensitivityBuilder test = @base.combinedWith(new MutablePointSensitivities()); assertEquals(test, expected); }
//------------------------------------------------------------------------- public virtual void test_combinedWith() { ZeroRateSensitivity base1 = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity base2 = ZeroRateSensitivity.of(GBP, YEARFRAC2, 22d); MutablePointSensitivities expected = new MutablePointSensitivities(); expected.add(base1).add(base2); PointSensitivityBuilder test = base1.combinedWith(base2); assertEquals(test, expected); }
public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_continous() { ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = test.discountFactorWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, -df * relativeYearFraction); ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, CONTINUOUS, 0); assertTrue(computed.compareKey(expected) == 0); assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA); }
//------------------------------------------------------------------------- public virtual void test_convertedTo() { double sensi = 32d; ZeroRateSensitivity @base = ZeroRateSensitivity.of(GBP, YEARFRAC, sensi); double rate = 1.5d; FxMatrix matrix = FxMatrix.of(CurrencyPair.of(GBP, USD), rate); ZeroRateSensitivity test1 = (ZeroRateSensitivity)@base.convertedTo(USD, matrix); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, YEARFRAC, USD, rate * sensi); assertEquals(test1, expected); ZeroRateSensitivity test2 = (ZeroRateSensitivity)@base.convertedTo(GBP, matrix); assertEquals(test2, @base); }
//------------------------------------------------------------------------- public virtual void test_compareKey() { ZeroRateSensitivity a1 = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity a2 = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); ZeroRateSensitivity b = ZeroRateSensitivity.of(USD, YEARFRAC, 32d); ZeroRateSensitivity c = ZeroRateSensitivity.of(GBP, YEARFRAC2, 32d); IborRateSensitivity other = IborRateSensitivity.of(IborIndexObservation.of(GBP_LIBOR_3M, date(2014, 6, 30), REF_DATA), 32d); assertEquals(a1.compareKey(a2), 0); assertEquals(a1.compareKey(b) < 0, true); assertEquals(b.compareKey(a1) > 0, true); assertEquals(a1.compareKey(c) < 0, true); assertEquals(c.compareKey(a1) > 0, true); assertEquals(a1.compareKey(other) > 0, true); assertEquals(other.compareKey(a1) < 0, true); }
public override ZeroRateSensitivity zeroRatePointSensitivityWithSpread(double yearFraction, Currency sensitivityCurrency, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear) { if (Math.Abs(yearFraction) < EFFECTIVE_ZERO) { return(ZeroRateSensitivity.of(currency, yearFraction, sensitivityCurrency, 0)); } if (compoundedRateType.Equals(CompoundedRateType.CONTINUOUS)) { double discountFactor = discountFactorWithSpread(yearFraction, zSpread, compoundedRateType, periodPerYear); return(ZeroRateSensitivity.of(currency, yearFraction, sensitivityCurrency, -discountFactor * yearFraction)); } double df = discountFactor(yearFraction); double df2 = Math.Pow(df, -1.0 / (yearFraction * periodPerYear)); double df3 = df2 + zSpread / periodPerYear; double ddfSdz = -yearFraction *Math.Pow(df3, -yearFraction *periodPerYear - 1) * df2; return(ZeroRateSensitivity.of(currency, yearFraction, sensitivityCurrency, ddfSdz)); }
public virtual void test_zeroRatePointSensitivityWithSpread_sensitivityCurrency_periodic() { int periodPerYear = 4; ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = test.discountFactor(DATE_AFTER); double z = -1.0 / relativeYearFraction * Math.Log(df); double shift = 1.0E-6; double zP = z + shift; double zM = z - shift; double dfSP = Math.Pow(Math.Pow(Math.Exp(-zP * relativeYearFraction), -1.0 / (relativeYearFraction * periodPerYear)) + SPREAD / periodPerYear, -relativeYearFraction * periodPerYear); double dfSM = Math.Pow(Math.Pow(Math.Exp(-zM * relativeYearFraction), -1.0 / (relativeYearFraction * periodPerYear)) + SPREAD / periodPerYear, -relativeYearFraction * periodPerYear); double ddfSdz = (dfSP - dfSM) / (2 * shift); ZeroRateSensitivity expected = ZeroRateSensitivity.of(GBP, relativeYearFraction, USD, ddfSdz); ZeroRateSensitivity computed = test.zeroRatePointSensitivityWithSpread(DATE_AFTER, USD, SPREAD, PERIODIC, periodPerYear); assertTrue(computed.compareKey(expected) == 0); assertEquals(computed.Sensitivity, expected.Sensitivity, TOLERANCE_DELTA_FD); }
//------------------------------------------------------------------------- public ZeroRateSensitivity zeroRatePointSensitivity(double yearFraction, Currency sensitivityCurrency) { double discountFactor = this.discountFactor(yearFraction); return(ZeroRateSensitivity.of(currency, yearFraction, sensitivityCurrency, -discountFactor * yearFraction)); }
public virtual void test_serialization() { ZeroRateSensitivity test = ZeroRateSensitivity.of(GBP, YEARFRAC, 32d); assertSerialization(test); }