public void test_of_String() { ConstantSurface test = ConstantSurface.of(NAME, VALUE); assertThat(test.getName()).isEqualTo(SURFACE_NAME); assertThat(test.getZValue()).isEqualTo(VALUE); assertThat(test.getParameterCount()).isEqualTo(1); assertThat(test.getParameter(0)).isEqualTo(VALUE); assertThat(test.getParameterMetadata(0)).isEqualTo(ParameterMetadata.empty()); assertThat(test.withParameter(0, 2d)).isEqualTo(ConstantSurface.of(NAME, 2d)); assertThat(test.withPerturbation((i, v, m) -> v + 1d)).isEqualTo(ConstantSurface.of(NAME, VALUE + 1d)); assertThat(test.getMetadata()).isEqualTo(METADATA); assertThat(test.withMetadata(METADATA2)).isEqualTo(ConstantSurface.of(METADATA2, VALUE)); }
@Override public ConstantSurface withPerturbation(ParameterPerturbation perturbation) { return new ConstantSurface(metadata, perturbation.perturbParameter(0, zValue, getParameterMetadata(0))); }
@Override public UnitParameterSensitivity zValueParameterSensitivity(double x, double y) { return createParameterSensitivity(SENSITIVITY); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -450004177: // metadata return ((ConstantSurface) bean).getMetadata(); case -719790825: // zValue return ((ConstantSurface) bean).getZValue(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Creates a constant surface with a specific value. * * @param name the surface name * @param zValue the constant z-value * @return the surface */ public static ConstantSurface of(String name, double zValue) { return of(SurfaceName.of(name), zValue); }
@Test(enabled = true) public void log_normal_atm() { double beta = 0.50; Surface betaSurface = ConstantSurface.of("Beta", beta) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION) .zValueType(ValueType.SABR_BETA).surfaceName("Beta").build()); double shift = 0.0000; Surface shiftSurface = ConstantSurface.of("Shift", shift) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).surfaceName("Shift").build()); SabrParametersSwaptionVolatilities calibratedSmile = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(
public void test_lookup() { ConstantSurface test = ConstantSurface.of(SURFACE_NAME, VALUE); assertThat(test.zValue(0d, 0d)).isEqualTo(VALUE); assertThat(test.zValue(-10d, 10d)).isEqualTo(VALUE); assertThat(test.zValue(100d, -100d)).isEqualTo(VALUE); assertThat(test.zValueParameterSensitivity(0d, 0d).getSensitivity().get(0)).isEqualTo(1d); assertThat(test.zValueParameterSensitivity(-10d, 10d).getSensitivity().get(0)).isEqualTo(1d); assertThat(test.zValueParameterSensitivity(100d, -100d).getSensitivity().get(0)).isEqualTo(1d); }
@Override public ConstantSurface build() { return new ConstantSurface( metadata, zValue); }
public void normal_atm() { double beta = 0.50; Surface betaSurface = ConstantSurface.of("Beta", beta) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION) .zValueType(ValueType.SABR_BETA).surfaceName("Beta").build()); double shift = 0.0300; Surface shiftSurface = ConstantSurface.of("Shift", shift) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).surfaceName("Shift").build()); SabrParametersSwaptionVolatilities calibratedSmile = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(
public void test_lookup_byPair() { ConstantSurface test = ConstantSurface.of(SURFACE_NAME, VALUE); assertThat(test.zValue(DoublesPair.of(0d, 0d))).isEqualTo(VALUE); assertThat(test.zValue(DoublesPair.of(-10d, 10d))).isEqualTo(VALUE); assertThat(test.zValue(DoublesPair.of(100d, -100d))).isEqualTo(VALUE); assertThat(test.zValueParameterSensitivity(DoublesPair.of(0d, 0d)).getSensitivity().get(0)).isEqualTo(1d); assertThat(test.zValueParameterSensitivity(DoublesPair.of(-10d, 10d)).getSensitivity().get(0)).isEqualTo(1d); assertThat(test.zValueParameterSensitivity(DoublesPair.of(100d, -100d)).getSensitivity().get(0)).isEqualTo(1d); }
/** * Creates a constant surface with a specific value. * * @param metadata the surface metadata * @param zValue the constant z-value * @return the surface */ public static ConstantSurface of(SurfaceMetadata metadata, double zValue) { return new ConstantSurface(metadata, zValue); }
public void test_of_SurfaceName() { ConstantSurface test = ConstantSurface.of(SURFACE_NAME, VALUE); assertThat(test.getName()).isEqualTo(SURFACE_NAME); assertThat(test.getZValue()).isEqualTo(VALUE); assertThat(test.getParameterCount()).isEqualTo(1); assertThat(test.getParameter(0)).isEqualTo(VALUE); assertThat(test.getParameterMetadata(0)).isEqualTo(ParameterMetadata.empty()); assertThat(test.withParameter(0, 2d)).isEqualTo(ConstantSurface.of(NAME, 2d)); assertThat(test.withPerturbation((i, v, m) -> v + 1d)).isEqualTo(ConstantSurface.of(NAME, VALUE + 1d)); assertThat(test.getMetadata()).isEqualTo(METADATA); assertThat(test.withMetadata(METADATA2)).isEqualTo(ConstantSurface.of(METADATA2, VALUE)); }
public void test_serialization() { ConstantSurface test = ConstantSurface.of(SURFACE_NAME, VALUE); assertSerialization(test); }
@Test public void log_normal_cube() { double beta = 0.50; Surface betaSurface = ConstantSurface.of("Beta", beta) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION) .zValueType(ValueType.SABR_BETA).surfaceName("Beta").build()); double shift = 0.0300; Surface shiftSurface = ConstantSurface.of("Shift", shift) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).surfaceName("Shift").build()); SabrParametersSwaptionVolatilities calibrated = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(
private Object readResolve() { return new ConstantSurface(metadata, zValue); }
public void test_of_SurfaceMetadata() { ConstantSurface test = ConstantSurface.of(METADATA, VALUE); assertThat(test.getName()).isEqualTo(SURFACE_NAME); assertThat(test.getZValue()).isEqualTo(VALUE); assertThat(test.getParameterCount()).isEqualTo(1); assertThat(test.getParameter(0)).isEqualTo(VALUE); assertThat(test.getParameterMetadata(0)).isEqualTo(ParameterMetadata.empty()); assertThat(test.withParameter(0, 2d)).isEqualTo(ConstantSurface.of(NAME, 2d)); assertThat(test.withPerturbation((i, v, m) -> v + 1d)).isEqualTo(ConstantSurface.of(NAME, VALUE + 1d)); assertThat(test.getMetadata()).isEqualTo(METADATA); assertThat(test.withMetadata(METADATA2)).isEqualTo(ConstantSurface.of(METADATA2, VALUE)); }
strikeList.add(strikes.get(i)); volList.add(volatilityData.get(i)); ConstantSurface constVolSurface = ConstantSurface.of(metadata, volatilityData.get(i)); IborCapletFloorletVolatilities vols = volatilityFunction.apply(constVolSurface); timeList.add(vols.relativeTime(capFloor.getFinalFixingDateTime()));
@Test public void normal_cube() { double beta = 0.50; Surface betaSurface = ConstantSurface.of("Beta", beta) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION) .zValueType(ValueType.SABR_BETA).surfaceName("Beta").build()); double shift = 0.0300; Surface shiftSurface = ConstantSurface.of("Shift", shift) .withMetadata(DefaultSurfaceMetadata.builder() .xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).surfaceName("Shift").build()); SabrParametersSwaptionVolatilities calibrated = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(
@Override public ConstantSurface withParameter(int parameterIndex, double newValue) { Preconditions.checkElementIndex(parameterIndex, 1); return new ConstantSurface(metadata, newValue); }