private static void validate(Curve curve, DayCount dayCount) { if (!curve.getMetadata().findInfo(CurveInfoType.DAY_COUNT).orElse(dayCount).equals(dayCount)) { throw new IllegalArgumentException("SABR curves must have the same day count"); } }
private static void validate(Curve curve, DayCount dayCount) { if (!curve.getMetadata().findInfo(CurveInfoType.DAY_COUNT).orElse(dayCount).equals(dayCount)) { throw new IllegalArgumentException("shift curve must have the same day count as surface"); } }
/** * Gets curve information of a specific type. * <p> * If the information is not found, an exception is thrown. * <p> * The most common information is the {@linkplain CurveInfoType#DAY_COUNT day count} * and {@linkplain CurveInfoType#JACOBIAN curve calibration information}. * * @param <T> the type of the info * @param type the type to find * @return the curve information * @throws IllegalArgumentException if the information is not found */ public default <T> T getInfo(CurveInfoType<T> type) { return findInfo(type).orElseThrow(() -> new IllegalArgumentException( Messages.format("Curve info not found for type '{}'", type))); }
@ImmutableConstructor private IsdaCreditDiscountFactors( Currency currency, LocalDate valuationDate, NodalCurve curve) { ArgChecker.notNull(currency, "currency"); ArgChecker.notNull(valuationDate, "valuationDate"); ArgChecker.notNull(curve, "curve"); DayCount dayCount = curve.getMetadata().findInfo(DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect curve metadata, missing DayCount")); this.currency = currency; this.valuationDate = valuationDate; this.curve = curve; this.dayCount = dayCount; }
@ImmutableConstructor private ZeroRatePeriodicDiscountFactors( Currency currency, LocalDate valuationDate, Curve curve) { ArgChecker.notNull(currency, "currency"); ArgChecker.notNull(valuationDate, "valuationDate"); ArgChecker.notNull(curve, "curve"); Optional<Integer> frequencyOpt = curve.getMetadata().findInfo(CurveInfoType.COMPOUNDING_PER_YEAR); ArgChecker.isTrue(frequencyOpt.isPresent(), "Compounding per year must be present for periodicaly compounded curve "); ArgChecker.isTrue(frequencyOpt.get() > 0, "Compounding per year must be positive"); curve.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for zero-rate discount curve"); curve.getMetadata().getYValueType().checkEquals( ValueType.ZERO_RATE, "Incorrect y-value type for zero-rate discount curve"); DayCount dayCount = curve.getMetadata().findInfo(CurveInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect curve metadata, missing DayCount")); this.currency = currency; this.valuationDate = valuationDate; this.curve = curve; this.dayCount = dayCount; this.frequency = frequencyOpt.get(); }
.orElseThrow(() -> new IllegalArgumentException( "Market Quote sensitivity requires curve: " + paramSens.getMarketDataName())); JacobianCalibrationMatrix info = curve.getMetadata().findInfo(CurveInfoType.JACOBIAN) .orElseThrow(() -> new IllegalArgumentException( "Market Quote sensitivity requires Jacobian calibration information"));
.orElseThrow(() -> new IllegalArgumentException( "Market Quote sensitivity requires curve: " + paramSens.getMarketDataName())); JacobianCalibrationMatrix info = curve.getMetadata().findInfo(CurveInfoType.JACOBIAN) .orElseThrow(() -> new IllegalArgumentException( "Market Quote sensitivity requires Jacobian calibration information"));
@ImmutableConstructor private BlackFxOptionFlatVolatilities( CurrencyPair currencyPair, ZonedDateTime valuationDateTime, Curve curve) { ArgChecker.notNull(currencyPair, "currencyPair"); ArgChecker.notNull(valuationDateTime, "valuationDateTime"); ArgChecker.notNull(curve, "curve"); curve.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for Black volatilities"); curve.getMetadata().getYValueType().checkEquals( ValueType.BLACK_VOLATILITY, "Incorrect y-value type for Black volatilities"); DayCount dayCount = curve.getMetadata().findInfo(CurveInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect curve metadata, missing DayCount")); this.currencyPair = currencyPair; this.valuationDateTime = valuationDateTime; this.curve = curve; this.dayCount = dayCount; }
@ImmutableConstructor private ZeroRateDiscountFactors( Currency currency, LocalDate valuationDate, Curve curve) { ArgChecker.notNull(currency, "currency"); ArgChecker.notNull(valuationDate, "valuationDate"); ArgChecker.notNull(curve, "curve"); curve.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for zero-rate discount curve"); curve.getMetadata().getYValueType().checkEquals( ValueType.ZERO_RATE, "Incorrect y-value type for zero-rate discount curve"); DayCount dayCount = curve.getMetadata().findInfo(CurveInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect curve metadata, missing DayCount")); this.currency = currency; this.valuationDate = valuationDate; this.curve = curve; this.dayCount = dayCount; }
@ImmutableConstructor private SimpleDiscountFactors( Currency currency, LocalDate valuationDate, Curve curve) { ArgChecker.notNull(currency, "currency"); ArgChecker.notNull(valuationDate, "valuationDate"); ArgChecker.notNull(curve, "curve"); curve.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for discount curve"); curve.getMetadata().getYValueType().checkEquals( ValueType.DISCOUNT_FACTOR, "Incorrect y-value type for discount curve"); DayCount dayCount = curve.getMetadata().findInfo(CurveInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect curve metadata, missing DayCount")); this.currency = currency; this.valuationDate = valuationDate; this.curve = curve; this.dayCount = dayCount; }
ArgChecker.isTrue(curveOpt.isPresent(), "Curve {} in the sensitiivty is not present in the provider", name); Curve curve = curveOpt.get(); Optional<DoubleArray> pvSensiOpt = curve.getMetadata().findInfo(CurveInfoType.PV_SENSITIVITY_TO_MARKET_QUOTE); ArgChecker.isTrue(pvSensiOpt.isPresent(), "Present value sensitivity curve info is required"); DoubleArray pvSensi = pvSensiOpt.get();
/** * Creates a curve as the sum of a base curve and a spread curve. * <p> * The metadata of the combined curve will be created form the base curve and spread curve. * * @param baseCurve the base curve * @param spreadCurve the spread curve * @return the combined curve */ public static CombinedCurve of(Curve baseCurve, Curve spreadCurve) { CurveMetadata baseMetadata = baseCurve.getMetadata(); CurveMetadata spreadMetadata = spreadCurve.getMetadata(); List<ParameterMetadata> paramMeta = Stream.concat( IntStream.range(0, baseCurve.getParameterCount()) .mapToObj(i -> baseCurve.getParameterMetadata(i)), IntStream.range(0, spreadCurve.getParameterCount()) .mapToObj(i -> spreadCurve.getParameterMetadata(i))) .collect(toImmutableList()); DefaultCurveMetadataBuilder metadataBuilder = DefaultCurveMetadata.builder() .curveName(baseCurve.getName().getName() + "+" + spreadMetadata.getCurveName().getName()) .xValueType(baseMetadata.getXValueType()) .yValueType(baseMetadata.getYValueType()) .parameterMetadata(paramMeta); if (baseMetadata.findInfo(CurveInfoType.DAY_COUNT).isPresent()) { metadataBuilder.addInfo( CurveInfoType.DAY_COUNT, baseMetadata.getInfo(CurveInfoType.DAY_COUNT)); } return of(baseCurve, spreadCurve, metadataBuilder.build()); }
@ImmutableConstructor private SimpleIborIndexRates( IborIndex index, LocalDate valuationDate, Curve curve, LocalDateDoubleTimeSeries fixings) { ArgChecker.notNull(index, "index"); ArgChecker.notNull(valuationDate, "valuationDate"); ArgChecker.notNull(curve, "curve"); ArgChecker.notNull(fixings, "fixings"); curve.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for ibor curve"); curve.getMetadata().getYValueType().checkEquals( ValueType.FORWARD_RATE, "Incorrect y-value type for ibor curve"); DayCount dayCount = curve.getMetadata().findInfo(CurveInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect curve metadata, missing DayCount")); this.valuationDate = valuationDate; this.index = index; this.curve = curve; this.fixings = fixings; this.dayCount = dayCount; }
mqsGroup.put(cps.getName(), pvSensitivityExpected); assertTrue(curve.isPresent()); assertTrue(curve.get().getMetadata().findInfo(CurveInfoType.PV_SENSITIVITY_TO_MARKET_QUOTE).isPresent()); DoubleArray pvSensitivityMetadata = curve.get().getMetadata().findInfo(CurveInfoType.PV_SENSITIVITY_TO_MARKET_QUOTE).get(); assertTrue(pvSensitivityExpected.equalWithTolerance(pvSensitivityMetadata, 1.0E-10));
/** * Obtains an instance from a curve. * <p> * The curve is specified by an instance of {@link Curve}, such as {@link InterpolatedNodalCurve}. * The curve must have x-values of {@linkplain ValueType#YEAR_FRACTION year fractions} with * the day count specified. The y-values must be {@linkplain ValueType#ZERO_RATE zero rates} * or {@linkplain ValueType#DISCOUNT_FACTOR discount factors}. * * @param currency the currency * @param valuationDate the valuation date for which the curve is valid * @param curve the underlying curve * @return the discount factors view */ public static DiscountFactors of(Currency currency, LocalDate valuationDate, Curve curve) { if (curve.getMetadata().getYValueType().equals(ValueType.DISCOUNT_FACTOR)) { return SimpleDiscountFactors.of(currency, valuationDate, curve); } if (curve.getMetadata().getYValueType().equals(ValueType.ZERO_RATE)) { Optional<Integer> frequencyOpt = curve.getMetadata().findInfo(CurveInfoType.COMPOUNDING_PER_YEAR); if (frequencyOpt.isPresent()) { return ZeroRatePeriodicDiscountFactors.of(currency, valuationDate, curve); } return ZeroRateDiscountFactors.of(currency, valuationDate, curve); } throw new IllegalArgumentException(Messages.format( "Unknown value type in discount curve, must be 'DiscountFactor' or 'ZeroRate' but was '{}'", curve.getMetadata().getYValueType())); }
@ImmutableConstructor private SabrParameters( Curve alphaCurve, Curve betaCurve, Curve rhoCurve, Curve nuCurve, Curve shiftCurve, SabrVolatilityFormula sabrFormula) { validate(alphaCurve, "alphaCurve", ValueType.SABR_ALPHA); validate(betaCurve, "betaCurve", ValueType.SABR_BETA); validate(rhoCurve, "rhoCurve", ValueType.SABR_RHO); validate(nuCurve, "nuCurve", ValueType.SABR_NU); ArgChecker.notNull(shiftCurve, "shiftCurve"); ArgChecker.notNull(sabrFormula, "sabrFormula"); DayCount dayCount = alphaCurve.getMetadata().findInfo(CurveInfoType.DAY_COUNT) .orElseThrow(() -> new IllegalArgumentException("Incorrect curve metadata, missing DayCount")); validate(betaCurve, dayCount); validate(rhoCurve, dayCount); validate(nuCurve, dayCount); validate(shiftCurve, dayCount); this.alphaCurve = alphaCurve; this.betaCurve = betaCurve; this.rhoCurve = rhoCurve; this.nuCurve = nuCurve; this.shiftCurve = shiftCurve; this.sabrVolatilityFormula = sabrFormula; this.dayCount = dayCount; this.paramCombiner = ParameterizedDataCombiner.of(alphaCurve, betaCurve, rhoCurve, nuCurve, shiftCurve); }
CurveSensitivityUtils.jacobianFromMarketQuoteSensitivities(LIST_CURVE_NAMES_1, trades, sensitivityFunction); DoubleMatrix jiExpected = MULTICURVE_EUR_SINGLE_CALIBRATED.findData(EUR_SINGLE_NAME).get().getMetadata().findInfo(CurveInfoType.JACOBIAN).get() .getJacobianMatrix();
.calibrate(definition, marketDataDw, ratesProvider, REF_DATA).getSurvivalProbabilities(); for (int j = 0; j < nNode; ++j) { double computed = df.getCurve().getMetadata().findInfo(CurveInfoType.JACOBIAN).get().getJacobianMatrix().get(j, i); double expected = 0.5 * (ccUp.getCurve().getYValues().get(j) - ccDw.getCurve().getYValues().get(j)) / EPS; assertEquals(computed, expected, EPS * 10d);
false, false, REF_DATA).getSurvivalProbabilities(); for (int j = 0; j < nNode; ++j) { double computed = df.getCurve().getMetadata().findInfo(CurveInfoType.JACOBIAN).get().getJacobianMatrix().get(j, i); double expected = 0.5 * (ccUp.getCurve().getYValues().get(j) - ccDw.getCurve().getYValues().get(j)) / eps; assertEquals(computed, expected, eps * 10d);
IsdaCreditDiscountFactors hcDw = CALIBRATOR.calibrate(curveDefinition, quotesDw, REF_DATA); for (int j = 0; j < nCurveNode; ++j) { double computed = curve.getCurve().getMetadata().findInfo(CurveInfoType.JACOBIAN).get().getJacobianMatrix().get(j, i); double expected = 0.5 * (hcUp.getCurve().getYValues().get(j) - hcDw.getCurve().getYValues().get(j)) / EPS; assertEquals(computed, expected, EPS * 10d);