/** * Gets the metadata of the parameter at the specified index. * <p> * If there is no specific parameter metadata, {@link SimpleSurfaceParameterMetadata} will be created. * * @param parameterIndex the zero-based index of the parameter to get * @return the metadata of the parameter * @throws IndexOutOfBoundsException if the index is invalid */ @Override public default ParameterMetadata getParameterMetadata(int parameterIndex) { return getMetadata().getParameterMetadata().map(pm -> pm.get(parameterIndex)) .orElse(SimpleSurfaceParameterMetadata.of( getMetadata().getXValueType(), getXValues().get(parameterIndex), getMetadata().getYValueType(), getYValues().get(parameterIndex))); }
@Override public UnitParameterSensitivity zValueParameterSensitivity(double x, double y) { return getMetadata().getParameterMetadata().isPresent() ? UnitParameterSensitivity.of( getMetadata().getSurfaceName(), getMetadata().getParameterMetadata().get(), deformationFunction.apply(DoublesPair.of(x, y)).getDerivatives()) : UnitParameterSensitivity.of( getMetadata().getSurfaceName(), deformationFunction.apply(DoublesPair.of(x, y)).getDerivatives()); }
@Override public ConstantSurface withMetadata(SurfaceMetadata metadata) { return new ConstantSurface(metadata.withParameterMetadata(null), zValue); }
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; }
sensi.add(entry.getValue()); SurfaceMetadata surfaceMetadata = metadata[i].withParameterMetadata(paramMetadata); sensiExpected = sensiExpected.combinedWith( CurrencyParameterSensitivity.of( surfaceMetadata.getSurfaceName(), surfaceMetadata.getParameterMetadata().get(), USD, DoubleArray.copyOf(sensi)));
/** * Gets the metadata of the parameter at the specified index. * <p> * If there is no specific parameter metadata, an empty instance will be returned. * * @param parameterIndex the zero-based index of the parameter to get * @return the metadata of the parameter * @throws IndexOutOfBoundsException if the index is invalid */ public default ParameterMetadata getParameterMetadata(int parameterIndex) { return getParameterMetadata().map(pm -> pm.get(parameterIndex)).orElse(ParameterMetadata.empty()); }
ParameterMetadata pm = metadata.getParameterMetadata(i); sorted.put(DoublesPair.of(xValues.get(i), yValues.get(i)), ObjDoublePair.of(pm, zValues.get(i))); SurfaceMetadata sortedMetadata = metadata.withParameterMetadata(Arrays.asList(sortedPm)); this.metadata = sortedMetadata; this.xValues = DoubleArray.ofUnsafe(sortedX); this.boundInterpolator = interpolator.bind(this.xValues, this.yValues, this.zValues); this.parameterMetadata = IntStream.range(0, getParameterCount()) .mapToObj(i -> sortedMetadata.getParameterMetadata(i)) .collect(toImmutableList());
/** * Gets the surface name. * * @return the surface name */ public default SurfaceName getName() { return getMetadata().getSurfaceName(); }
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"); } }
@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; }
sensi.add(entry.getValue()); SurfaceMetadata surfaceMetadata = metadata[i].withParameterMetadata(paramMetadata); sensiExpected = sensiExpected.combinedWith( CurrencyParameterSensitivity.of( surfaceMetadata.getSurfaceName(), surfaceMetadata.getParameterMetadata().get(), EUR, DoubleArray.copyOf(sensi)));
@Override public default ParameterMetadata getParameterMetadata(int parameterIndex) { return getMetadata().getParameterMetadata(parameterIndex); }
if (capFloorData.getDataType().equals(NORMAL_VOLATILITY)) { // correct initial surface metadata = Surfaces.blackVolatilityByExpiryStrike(bsDefinition.getName().getName(), bsDefinition.getDayCount()) .withParameterMetadata(metadata.getParameterMetadata().get()); initialVol = DoubleArray.of(nTotal, n -> volList.get(n) / (ratesProvider.iborIndexRates(index).rate(capList.get(n).getFinalPeriod().getIborRate().getObservation()) +
public void test_of() { DeformedSurface test = DeformedSurface.of(METADATA, SURFACE_ORG, FUNCTION); assertEquals(test.getDeformationFunction(), FUNCTION); assertEquals(test.getMetadata(), METADATA); assertEquals(test.getName(), METADATA.getSurfaceName()); assertEquals(test.getOriginalSurface(), SURFACE_ORG); assertEquals(test.getParameterCount(), SIZE); assertEquals(test.getParameter(2), SURFACE_ORG.getParameter(2)); assertEquals(test.getParameterMetadata(2), SURFACE_ORG.getParameterMetadata(2)); }
/** * Gets surface information of a specific type. * <p> * If the information is not found, an exception is thrown. * * @param <T> the type of the info * @param type the type to find * @return the surface information * @throws IllegalArgumentException if the information is not found */ public default <T> T getInfo(SurfaceInfoType<T> type) { return findInfo(type).orElseThrow(() -> new IllegalArgumentException( Messages.format("Surface info not found for type '{}'", type))); }
@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; }
private void validateInputs( SurfaceMetadata metadata, DoubleArray xValues, DoubleArray yValues, DoubleArray zValues, SurfaceInterpolator interpolator) { ArgChecker.notNull(metadata, "metadata"); ArgChecker.notNull(xValues, "times"); ArgChecker.notNull(yValues, "values"); ArgChecker.notNull(interpolator, "interpolator"); if (xValues.size() < 2) { throw new IllegalArgumentException("Length of x-values must be at least 2"); } if (xValues.size() != yValues.size()) { throw new IllegalArgumentException("Length of x-values and y-values must match"); } if (xValues.size() != zValues.size()) { throw new IllegalArgumentException("Length of x-values and z-values must match"); } metadata.getParameterMetadata().ifPresent(params -> { if (xValues.size() != params.size()) { throw new IllegalArgumentException("Length of x-values and parameter metadata must match when metadata present"); } }); }
@Override public SurfaceMetadata createMetadata(RawOptionData capFloorData) { List<GenericVolatilitySurfacePeriodParameterMetadata> list = new ArrayList<>(); ImmutableList<Period> expiries = capFloorData.getExpiries(); int nExpiries = expiries.size(); DoubleArray strikes = capFloorData.getStrikes(); int nStrikes = strikes.size(); for (int i = 0; i < nExpiries; ++i) { for (int j = 0; j < nStrikes; ++j) { if (Double.isFinite(capFloorData.getData().get(i, j))) { list.add(GenericVolatilitySurfacePeriodParameterMetadata.of(expiries.get(i), SimpleStrike.of(strikes.get(j)))); } } } SurfaceMetadata metadata; if (capFloorData.getDataType().equals(ValueType.BLACK_VOLATILITY)) { metadata = Surfaces.blackVolatilityByExpiryStrike(name.getName(), dayCount); } else if (capFloorData.getDataType().equals(ValueType.NORMAL_VOLATILITY)) { metadata = Surfaces.normalVolatilityByExpiryStrike(name.getName(), dayCount); } else { throw new IllegalArgumentException("Data type not supported"); } return metadata.withParameterMetadata(list); }
.zValueParameterSensitivity(expiryTime, TEST_TENOR[i]); CurrencyParameterSensitivity alphaSensiObj = sensiComputed.getSensitivity( SwaptionSabrRateVolatilityDataSet.META_ALPHA.getSurfaceName(), USD); CurrencyParameterSensitivity betaSensiObj = sensiComputed.getSensitivity( SwaptionSabrRateVolatilityDataSet.META_BETA_USD.getSurfaceName(), USD); CurrencyParameterSensitivity rhoSensiObj = sensiComputed.getSensitivity( SwaptionSabrRateVolatilityDataSet.META_RHO.getSurfaceName(), USD); CurrencyParameterSensitivity nuSensiObj = sensiComputed.getSensitivity( SwaptionSabrRateVolatilityDataSet.META_NU.getSurfaceName(), USD); DoubleArray alphaNodeSensiComputed = alphaSensiObj.getSensitivity(); DoubleArray betaNodeSensiComputed = betaSensiObj.getSensitivity();