@Override public CurveMetadata getMetadata() { return underlyingCurve.getMetadata(); }
@Override public CurveMetadata getMetadata() { return spreadCurve.getMetadata(); }
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"); } }
@Override public default ParameterMetadata getParameterMetadata(int parameterIndex) { return getMetadata().getParameterMetadata(parameterIndex); }
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 the curve name. * * @return the curve name */ public default CurveName getName() { return getMetadata().getCurveName(); }
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; }
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 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; }
/** * 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())); }
private SabrParametersIborCapletFloorletVolatilities updateParameters( SabrIborCapletFloorletVolatilityCalibrationDefinition sabrDefinition, SabrParametersIborCapletFloorletVolatilities volatilities, DoubleArray newValues) { SabrParameters sabrParams = volatilities.getParameters(); CurveMetadata alphaMetadata = sabrParams.getAlphaCurve().getMetadata(); CurveMetadata betaMetadata = sabrParams.getBetaCurve().getMetadata(); CurveMetadata rhoMetadata = sabrParams.getRhoCurve().getMetadata(); CurveMetadata nuMetadata = sabrParams.getNuCurve().getMetadata(); List<Curve> newCurveList = sabrDefinition.createSabrParameterCurve( ImmutableList.of(alphaMetadata, betaMetadata, rhoMetadata, nuMetadata), newValues); SabrParameters newSabrParams = SabrParameters.of( newCurveList.get(0), newCurveList.get(1), newCurveList.get(2), newCurveList.get(3), sabrDefinition.getShiftCurve(), sabrDefinition.getSabrVolatilityFormula()); SabrParametersIborCapletFloorletVolatilities newVols = SabrParametersIborCapletFloorletVolatilities.of( volatilities.getName(), volatilities.getIndex(), volatilities.getValuationDateTime(), newSabrParams); return newVols; }
/** * 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"); }
@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; }
/** * 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()); }
CurveMetadata metadata = curve.getMetadata(); if (metadata.getXValueType().equals(ValueType.YEAR_FRACTION) && metadata.getYValueType().equals(ValueType.ZERO_RATE)) { if (curve instanceof ConstantNodalCurve) {
public void test_of() { Curve test = ParallelShiftedCurve.of(CONSTANT_CURVE, ShiftType.RELATIVE, 0.1d); assertThat(test.yValue(0)).isEqualTo(3.3d, offset(1e-10)); assertThat(test.yValue(1)).isEqualTo(3.3d, offset(1e-10)); assertThat(test.getName()).isEqualTo(METADATA.getCurveName()); assertThat(test.getParameterCount()).isEqualTo(2); assertThat(test.getParameter(0)).isEqualTo(3d); assertThat(test.getParameter(1)).isEqualTo(0.1d); assertThat(test.getParameterMetadata(0)).isEqualTo(ParameterMetadata.empty()); assertThat(test.getParameterMetadata(1)).isEqualTo(LabelParameterMetadata.of("RelativeShift")); assertThat(test.getMetadata()).isEqualTo(METADATA); }
/** * 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); }