/** * Sets the day count. * <p> * This stores the day count in the additional information map using the * key {@link SurfaceInfoType#DAY_COUNT}. * <p> * This is stored in the additional information map using {@code Map.put} semantics, * removing the key if the day count is null. * * @param dayCount the day count, may be null * @return this, for chaining */ public DefaultSurfaceMetadataBuilder dayCount(DayCount dayCount) { return addInfo(SurfaceInfoType.DAY_COUNT, dayCount); }
@Override public <T> DefaultSurfaceMetadata withInfo(SurfaceInfoType<T> type, T value) { return toBuilder().addInfo(type, value).build(); }
public void test_builder1() { DefaultSurfaceMetadata test = DefaultSurfaceMetadata.builder() .surfaceName(SURFACE_NAME.toString()) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.DISCOUNT_FACTOR) .zValueType(ValueType.ZERO_RATE) .dayCount(ACT_365F) .addInfo(DESCRIPTION, "Hello") .parameterMetadata(ImmutableList.of(ParameterMetadata.empty())) .build(); assertThat(test.getSurfaceName()).isEqualTo(SURFACE_NAME); assertThat(test.getXValueType()).isEqualTo(ValueType.YEAR_FRACTION); assertThat(test.getYValueType()).isEqualTo(ValueType.DISCOUNT_FACTOR); assertThat(test.getZValueType()).isEqualTo(ValueType.ZERO_RATE); assertThat(test.getInfo(SurfaceInfoType.DAY_COUNT)).isEqualTo(ACT_365F); assertThat(test.findInfo(SurfaceInfoType.DAY_COUNT)).isEqualTo(Optional.of(ACT_365F)); assertThat(test.getInfo(DESCRIPTION)).isEqualTo("Hello"); assertThat(test.findInfo(DESCRIPTION)).isEqualTo(Optional.of("Hello")); assertThat(test.findInfo(SurfaceInfoType.of("Rubbish"))).isEqualTo(Optional.empty()); assertThat(test.getParameterMetadata().isPresent()).isTrue(); assertThat(test.getParameterMetadata().get()).containsExactly(ParameterMetadata.empty()); }
public void test_builder2() { DefaultSurfaceMetadata test = DefaultSurfaceMetadata.builder() .surfaceName(SURFACE_NAME) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.DISCOUNT_FACTOR) .zValueType(ValueType.ZERO_RATE) .dayCount(ACT_365F) .addInfo(SurfaceInfoType.DAY_COUNT, null) .addInfo(DESCRIPTION, "Hello") .parameterMetadata(ImmutableList.of(ParameterMetadata.empty())) .build(); assertThat(test.getSurfaceName()).isEqualTo(SURFACE_NAME); assertThat(test.getXValueType()).isEqualTo(ValueType.YEAR_FRACTION); assertThat(test.getYValueType()).isEqualTo(ValueType.DISCOUNT_FACTOR); assertThat(test.getZValueType()).isEqualTo(ValueType.ZERO_RATE); assertThrowsIllegalArg(() -> test.getInfo(SurfaceInfoType.DAY_COUNT)); assertThat(test.findInfo(SurfaceInfoType.DAY_COUNT)).isEmpty(); assertThat(test.getInfo(DESCRIPTION)).isEqualTo("Hello"); assertThat(test.findInfo(DESCRIPTION)).isEqualTo(Optional.of("Hello")); assertThat(test.findInfo(SurfaceInfoType.of("Rubbish"))).isEqualTo(Optional.empty()); assertThat(test.getParameterMetadata().isPresent()).isTrue(); assertThat(test.getParameterMetadata().get()).containsExactly(ParameterMetadata.empty()); }
/** * Creates metadata for a surface providing Normal expiry-simple moneyness volatility. * <p> * The x-values represent time to expiry year fractions as defined by the specified day count. * The y-values represent simple moneyness. * The z-values represent Normal volatility. * * @param name the surface name * @param dayCount the day count * @param moneynessType the moneyness type, prices or rates * @return the surface metadata */ public static SurfaceMetadata normalVolatilityByExpirySimpleMoneyness( SurfaceName name, DayCount dayCount, MoneynessType moneynessType) { return DefaultSurfaceMetadata.builder() .surfaceName(name) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.SIMPLE_MONEYNESS) .zValueType(ValueType.NORMAL_VOLATILITY) .dayCount(dayCount) .addInfo(SurfaceInfoType.MONEYNESS_TYPE, moneynessType) .build(); }
public void normalVolatilityByExpirySimpleMoneyness_string() { SurfaceMetadata test = Surfaces.normalVolatilityByExpirySimpleMoneyness(NAME, ACT_360, MoneynessType.PRICE); SurfaceMetadata expected = DefaultSurfaceMetadata.builder() .surfaceName(SURFACE_NAME) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.SIMPLE_MONEYNESS) .zValueType(ValueType.NORMAL_VOLATILITY) .dayCount(ACT_360) .addInfo(SurfaceInfoType.MONEYNESS_TYPE, MoneynessType.PRICE) .build(); assertEquals(test, expected); }
public void normalVolatilityByExpirySimpleMoneyness_surfaceName() { SurfaceMetadata test = Surfaces.normalVolatilityByExpirySimpleMoneyness(SURFACE_NAME, ACT_360, MoneynessType.PRICE); SurfaceMetadata expected = DefaultSurfaceMetadata.builder() .surfaceName(SURFACE_NAME) .xValueType(ValueType.YEAR_FRACTION) .yValueType(ValueType.SIMPLE_MONEYNESS) .zValueType(ValueType.NORMAL_VOLATILITY) .dayCount(ACT_360) .addInfo(SurfaceInfoType.MONEYNESS_TYPE, MoneynessType.PRICE) .build(); assertEquals(test, expected); }