public virtual void test_volatilities() { BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification @base = BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification.builder().name(VOL_NAME).currencyPair(GBP_USD).dayCount(ACT_365F).nodes(NODES).timeInterpolator(PCHIP).strikeInterpolator(DOUBLE_QUADRATIC).build(); LocalDate date = LocalDate.of(2017, 9, 25); ZonedDateTime dateTime = date.atStartOfDay().atZone(ZoneId.of("Europe/London")); DoubleArray parameters = DoubleArray.of(0.19, 0.15, 0.13, 0.14, 0.14, 0.11, 0.09, 0.09, 0.11, 0.09, 0.07, 0.07); BlackFxOptionSurfaceVolatilities computed = @base.volatilities(dateTime, parameters, REF_DATA); DaysAdjustment expOffset = DaysAdjustment.ofBusinessDays(-2, NY_LO); double[] expiries = new double[STRIKES.Count * TENORS.Count]; double[] strikes = new double[STRIKES.Count * TENORS.Count]; ImmutableList.Builder <ParameterMetadata> paramMetadata = ImmutableList.builder(); for (int i = 0; i < TENORS.Count; ++i) { double expiry = ACT_365F.relativeYearFraction(date, expOffset.adjust(BDA.adjust(SPOT_OFFSET.adjust(date, REF_DATA).plus(TENORS[i]), REF_DATA), REF_DATA)); for (int j = 0; j < STRIKES.Count; ++j) { paramMetadata.add(FxVolatilitySurfaceYearFractionParameterMetadata.of(expiry, SimpleStrike.of(STRIKES[j]), GBP_USD)); expiries[STRIKES.Count * i + j] = expiry; strikes[STRIKES.Count * i + j] = STRIKES[j]; } } InterpolatedNodalSurface surface = InterpolatedNodalSurface.ofUnsorted(Surfaces.blackVolatilityByExpiryStrike(VOL_NAME.Name, ACT_365F).withParameterMetadata(paramMetadata.build()), DoubleArray.ofUnsafe(expiries), DoubleArray.ofUnsafe(strikes), parameters, GridSurfaceInterpolator.of(PCHIP, DOUBLE_QUADRATIC)); BlackFxOptionSurfaceVolatilities expected = BlackFxOptionSurfaceVolatilities.of(VOL_NAME, GBP_USD, dateTime, surface); assertEquals(computed, expected); }
//------------------------------------------------------------------------- public virtual void test_discountFactor() { ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expected = Math.Pow(1.0d + CURVE.yValue(relativeYearFraction) / CMP_PERIOD, -CMP_PERIOD * relativeYearFraction); assertEquals(test.discountFactor(DATE_AFTER), expected); }
//------------------------------------------------------------------------- public virtual void test_discountFactor_withSpread_continuous() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expected = CURVE.yValue(relativeYearFraction) * Math.Exp(-SPREAD * relativeYearFraction); assertEquals(test.discountFactorWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0), expected, TOL); }
//------------------------------------------------------------------------- public virtual void test_discountFactor() { IsdaCreditDiscountFactors test = IsdaCreditDiscountFactors.of(USD, VALUATION, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(VALUATION, DATE_AFTER); double expected = Math.Exp(-relativeYearFraction * CURVE.yValue(relativeYearFraction)); assertEquals(test.discountFactor(DATE_AFTER), expected); }
//------------------------------------------------------------------------- public virtual void test_discountFactor() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expected = CURVE.yValue(relativeYearFraction); assertEquals(test.discountFactor(DATE_AFTER), expected); }
//------------------------------------------------------------------------- public virtual void test_discountFactor() { ZeroRateDiscountFactors test = ZeroRateDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expected = Math.Exp(-relativeYearFraction * CURVE.yValue(relativeYearFraction)); assertEquals(test.discountFactor(DATE_AFTER), expected); }
//------------------------------------------------------------------------- public virtual void test_presentValueWithSpread_df_spread_continuous() { CurrencyAmount computed = PRICER.presentValueWithSpread(PAYMENT, DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double expected = NOTIONAL_USD * DF * Math.Exp(-Z_SPREAD * relativeYearFraction); assertEquals(computed.Amount, expected, NOTIONAL_USD * TOL); }
//------------------------------------------------------------------------- public virtual void test_zeroRate() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double discountFactor = test.discountFactor(DATE_AFTER); double zeroRate = test.zeroRate(DATE_AFTER); assertEquals(Math.Exp(-zeroRate * relativeYearFraction), discountFactor); }
public virtual void test_discountFactorTimeDerivative() { DiscountFactors test = DiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double expectedP = test.discountFactor(relativeYearFraction + EPS); double expectedM = test.discountFactor(relativeYearFraction - EPS); assertEquals(test.discountFactorTimeDerivative(relativeYearFraction), (expectedP - expectedM) / (2 * EPS), TOL_FD); }
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_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 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_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_presentValueWithSpread_df_spread_periodic() { CurrencyAmount computed = PRICER.presentValueWithSpread(PAYMENT, DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double rate = (Math.Pow(DF, -1d / PERIOD_PER_YEAR / relativeYearFraction) - 1d) * PERIOD_PER_YEAR; double expected = NOTIONAL_USD * discountFactorFromPeriodicallyCompoundedRate(rate + Z_SPREAD, PERIOD_PER_YEAR, relativeYearFraction); assertEquals(computed.Amount, expected, NOTIONAL_USD * TOL); }
public virtual void test_zeroRate() { LegalEntitySurvivalProbabilities test = LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, DFS); double relativeYearFraction = ACT_365F.relativeYearFraction(VALUATION, DATE_AFTER); double discountFactor = test.survivalProbability(DATE_AFTER); double zeroRate = test.zeroRate(relativeYearFraction); assertEquals(Math.Exp(-zeroRate * relativeYearFraction), discountFactor); }
public virtual void test_zeroRate() { IsdaCreditDiscountFactors test = IsdaCreditDiscountFactors.of(USD, VALUATION, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(VALUATION, DATE_AFTER); double discountFactor = test.discountFactor(DATE_AFTER); double zeroRate = test.zeroRate(DATE_AFTER); assertEquals(Math.Exp(-zeroRate * relativeYearFraction), discountFactor); }
public virtual void test_zeroRatePointSensitivity_sensitivityCurrency() { IsdaCreditDiscountFactors test = IsdaCreditDiscountFactors.of(USD, VALUATION, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(VALUATION, DATE_AFTER); double df = Math.Exp(-relativeYearFraction * CURVE.yValue(relativeYearFraction)); ZeroRateSensitivity expected = ZeroRateSensitivity.of(USD, relativeYearFraction, GBP, -df * relativeYearFraction); assertEquals(test.zeroRatePointSensitivity(DATE_AFTER, GBP), expected); }
//------------------------------------------------------------------------- public virtual void test_discountFactorWithSpread_continuous() { ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double df = test.discountFactor(DATE_AFTER); double expected = df * Math.Exp(-SPREAD * relativeYearFraction); assertEquals(test.discountFactorWithSpread(DATE_AFTER, SPREAD, CONTINUOUS, 0), expected, TOLERANCE_DF); }
public virtual void test_expiry() { FxOptionVolatilitiesNode test = FxOptionVolatilitiesNode.of(EUR_GBP, SPOT_DATE_OFFSET, BDA, ValueType.BLACK_VOLATILITY, QUOTE_ID, Tenor.TENOR_3M, STRIKE); ZonedDateTime dateTime = LocalDate.of(2016, 1, 23).atStartOfDay(ZoneId.of("Europe/London")); DaysAdjustment expAdj = DaysAdjustment.ofBusinessDays(-2, LO_TA); double computed = test.timeToExpiry(dateTime, ACT_365F, REF_DATA); double expected = ACT_365F.relativeYearFraction(dateTime.toLocalDate(), expAdj.adjust(BDA.adjust(SPOT_DATE_OFFSET.adjust(dateTime.toLocalDate(), REF_DATA).plus(Tenor.TENOR_3M), REF_DATA), REF_DATA)); assertEquals(computed, expected); }
//------------------------------------------------------------------------- public virtual void test_unitParameterSensitivity() { IsdaCreditDiscountFactors test = IsdaCreditDiscountFactors.of(USD, VALUATION, CURVE); ZeroRateSensitivity sens = test.zeroRatePointSensitivity(DATE_AFTER); double relativeYearFraction = ACT_365F.relativeYearFraction(VALUATION, DATE_AFTER); CurrencyParameterSensitivities expected = CurrencyParameterSensitivities.of(CURVE.yValueParameterSensitivity(relativeYearFraction).multipliedBy(sens.Currency, sens.Sensitivity)); assertEquals(test.parameterSensitivity(sens), expected); }
public virtual void test_loadAllDates() { LocalDate sampleDate = ALL_DATES[3]; // 2017-04-21 ImmutableList <LocalDate> expDates = ImmutableList.of(LocalDate.of(2017, 0x7, 21), LocalDate.of(2017, 10, 0x7), LocalDate.of(2018, 4, 13), LocalDate.of(2019, 4, 12), LocalDate.of(2020, 3, 20), LocalDate.of(2021, 3, 19), LocalDate.of(2022, 3, 19), LocalDate.of(2023, 3, 17), LocalDate.of(2024, 6, 17), LocalDate.of(2025, 3, 18), LocalDate.of(2026, 3, 20), LocalDate.of(2027, 3, 20), LocalDate.of(2031, 12, 19), LocalDate.of(2037, 3, 17), LocalDate.of(2047, 3, 17), LocalDate.of(2056, 3, 17)); ImmutableList <string> expTenors = ImmutableList.of("3M", "6M", "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "15Y", "20Y", "30Y", "40Y"); RepoGroup repoGroup = RepoGroup.of("JP-REPO"); DoubleArray expRepoXValues = DoubleArray.of(3, n => ACT_365F.relativeYearFraction(sampleDate, expDates.get(n))); DoubleArray expRepoYValues = DoubleArray.of(-0.0019521, -0.0016021, -0.0022521); ImmutableList <LabelDateParameterMetadata> expRepoMetadata = IntStream.range(0, 3).mapToObj(n => LabelDateParameterMetadata.of(expDates.get(n), expTenors.get(n))).collect(Guavate.toImmutableList()); LegalEntityGroup legalEntityGroup = LegalEntityGroup.of("JP-GOVT"); DoubleArray expIssuerXValues = DoubleArray.of(expDates.size(), n => ACT_365F.relativeYearFraction(sampleDate, expDates.get(n))); DoubleArray expIssuerYValues = DoubleArray.of(-0.0019511690511744527, -0.001497422302092893, -0.0021798583657932176, -0.002215700360912938, -0.0021722324679574866, -0.001922059591219172, -0.0015461646763548528, -0.0014835851245462084, -0.001118669580570464, -5.476767138782941E-4, -2.2155596172855965E-4, 2.0333291172821893E-5, 0.00284500423293463, 0.005876533417933958, 0.007957581583531789, 0.009134630405512047); ImmutableList <LabelDateParameterMetadata> expIssuerMetadata = IntStream.range(0, expDates.size()).mapToObj(n => LabelDateParameterMetadata.of(expDates.get(n), expTenors.get(n))).collect(Guavate.toImmutableList()); ImmutableListMultimap <LocalDate, LegalEntityCurveGroup> allCurves = LegalEntityRatesCurvesCsvLoader.loadAllDates(ResourceLocator.of(GROUPS), ResourceLocator.of(SETTINGS), ImmutableList.of(ResourceLocator.of(CURVES_1), ResourceLocator.of(CURVES_2))); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: assertTrue(allCurves.Keys.containsAll(ALL_DATES)); ImmutableList <LegalEntityCurveGroup> groups = allCurves.get(sampleDate); assertEquals(groups.size(), 2); // group 0 LegalEntityCurveGroup group0 = groups.get(0); assertEquals(group0.Name, CurveGroupName.of("Default1")); // repo assertEquals(group0.RepoCurves.size(), 1); Curve repoCurve = group0.RepoCurves.get(Pair.of(repoGroup, JPY)); InterpolatedNodalCurve expectedRepoCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-REPO-1"), ACT_365F, expRepoMetadata), expRepoXValues, expRepoYValues, CurveInterpolators.LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT); assertEquals(repoCurve, expectedRepoCurve); // issuer assertEquals(group0.IssuerCurves.size(), 2); Curve issuerCurve = group0.IssuerCurves.get(Pair.of(legalEntityGroup, JPY)); InterpolatedNodalCurve expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-GOVT-1"), ACT_365F, expIssuerMetadata), expIssuerXValues, expIssuerYValues, CurveInterpolators.LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT); assertEquals(issuerCurve, expectedIssuerCurve); Curve usIssuerCurve = group0.IssuerCurves.get(Pair.of(LegalEntityGroup.of("US-GOVT"), USD)); expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("US-GOVT"), ACT_360, expIssuerMetadata), DoubleArray.of(expDates.size(), n => ACT_360.relativeYearFraction(sampleDate, expDates.get(n))), expIssuerYValues, CurveInterpolators.NATURAL_SPLINE, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT); assertEquals(usIssuerCurve, expectedIssuerCurve); // group 1 LegalEntityCurveGroup group1 = groups.get(1); assertEquals(group1.Name, CurveGroupName.of("Default2")); // repo repoCurve = group1.RepoCurves.get(Pair.of(repoGroup, JPY)); expectedRepoCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-REPO-2"), ACT_365F, expRepoMetadata), expRepoXValues, expRepoYValues, CurveInterpolators.DOUBLE_QUADRATIC, CurveExtrapolators.LINEAR, CurveExtrapolators.LINEAR); assertEquals(repoCurve, expectedRepoCurve); // issuer assertEquals(group1.IssuerCurves.size(), 1); issuerCurve = group1.IssuerCurves.get(Pair.of(legalEntityGroup, JPY)); expectedIssuerCurve = InterpolatedNodalCurve.of(Curves.zeroRates(CurveName.of("JP-GOVT-2"), ACT_365F, expIssuerMetadata), expIssuerXValues, expIssuerYValues, CurveInterpolators.DOUBLE_QUADRATIC, CurveExtrapolators.LINEAR, CurveExtrapolators.LINEAR); assertEquals(issuerCurve, expectedIssuerCurve); }
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_discountFactorWithSpread_periodic() { int periodPerYear = 4; ZeroRatePeriodicDiscountFactors test = ZeroRatePeriodicDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double discountFactorBase = test.discountFactor(DATE_AFTER); double onePlus = Math.Pow(discountFactorBase, -1.0d / (periodPerYear * relativeYearFraction)); double expected = Math.Pow(onePlus + SPREAD / periodPerYear, -periodPerYear * relativeYearFraction); assertEquals(test.discountFactorWithSpread(DATE_AFTER, SPREAD, PERIODIC, periodPerYear), expected, TOLERANCE_DF); }
//------------------------------------------------------------------------- public virtual void test_currencyParameterSensitivity() { SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); ZeroRateSensitivity sens = test.zeroRatePointSensitivity(DATE_AFTER); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double discountFactor = CURVE.yValue(relativeYearFraction); CurrencyParameterSensitivities expected = CurrencyParameterSensitivities.of(CURVE.yValueParameterSensitivity(relativeYearFraction).multipliedBy(-1d / discountFactor / relativeYearFraction).multipliedBy(sens.Currency, sens.Sensitivity)); assertEquals(test.parameterSensitivity(sens), expected); }
public virtual void test_discountFactor_withSpread_periodic() { int periodPerYear = 4; SimpleDiscountFactors test = SimpleDiscountFactors.of(GBP, DATE_VAL, CURVE); double relativeYearFraction = ACT_365F.relativeYearFraction(DATE_VAL, DATE_AFTER); double discountFactorBase = test.discountFactor(DATE_AFTER); double rate = (Math.Pow(discountFactorBase, -1d / periodPerYear / relativeYearFraction) - 1d) * periodPerYear; double expected = discountFactorFromPeriodicallyCompoundedRate(rate + SPREAD, periodPerYear, relativeYearFraction); assertEquals(test.discountFactorWithSpread(DATE_AFTER, SPREAD, PERIODIC, periodPerYear), expected, TOL); }
//------------------------------------------------------------------------- public virtual void test_presentValueSensitivity_df() { PointSensitivities point = PRICER.presentValueSensitivity(PAYMENT, DISCOUNT_FACTORS).build(); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double expected = -DF * relativeYearFraction * NOTIONAL_USD; ZeroRateSensitivity actual = (ZeroRateSensitivity)point.Sensitivities.get(0); assertEquals(actual.Currency, USD); assertEquals(actual.CurveCurrency, USD); assertEquals(actual.YearFraction, relativeYearFraction); assertEquals(actual.Sensitivity, expected, NOTIONAL_USD * TOL); }
public virtual void test_price() { double computed = OPTION_PRICER.price(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOLS); double futurePrice = FUTURE_PRICER.price(FUTURE_OPTION_PRODUCT.UnderlyingFuture, RATE_PROVIDER); double strike = FUTURE_OPTION_PRODUCT.StrikePrice; double expiryTime = ACT_365F.relativeYearFraction(VAL_DATE, FUTURE_OPTION_PRODUCT.ExpiryDate); double logMoneyness = Math.Log(strike / futurePrice); double vol = SURFACE.zValue(expiryTime, logMoneyness); double expected = BlackFormulaRepository.price(futurePrice, strike, expiryTime, vol, true); assertEquals(computed, expected, TOL); }
public virtual void test_theta_from_future_price() { double futurePrice = 1.1d; double computed = OPTION_PRICER.theta(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOLS, futurePrice); double strike = FUTURE_OPTION_PRODUCT.StrikePrice; double expiryTime = ACT_365F.relativeYearFraction(VAL_DATE, FUTURE_OPTION_PRODUCT.ExpiryDate); double logMoneyness = Math.Log(strike / futurePrice); double vol = SURFACE.zValue(expiryTime, logMoneyness); double expected = BlackFormulaRepository.driftlessTheta(futurePrice, strike, expiryTime, vol); assertEquals(computed, expected, TOL); }
//------------------------------------------------------------------------- public virtual void test_presentValueSensitivityWithSpread_df_spread_continuous() { PointSensitivities point = PRICER.presentValueSensitivityWithSpread(PAYMENT, DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0).build(); double relativeYearFraction = ACT_365F.relativeYearFraction(VAL_DATE_2014_01_22, PAYMENT_DATE); double expected = -DF *relativeYearFraction *NOTIONAL_USD *Math.Exp(-Z_SPREAD *relativeYearFraction); ZeroRateSensitivity actual = (ZeroRateSensitivity)point.Sensitivities.get(0); assertEquals(actual.Currency, USD); assertEquals(actual.CurveCurrency, USD); assertEquals(actual.YearFraction, relativeYearFraction); assertEquals(actual.Sensitivity, expected, NOTIONAL_USD * TOL); }
//------------------------------------------------------------------------- public virtual void test_resolve() { TermDeposit @base = TermDeposit.builder().buySell(SELL).startDate(START_DATE).endDate(END_DATE).businessDayAdjustment(BDA_MOD_FOLLOW).dayCount(ACT_365F).notional(NOTIONAL).currency(GBP).rate(RATE).build(); ResolvedTermDeposit test = @base.resolve(REF_DATA); LocalDate expectedEndDate = BDA_MOD_FOLLOW.adjust(END_DATE, REF_DATA); double expectedYearFraction = ACT_365F.yearFraction(START_DATE, expectedEndDate); assertEquals(test.StartDate, START_DATE); assertEquals(test.EndDate, expectedEndDate); assertEquals(test.Notional, -NOTIONAL); assertEquals(test.YearFraction, expectedYearFraction, EPS); assertEquals(test.Interest, -RATE * expectedYearFraction * NOTIONAL, NOTIONAL * EPS); assertEquals(test.Rate, RATE); assertEquals(test.Currency, GBP); }