private static void validate(Surface surface, DayCount dayCount) { if (!surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT).orElse(dayCount).equals(dayCount)) { throw new IllegalArgumentException("SABR surfaces must have the same day count"); } }
/** * Gets the surface name. * * @return the surface name */ public default SurfaceName getName() { return getMetadata().getSurfaceName(); }
@Override public default ParameterMetadata getParameterMetadata(int parameterIndex) { return getMetadata().getParameterMetadata(parameterIndex); }
private static void validate(Surface surface, String name, ValueType zType) { ArgChecker.notNull(surface, name); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for SABR volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect y-value type for SABR volatilities"); ValueType zValueType = surface.getMetadata().getZValueType(); zValueType.checkEquals( zType, "Incorrect z-value type for SABR volatilities"); }
@ImmutableConstructor private BlackBondFutureExpiryLogMoneynessVolatilities( ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Black volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.LOG_MONEYNESS, "Incorrect y-value type for Black volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.BLACK_VOLATILITY, "Incorrect z-value type for Black volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.valuationDateTime = valuationDateTime; this.surface = surface; this.dayCount = dayCount; }
@ImmutableConstructor private NormalIborFutureOptionExpirySimpleMoneynessVolatilities( IborIndex index, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(index, "index"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Normal volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.SIMPLE_MONEYNESS, "Incorrect y-value type for Normal volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.NORMAL_VOLATILITY, "Incorrect z-value type for Normal volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); MoneynessType moneynessType = surface.getMetadata().findInfo(SurfaceInfoType.MONEYNESS_TYPE) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing MoneynessType")); this.index = index; this.valuationDateTime = valuationDateTime; this.surface = surface; this.moneynessOnPrice = moneynessType == MoneynessType.PRICE; this.dayCount = dayCount; }
@ImmutableConstructor private NormalSwaptionExpiryStrikeVolatilities( FixedIborSwapConvention convention, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(convention, "convention"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Normal volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.STRIKE, "Incorrect y-value type for Normal volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.NORMAL_VOLATILITY, "Incorrect z-value type for Normal volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.valuationDateTime = valuationDateTime; this.surface = surface; this.convention = convention; this.dayCount = dayCount; }
@ImmutableConstructor private NormalSwaptionExpiryTenorVolatilities( FixedIborSwapConvention convention, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(convention, "convention"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Normal volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect y-value type for Normal volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.NORMAL_VOLATILITY, "Incorrect z-value type for Normal volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.valuationDateTime = valuationDateTime; this.surface = surface; this.convention = convention; this.dayCount = dayCount; }
@ImmutableConstructor private BlackSwaptionExpiryTenorVolatilities( FixedIborSwapConvention convention, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(convention, "convention"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Black volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect y-value type for Black volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.BLACK_VOLATILITY, "Incorrect z-value type for Black volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.valuationDateTime = valuationDateTime; this.surface = surface; this.convention = convention; this.dayCount = dayCount; }
@ImmutableConstructor private BlackIborCapletFloorletExpiryStrikeVolatilities( IborIndex index, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(index, "index"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Black volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.STRIKE, "Incorrect y-value type for Black volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.BLACK_VOLATILITY, "Incorrect z-value type for Black volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.index = index; this.valuationDateTime = valuationDateTime; this.surface = surface; this.dayCount = dayCount; }
@ImmutableConstructor private NormalSwaptionExpirySimpleMoneynessVolatilities( FixedIborSwapConvention convention, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(convention, "convention"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Normal volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.SIMPLE_MONEYNESS, "Incorrect y-value type for Normal volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.NORMAL_VOLATILITY, "Incorrect z-value type for Normal volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.valuationDateTime = valuationDateTime; this.surface = surface; this.convention = convention; this.dayCount = dayCount; }
@ImmutableConstructor private NormalIborCapletFloorletExpiryStrikeVolatilities( IborIndex index, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(index, "index"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Normal volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.STRIKE, "Incorrect y-value type for Normal volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.NORMAL_VOLATILITY, "Incorrect z-value type for Normal volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.index = index; this.valuationDateTime = valuationDateTime; this.surface = surface; this.dayCount = dayCount; }
@ImmutableConstructor private BlackFxOptionSurfaceVolatilities( FxOptionVolatilitiesName name, CurrencyPair currencyPair, ZonedDateTime valuationDateTime, Surface surface) { ArgChecker.notNull(name, "name"); ArgChecker.notNull(currencyPair, "currencyPair"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Black volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.STRIKE, "Incorrect y-value type for Black volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.BLACK_VOLATILITY, "Incorrect z-value type for Black volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); this.name = name; this.currencyPair = currencyPair; this.valuationDateTime = valuationDateTime; this.surface = surface; this.dayCount = dayCount; }
@ImmutableConstructor private ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities( IborIndex index, ZonedDateTime valuationDateTime, Surface surface, Curve shiftCurve) { ArgChecker.notNull(index, "index"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(surface, "surface"); ArgChecker.notNull(shiftCurve, "shiftCurve"); surface.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Black volatilities"); surface.getMetadata().getYValueType().checkEquals( ValueType.STRIKE, "Incorrect y-value type for Black volatilities"); surface.getMetadata().getZValueType().checkEquals( ValueType.BLACK_VOLATILITY, "Incorrect z-value type for Black volatilities"); DayCount dayCount = surface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); validate(shiftCurve, dayCount); this.index = index; this.valuationDateTime = valuationDateTime; this.surface = surface; this.dayCount = dayCount; this.shiftCurve = shiftCurve; }
@ImmutableConstructor private SabrInterestRateParameters( Surface alphaSurface, Surface betaSurface, Surface rhoSurface, Surface nuSurface, Surface shiftSurface, SabrVolatilityFormula sabrFormula) { validate(alphaSurface, "alphaSurface", ValueType.SABR_ALPHA); validate(betaSurface, "betaSurface", ValueType.SABR_BETA); validate(rhoSurface, "rhoSurface", ValueType.SABR_RHO); validate(nuSurface, "nuSurface", ValueType.SABR_NU); ArgChecker.notNull(shiftSurface, "shiftSurface"); ArgChecker.notNull(sabrFormula, "sabrFormula"); DayCount dayCount = alphaSurface.getMetadata().findInfo(SurfaceInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect surface metadata, missing DayCount")); validate(betaSurface, dayCount); validate(rhoSurface, dayCount); validate(nuSurface, dayCount); validate(shiftSurface, dayCount); this.alphaSurface = alphaSurface; this.betaSurface = betaSurface; this.rhoSurface = rhoSurface; this.nuSurface = nuSurface; this.shiftSurface = shiftSurface; this.sabrVolatilityFormula = sabrFormula; this.dayCount = dayCount; this.paramCombiner = ParameterizedDataCombiner.of(alphaSurface, betaSurface, rhoSurface, nuSurface, shiftSurface); }
double fdShift = 1.0E-5; SurfaceMetadata alphaMetadata = calibrated.getParameters().getAlphaSurface().getMetadata(); Optional<List<ParameterMetadata>> alphaParameterMetadataOption = alphaMetadata.getParameterMetadata(); assertTrue(alphaParameterMetadataOption.isPresent()); List<ParameterMetadata> alphaParameterMetadata = alphaParameterMetadataOption.get(); List<DoubleArray> alphaJacobian = calibrated.getDataSensitivityAlpha().get(); SurfaceMetadata rhoMetadata = calibrated.getParameters().getRhoSurface().getMetadata(); Optional<List<ParameterMetadata>> rhoParameterMetadataOption = rhoMetadata.getParameterMetadata(); assertTrue(rhoParameterMetadataOption.isPresent()); List<ParameterMetadata> rhoParameterMetadata = rhoParameterMetadataOption.get(); List<DoubleArray> rhoJacobian = calibrated.getDataSensitivityRho().get(); SurfaceMetadata nuMetadata = calibrated.getParameters().getNuSurface().getMetadata(); Optional<List<ParameterMetadata>> nuParameterMetadataOption = nuMetadata.getParameterMetadata(); assertTrue(nuParameterMetadataOption.isPresent());
double fdShift = 1.0E-5; SurfaceMetadata alphaMetadata = calibrated.getParameters().getAlphaSurface().getMetadata(); Optional<List<ParameterMetadata>> alphaParameterMetadataOption = alphaMetadata.getParameterMetadata(); assertTrue(alphaParameterMetadataOption.isPresent()); List<ParameterMetadata> alphaParameterMetadata = alphaParameterMetadataOption.get(); List<DoubleArray> alphaJacobian = calibrated.getDataSensitivityAlpha().get(); SurfaceMetadata rhoMetadata = calibrated.getParameters().getRhoSurface().getMetadata(); Optional<List<ParameterMetadata>> rhoParameterMetadataOption = rhoMetadata.getParameterMetadata(); assertTrue(rhoParameterMetadataOption.isPresent()); List<ParameterMetadata> rhoParameterMetadata = rhoParameterMetadataOption.get(); List<DoubleArray> rhoJacobian = calibrated.getDataSensitivityRho().get(); SurfaceMetadata nuMetadata = calibrated.getParameters().getNuSurface().getMetadata(); Optional<List<ParameterMetadata>> nuParameterMetadataOption = nuMetadata.getParameterMetadata(); assertTrue(nuParameterMetadataOption.isPresent());