/** * Sets the curve name. * * @param curveName the curve name * @return this, for chaining */ public DefaultCurveMetadataBuilder curveName(String curveName) { this.curveName = CurveName.of(curveName); return this; }
/** * Checks if this info contains the specified curve. * * @param name the curve to find * @return true if the curve is matched */ public boolean containsCurve(CurveName name) { return order.stream().anyMatch(o -> o.getName().equals(name)); }
@Override public FxOptionVolatilitiesName getName() { return FxOptionVolatilitiesName.of(curve.getName().getName()); }
private static Curve queryCurve( CurveName name, Map<CurveName, Curve> curves, LocalDate date, CurveGroupName groupName, String curveType) { Curve curve = curves.get(name); if (curve == null) { throw new IllegalArgumentException( curveType + " curve values for " + name.toString() + " in group " + groupName.getName() + " are missing on " + date.toString()); } return curve; }
/** * Obtains an instance from the specified name. * <p> * Curve names may contain any character, but must not be empty. * * @param name the name of the curve * @return a curve with the specified name */ @FromString public static CurveName of(String name) { return new CurveName(name); }
private static void writeCurveGroup(CsvOutput csv, RatesCurveGroup group) { String groupName = group.getName().getName(); Map<Currency, Curve> discountingCurves = group.getDiscountCurves(); for (Entry<Currency, Curve> entry : discountingCurves.entrySet()) { List<String> line = new ArrayList<>(4); line.add(groupName); line.add(DISCOUNT); line.add(entry.getKey().toString()); line.add(entry.getValue().getName().getName()); csv.writeLine(line); } Map<Index, Curve> forwardCurves = group.getForwardCurves(); for (Entry<Index, Curve> entry : forwardCurves.entrySet()) { List<String> line = new ArrayList<>(4); line.add(groupName); line.add(FORWARD); line.add(entry.getKey().toString()); line.add(entry.getValue().getName().getName()); csv.writeLine(line); } }
@Override public ConstantDiscountFactorCurve withParameter(int parameterIndex, double newValue) { return new ConstantDiscountFactorCurve(metadata.getCurveName().toString(), newValue); }
/** * Creates a constant curve with a specific value. * * @param name the curve name * @param yValue the constant y-value * @return the curve */ public static ConstantCurve of(String name, double yValue) { return of(CurveName.of(name), yValue); }
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; }
@Override public <T> Optional<T> findData(MarketDataName<T> name) { if (curve.getName().equals(name)) { return Optional.of(name.getMarketDataType().cast(curve)); } return Optional.empty(); }
public void test_builder1() { DefaultCurveMetadata test = DefaultCurveMetadata.builder() .curveName(CURVE_NAME.toString()) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.DISCOUNT_FACTOR) .dayCount(ACT_360) .jacobian(JACOBIAN_DATA) .addInfo(CurveInfoType.DAY_COUNT, null) .parameterMetadata(ImmutableList.of(ParameterMetadata.empty())) .build(); assertThat(test.getCurveName()).isEqualTo(CURVE_NAME); assertThat(test.getXValueType()).isEqualTo(ValueType.YEAR_FRACTION); assertThat(test.getYValueType()).isEqualTo(ValueType.DISCOUNT_FACTOR); assertThat(test.findInfo(CurveInfoType.DAY_COUNT)).isEmpty(); assertThat(test.getInfo(CurveInfoType.JACOBIAN)).isEqualTo(JACOBIAN_DATA); assertThat(test.findInfo(CurveInfoType.JACOBIAN)).isEqualTo(Optional.of(JACOBIAN_DATA)); assertThat(test.findInfo(CurveInfoType.of("Rubbish"))).isEqualTo(Optional.empty()); assertThat(test.getParameterMetadata().isPresent()).isTrue(); assertThat(test.getParameterMetadata().get()).containsExactly(ParameterMetadata.empty()); }
/** * Creates the metadata. * <p> * No information will be available for the x-values, y-values or parameters. * * @param name the curve name * @return the metadata */ public static DefaultCurveMetadata of(String name) { return of(CurveName.of(name)); }
private static void writeCurveGroupDefinition(CsvOutput csv, RatesCurveGroupDefinition group) { String groupName = group.getName().getName(); for (RatesCurveGroupEntry entry : group.getEntries()) { for (Currency currency : entry.getDiscountCurrencies()) { csv.writeLine( ImmutableList.of(groupName, DISCOUNT, currency.toString(), entry.getCurveName().getName())); } for (Index index : entry.getIndices()) { csv.writeLine( ImmutableList.of(groupName, FORWARD, index.toString(), entry.getCurveName().getName())); } } }
@Override public <T> Optional<T> findData(MarketDataName<T> name) { if (curve.getName().equals(name)) { return Optional.of(name.getMarketDataType().cast(curve)); } return Optional.empty(); }
/** * Creates curve metadata for a curve providing monthly prices, typically used in inflation. * <p> * The x-values represent months relative to an unspecified base month. * * @param name the curve name * @return the curve metadata */ public static CurveMetadata prices(String name) { return prices(CurveName.of(name)); }
private static Currency parseCurrency(CsvRow row, CurveName reference) { Optional<String> currencyStr = row.findValue(CURRENCY_HEADER); if (currencyStr.isPresent()) { return LoaderUtils.parseCurrency(currencyStr.get()); } String referenceStr = reference.getName().toUpperCase(Locale.ENGLISH); try { Optional<IborIndex> ibor = IborIndex.extendedEnum().find(referenceStr); if (ibor.isPresent()) { return ibor.get().getCurrency(); } else { Optional<FloatingRateName> frName = FloatingRateName.extendedEnum().find(referenceStr); if (frName.isPresent()) { return frName.get().getCurrency(); } else if (referenceStr.length() == 3) { return Currency.of(referenceStr); } else if (referenceStr.length() > 3 && referenceStr.charAt(3) == '-' || referenceStr.charAt(3) == '_') { return LoaderUtils.parseCurrency(referenceStr.substring(0, 3)); } else { // drop out to exception } } } catch (RuntimeException ex) { // drop out to exception } throw new IllegalArgumentException("Unable to parse currency from reference, consider adding a 'Currency' column"); }
@Override public <T> Optional<T> findData(MarketDataName<T> name) { if (curve.getName().equals(name)) { return Optional.of(name.getMarketDataType().cast(curve)); } return Optional.empty(); }
/** * Creates curve metadata for a curve providing zero rates. * <p> * The x-values represent year fractions relative to an unspecified base date * as defined by the specified day count. * * @param name the curve name * @param dayCount the day count * @return the curve metadata */ public static CurveMetadata zeroRates(String name, DayCount dayCount) { return zeroRates(CurveName.of(name), dayCount); }
private static void nodeLines(String valuationDateStr, Curve curve, CsvOutput csv) { ArgChecker.isTrue(curve instanceof InterpolatedNodalCurve, "interpolated"); InterpolatedNodalCurve interpolatedCurve = (InterpolatedNodalCurve) curve; int nbPoints = interpolatedCurve.getXValues().size(); for (int i = 0; i < nbPoints; i++) { ArgChecker.isTrue( interpolatedCurve.getParameterMetadata(i) instanceof DatedParameterMetadata, "Curve metadata must contain a date, but was " + interpolatedCurve.getParameterMetadata(i).getClass().getSimpleName()); DatedParameterMetadata metadata = (DatedParameterMetadata) interpolatedCurve.getParameterMetadata(i); List<String> line = new ArrayList<>(); line.add(valuationDateStr); line.add(curve.getName().getName().toString()); line.add(metadata.getDate().toString()); line.add(BigDecimal.valueOf(interpolatedCurve.getYValues().get(i)).toPlainString()); line.add(metadata.getLabel()); csv.writeLine(line); } }