public void curveConstructionTest( final InstrumentDefinition<?>[][][] definitions, final MulticurveProviderDiscount curves, final boolean withToday, final int block) { final int nbBlocks = definitions.length; for (int loopblock = 0; loopblock < nbBlocks; loopblock++) { final InstrumentDerivative[][] instruments = convert(definitions[loopblock], withToday); final double[][] pv = new double[instruments.length][]; for (int loopcurve = 0; loopcurve < instruments.length; loopcurve++) { pv[loopcurve] = new double[instruments[loopcurve].length]; for (int loopins = 0; loopins < instruments[loopcurve].length; loopins++) { pv[loopcurve][loopins] = curves .getFxRates() .convert(instruments[loopcurve][loopins].accept(PVC, curves), AUD) .getAmount(); assertEquals( "Curve construction: block " + block + ", unit " + loopblock + " - instrument " + loopins, 0, pv[loopcurve][loopins], TOLERANCE_CAL); } } } }
@Test public void parSpreadMarketQuoteDiscountingCalculator() { final double psmq = SWAP_MULTI_LEG.accept(PSMQDC, MULTICURVES); final double pv = -MULTICURVES .getFxRates() .convert( SWAP_MULTI_LEG.accept(PVDC, MULTICURVES), SWAP_MULTI_LEG.getLegs()[0].getCurrency()) .getAmount(); final double pvbp = SWAP_MULTI_LEG.getLegs()[0].accept(PVMQSC, MULTICURVES); assertEquals( "SwapMultileg: parSpreadMarketQuoteDiscountingCalculator", psmq, pv / pvbp, TOLERANCE_RATE); }
@Test public void parSpreadMarketQuoteCurveSensitivityDiscountingCalculator() { final double pv = MULTICURVES .getFxRates() .convert( SWAP_MULTI_LEG.accept(PVDC, MULTICURVES), SWAP_MULTI_LEG.getLegs()[0].getCurrency()) .getAmount(); final double pvbp = SWAP_MULTI_LEG.getLegs()[0].accept(PVMQSC, MULTICURVES); final MulticurveSensitivity pvcs = SWAP_MULTI_LEG .accept(PVCSDC, MULTICURVES) .converted(EUR, MULTICURVES.getFxRates()) .getSensitivity(EUR); final MulticurveSensitivity pvbpcs = SWAP_MULTI_LEG.getLegs()[0].accept(PVMQSCSC, MULTICURVES); final MulticurveSensitivity psmqcsExpected = pvcs.multipliedBy(-1.0d / pvbp).plus(pvbpcs.multipliedBy(pv / (pvbp * pvbp))).cleaned(); final MulticurveSensitivity psmqcs = SWAP_MULTI_LEG.accept(PSMQCSDC, MULTICURVES).cleaned(); AssertSensitivityObjects.assertEquals( "SwapMultileg: presentValueCurveSensitivityDiscountingCalculator", psmqcs, psmqcsExpected, TOLERANCE_RATE_DELTA); }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final MulticurveProviderDiscount object) { final Map<Currency, YieldAndDiscountCurve> discountingCurves = object.getDiscountingCurves(); for (final Map.Entry<Currency, YieldAndDiscountCurve> entry : discountingCurves.entrySet()) { message.add(CURRENCY_FIELD, entry.getKey().getCode()); serializer.addToMessageWithClassHeaders( message, DISCOUNTING_CURVE_FIELD, null, entry.getValue()); } final Map<IborIndex, YieldAndDiscountCurve> forwardIborCurves = object.getForwardIborCurves(); for (final Map.Entry<IborIndex, YieldAndDiscountCurve> entry : forwardIborCurves.entrySet()) { serializer.addToMessageWithClassHeaders(message, INDEX_IBOR_FIELD, null, entry.getKey()); serializer.addToMessageWithClassHeaders(message, INDEX_IBOR_CURVE, null, entry.getValue()); } final Map<IndexON, YieldAndDiscountCurve> forwardONCurves = object.getForwardONCurves(); for (final Map.Entry<IndexON, YieldAndDiscountCurve> entry : forwardONCurves.entrySet()) { serializer.addToMessageWithClassHeaders(message, INDEX_ON_FIELD, null, entry.getKey()); serializer.addToMessageWithClassHeaders( message, OVERNIGHT_CURVE_FIELD, null, entry.getValue()); } serializer.addToMessageWithClassHeaders(message, FX_MATRIX_FIELD, null, object.getFxRates()); }
@Test(enabled = false) /** Tests present value curve sensitivity when the valuation date is on trade date. */ public void presentValueCurveSensitivityStability() { // 5Yx5Y final MultipleCurrencyParameterSensitivity pvpsExact = PS_HW_C.calculateSensitivity( SWAPTION_SHORT_RECEIVER, HW_MULTICURVES, HW_MULTICURVES.getMulticurveProvider().getAllNames()); final double derivativeExact = pvpsExact.totalSensitivity(MULTICURVES.getFxRates(), EUR); final double startingShift = 1.0E-4; final double ratio = Math.sqrt(2.0); final int nbShift = 55; final double[] eps = new double[nbShift + 1]; final double[] derivative_FD = new double[nbShift]; final double[] diff = new double[nbShift]; eps[0] = startingShift; for (int loopshift = 0; loopshift < nbShift; loopshift++) { final ParameterSensitivityHullWhiteDiscountInterpolatedFDCalculator fdShift = new ParameterSensitivityHullWhiteDiscountInterpolatedFDCalculator(PVHWC, eps[loopshift]); final MultipleCurrencyParameterSensitivity pvpsFD = fdShift.calculateSensitivity(SWAPTION_SHORT_RECEIVER, HW_MULTICURVES); derivative_FD[loopshift] = pvpsFD.totalSensitivity(MULTICURVES.getFxRates(), EUR); diff[loopshift] = derivative_FD[loopshift] - derivativeExact; eps[loopshift + 1] = eps[loopshift] / ratio; } // 1Mx5Y final Period expirationPeriod = Period.ofDays( 1); // Period.ofDays(1); Period.ofDays(7); Period.ofMonths(1); Period.ofYears(1); // Period.ofYears(10); final ZonedDateTime expiryDateExp = ScheduleCalculator.getAdjustedDate(REFERENCE_DATE, expirationPeriod, EURIBOR6M, CALENDAR); final ZonedDateTime settlementDateExp = ScheduleCalculator.getAdjustedDate(expiryDateExp, SPOT_LAG, CALENDAR); final double ATM = 0.0151; // 1W: 1.52% - 1M: 1.52% - 1Y: 1.51% - 10Y: 1.51% final SwapFixedIborDefinition swapExpx5YDefinition = SwapFixedIborDefinition.from( settlementDateExp, SWAP_TENOR, EUR1YEURIBOR6M, NOTIONAL, ATM, !FIXED_IS_PAYER); final SwaptionPhysicalFixedIborDefinition swaptionExpx5YDefinition = SwaptionPhysicalFixedIborDefinition.from(EXPIRY_DATE, swapExpx5YDefinition, !IS_LONG); final SwaptionPhysicalFixedIbor swaptionExpx5Y = swaptionExpx5YDefinition.toDerivative(REFERENCE_DATE); // final double forward = swaptionExpx5Y.getUnderlyingSwap().accept(PRDC, MULTICURVES); final MultipleCurrencyParameterSensitivity pvpsExactExp = PS_HW_C.calculateSensitivity( swaptionExpx5Y, HW_MULTICURVES, HW_MULTICURVES.getMulticurveProvider().getAllNames()); final double derivativeExactExp = pvpsExactExp.totalSensitivity(MULTICURVES.getFxRates(), EUR); final double[] derivative_FDExp = new double[nbShift]; final double[] diffExp = new double[nbShift]; for (int loopshift = 0; loopshift < nbShift; loopshift++) { final ParameterSensitivityHullWhiteDiscountInterpolatedFDCalculator fdShift = new ParameterSensitivityHullWhiteDiscountInterpolatedFDCalculator(PVHWC, eps[loopshift]); final MultipleCurrencyParameterSensitivity pvpsFD = fdShift.calculateSensitivity(swaptionExpx5Y, HW_MULTICURVES); derivative_FDExp[loopshift] = pvpsFD.totalSensitivity(MULTICURVES.getFxRates(), EUR); diffExp[loopshift] = derivative_FDExp[loopshift] - derivativeExactExp; } // int t = 0; // t++; }