//------------------------------------------------------------------------- public SurfaceMetadata createMetadata(RawOptionData capFloorData) { IList <GenericVolatilitySurfacePeriodParameterMetadata> list = new List <GenericVolatilitySurfacePeriodParameterMetadata>(); ImmutableList <Period> expiries = capFloorData.Expiries; int nExpiries = expiries.size(); DoubleArray strikes = capFloorData.Strikes; int nStrikes = strikes.size(); for (int i = 0; i < nExpiries; ++i) { for (int j = 0; j < nStrikes; ++j) { if (Double.isFinite(capFloorData.Data.get(i, j))) { list.Add(GenericVolatilitySurfacePeriodParameterMetadata.of(expiries.get(i), SimpleStrike.of(strikes.get(j)))); } } } SurfaceMetadata metadata; if (capFloorData.DataType.Equals(ValueType.BLACK_VOLATILITY)) { metadata = Surfaces.blackVolatilityByExpiryStrike(name.Name, dayCount); } else if (capFloorData.DataType.Equals(ValueType.NORMAL_VOLATILITY)) { metadata = Surfaces.normalVolatilityByExpiryStrike(name.Name, dayCount); } else { throw new System.ArgumentException("Data type not supported"); } return(metadata.withParameterMetadata(list)); }
public virtual void test_createMetadata_normal() { SurfaceIborCapletFloorletVolatilityBootstrapDefinition @base = SurfaceIborCapletFloorletVolatilityBootstrapDefinition.of(NAME, USD_LIBOR_3M, ACT_ACT_ISDA, LINEAR, DOUBLE_QUADRATIC); RawOptionData capData = RawOptionData.of(ImmutableList.of(Period.ofYears(1), Period.ofYears(5)), DoubleArray.of(0.005, 0.01, 0.015), ValueType.STRIKE, DoubleMatrix.copyOf(new double[][] { new double[] { 0.15, 0.12, 0.13 }, new double[] { 0.1, Double.NaN, 0.09 } }), ValueType.NORMAL_VOLATILITY); IList <GenericVolatilitySurfacePeriodParameterMetadata> list = new List <GenericVolatilitySurfacePeriodParameterMetadata>(); list.Add(GenericVolatilitySurfacePeriodParameterMetadata.of(Period.ofYears(1), SimpleStrike.of(0.005))); list.Add(GenericVolatilitySurfacePeriodParameterMetadata.of(Period.ofYears(1), SimpleStrike.of(0.01))); list.Add(GenericVolatilitySurfacePeriodParameterMetadata.of(Period.ofYears(1), SimpleStrike.of(0.015))); list.Add(GenericVolatilitySurfacePeriodParameterMetadata.of(Period.ofYears(5), SimpleStrike.of(0.005))); list.Add(GenericVolatilitySurfacePeriodParameterMetadata.of(Period.ofYears(5), SimpleStrike.of(0.015))); SurfaceMetadata expected = Surfaces.normalVolatilityByExpiryStrike(NAME.Name, ACT_ACT_ISDA).withParameterMetadata(list); SurfaceMetadata computed = @base.createMetadata(capData); assertEquals(computed, expected); }