/** * Gets the metadata of the parameter at the specified index. * <p> * If there is no specific parameter metadata, {@link SimpleCurveParameterMetadata} 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(SimpleCurveParameterMetadata.of(getMetadata().getXValueType(), getXValues().get(parameterIndex))); }
private DoubleArray buildNodeTimes(LocalDate valuationDate, CurveMetadata metadata) { if (metadata.getXValueType().equals(ValueType.YEAR_FRACTION)) { return DoubleArray.of(getParameterCount(), i -> { LocalDate nodeDate = ((DatedParameterMetadata) metadata.getParameterMetadata().get().get(i)).getDate(); return getDayCount().get().yearFraction(valuationDate, nodeDate); }); } else if (metadata.getXValueType().equals(ValueType.MONTHS)) { return DoubleArray.of(getParameterCount(), i -> { LocalDate nodeDate = ((DatedParameterMetadata) metadata.getParameterMetadata().get().get(i)).getDate(); return YearMonth.from(valuationDate).until(YearMonth.from(nodeDate), MONTHS); }); } else { throw new IllegalArgumentException("Metadata XValueType should be YearFraction or Months in curve definition"); } }
CurveMetadata spreadMetadata = spreadCurve.getMetadata(); if (!baseMetadata.getXValueType().equals(metadata.getXValueType())) { throw new IllegalArgumentException(Messages.format( "xValueType is {} in baseCurve, but {} in CombinedCurve", baseMetadata.getXValueType(), metadata.getXValueType())); if (!spreadMetadata.getXValueType().equals(metadata.getXValueType())) { throw new IllegalArgumentException(Messages.format( "xValueType is {} in spreadCurve, but {} in CombinedCurve", spreadMetadata.getXValueType(), metadata.getXValueType()));
private static void validate(Curve curve, String name, ValueType yType) { ArgChecker.notNull(curve, name); curve.getMetadata().getXValueType().checkEquals( ValueType.YEAR_FRACTION, "Incorrect x-value type for SABR volatilities"); ValueType yValueType = curve.getMetadata().getYValueType(); yValueType.checkEquals(yType, "Incorrect y-value type for SABR volatilities"); }
if (metadata.getXValueType().equals(ValueType.YEAR_FRACTION) && metadata.getYValueType().equals(ValueType.ZERO_RATE)) { if (curve instanceof ConstantNodalCurve) { ConstantNodalCurve constantCurve = (ConstantNodalCurve) curve;
@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 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(); }
@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; }
/** * Creates an instance from the underlying curve. * * @param currency the currency * @param valuationDate the valuation date * @param curve the underlying curve * @return the instance */ public static IsdaCreditDiscountFactors of(Currency currency, LocalDate valuationDate, NodalCurve curve) { curve.getMetadata().getXValueType().checkEquals(YEAR_FRACTION, "Incorrect x-value type for zero-rate discount curve"); curve.getMetadata().getYValueType().checkEquals(ZERO_RATE, "Incorrect y-value type for zero-rate discount curve"); if (curve instanceof InterpolatedNodalCurve) { InterpolatedNodalCurve interpolatedCurve = (InterpolatedNodalCurve) curve; ArgChecker.isTrue(interpolatedCurve.getInterpolator().equals(CurveInterpolators.PRODUCT_LINEAR), "Interpolator must be PRODUCT_LINEAR"); ArgChecker.isTrue(interpolatedCurve.getExtrapolatorLeft().equals(CurveExtrapolators.FLAT), "Left extrapolator must be FLAT"); ArgChecker.isTrue(interpolatedCurve.getExtrapolatorRight().equals(CurveExtrapolators.PRODUCT_LINEAR), "Right extrapolator must be PRODUCT_LINEAR"); } else { ArgChecker.isTrue(curve instanceof ConstantNodalCurve, "the underlying curve must be InterpolatedNodalCurve or ConstantNodalCurve"); } return new IsdaCreditDiscountFactors(currency, valuationDate, curve); }
/** * 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; }
@ImmutableConstructor private SimplePriceIndexValues( PriceIndex index, LocalDate valuationDate, NodalCurve curve, LocalDateDoubleTimeSeries fixings) { ArgChecker.isFalse(fixings.isEmpty(), "Fixings must not be empty"); curve.getMetadata().getXValueType().checkEquals(ValueType.MONTHS, "Incorrect x-value type for price curve"); curve.getMetadata().getYValueType().checkEquals(ValueType.PRICE_INDEX, "Incorrect y-value type for price curve"); this.index = ArgChecker.notNull(index, "index"); this.valuationDate = ArgChecker.notNull(valuationDate, "valuationDate"); this.fixings = ArgChecker.notNull(fixings, "fixings"); this.curve = ArgChecker.notNull(curve, "curve"); }