private static List<String> curveSettings(Curve curve) { ArgChecker.isTrue(curve instanceof InterpolatedNodalCurve, "Curve must be an InterpolatedNodalCurve"); if (!VALUE_TYPE_MAP.inverse().containsKey(curve.getMetadata().getYValueType())) { throw new IllegalArgumentException( Messages.format("Unsupported ValueType in curve settings: {}", curve.getMetadata().getYValueType())); } InterpolatedNodalCurve interpolatedCurve = (InterpolatedNodalCurve) curve; List<String> line = new ArrayList<>(); line.add(curve.getName().getName()); line.add(VALUE_TYPE_MAP.inverse().get(curve.getMetadata().getYValueType())); line.add(curve.getMetadata().getInfo(CurveInfoType.DAY_COUNT).toString()); line.add(interpolatedCurve.getInterpolator().toString()); line.add(interpolatedCurve.getExtrapolatorLeft().toString()); line.add(interpolatedCurve.getExtrapolatorRight().toString()); return line; }
/** * Obtains an instance from a curve. * <p> * If the curve is {@code ConstantCurve}, {@code ConstantRecoveryRates} is always instantiated. * * @param legalEntityId the legal entity identifier * @param valuationDate the valuation date for which the curve is valid * @param curve the underlying curve * @return the instance */ public static RecoveryRates of(StandardId legalEntityId, LocalDate valuationDate, Curve curve) { if (curve.getMetadata().getYValueType().equals(ValueType.RECOVERY_RATE)) { ConstantCurve constantCurve = (ConstantCurve) curve; return ConstantRecoveryRates.of(legalEntityId, valuationDate, constantCurve.getYValue()); } throw new IllegalArgumentException("Unknown curve type"); }
/** * 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())); }
metadata.getXValueType())); if (!baseMetadata.getYValueType().equals(metadata.getYValueType())) { throw new IllegalArgumentException(Messages.format( "yValueType is {} in baseCurve, but {} in CombinedCurve", baseMetadata.getYValueType(), metadata.getYValueType())); if (!spreadMetadata.getYValueType().equals(metadata.getYValueType())) { throw new IllegalArgumentException(Messages.format( "yValueType is {} in spreadCurve, but {} in CombinedCurve", spreadMetadata.getYValueType(), metadata.getYValueType()));
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"); }
@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(); }
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 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()); }
/** * Obtains an instance from a curve and time-series of fixings. * <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 index the index * @param valuationDate the valuation date for which the curve is valid * @param forwardCurve the forward curve * @param fixings the time-series of fixings * @return the rates view */ public static IborIndexRates of( IborIndex index, LocalDate valuationDate, Curve forwardCurve, LocalDateDoubleTimeSeries fixings) { if (forwardCurve.getMetadata().getYValueType().equals(ValueType.FORWARD_RATE)) { return SimpleIborIndexRates.of(index, valuationDate, forwardCurve, fixings); } DiscountFactors discountFactors = DiscountFactors.of(index.getCurrency(), valuationDate, forwardCurve); return DiscountIborIndexRates.of(index, discountFactors, fixings); }
@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"); }