コード例 #1
0
 /** Tests applying a relative index shift to SmileSurfaceDataBundle. */
 @Test
 public void indexShiftRelativeSurfaceData() {
   StandardSmileSurfaceDataBundle surfaceData =
       new StandardSmileSurfaceDataBundle(
           0d,
           new double[] {0, 0, 0}, // not relevant to this test
           new double[] {1.1, 1.2, 1.3},
           new double[][] {{10}, {10, 20}, {10, 20, 30}},
           new double[][] {{1}, {2, 3}, {4, 5, 6}},
           new LinearInterpolator1D()); // not relevant to this test
   List<Double> shiftList = Lists.newArrayList(0d, 0.1, 0.2);
   VolatilitySurfaceIndexShifts shifts =
       new VolatilitySurfaceIndexShifts(ScenarioShiftType.RELATIVE, shiftList);
   SmileSurfaceDataBundle shiftedData = shifts.shiftSurfaceData(surfaceData);
   double[][] expectedVols = new double[][] {{1}, {2.2, 3.3}, {4.8, 6.0, 7.2}};
   double[][] shiftedVols = shiftedData.getVolatilities();
   assertTrue(Arrays.deepEquals(expectedVols, shiftedVols));
 }
コード例 #2
0
 /**
  * Tests applying an index shift to a surface where there are fewer shifts specified than expiries
  * in the surface.
  */
 @Test
 public void indexSurfaceFewerShiftsThanExpiries() {
   NodalDoublesSurface surface =
       new NodalDoublesSurface(
           new double[] {1.1, 1.2, 1.2, 1.3, 1.3, 1.3},
           new double[] {0.1, 0.1, 0.2, 0.1, 0.2, 0.3},
           new double[] {1, 2, 3, 4, 5, 6});
   List<Double> shiftList = Lists.newArrayList(0d, 0.1);
   VolatilitySurfaceIndexShifts shifts =
       new VolatilitySurfaceIndexShifts(ScenarioShiftType.ABSOLUTE, shiftList);
   ValueProperties properties = ValueProperties.with(ValuePropertyNames.FUNCTION, "bar").get();
   ValueSpecification spec =
       new ValueSpecification("foo", ComputationTargetSpecification.NULL, properties);
   VolatilitySurface shiftedSurface =
       shifts.execute(new VolatilitySurface(surface), spec, new FunctionExecutionContext());
   assertEquals(1.0, shiftedSurface.getVolatility(1.1, 0.1), DELTA);
   assertEquals(2.1, shiftedSurface.getVolatility(1.2, 0.1), DELTA);
   assertEquals(3.1, shiftedSurface.getVolatility(1.2, 0.2), DELTA);
   assertEquals(4.0, shiftedSurface.getVolatility(1.3, 0.1), DELTA);
   assertEquals(5.0, shiftedSurface.getVolatility(1.3, 0.2), DELTA);
   assertEquals(6.0, shiftedSurface.getVolatility(1.3, 0.3), DELTA);
 }
コード例 #3
0
 /** Tests applying a relative index shift to a surface. */
 @Test
 public void indexSurfaceRelative() {
   NodalDoublesSurface surface =
       new NodalDoublesSurface(
           new double[] {1.1, 1.2, 1.2, 1.3, 1.3, 1.3},
           new double[] {10, 10, 20, 10, 20, 30},
           new double[] {1, 2, 3, 4, 5, 6});
   List<Double> shiftList = Lists.newArrayList(0d, 0.1, 0.2);
   VolatilitySurfaceIndexShifts shifts =
       new VolatilitySurfaceIndexShifts(ScenarioShiftType.RELATIVE, shiftList);
   ValueProperties properties = ValueProperties.with(ValuePropertyNames.FUNCTION, "bar").get();
   ValueSpecification spec =
       new ValueSpecification("foo", ComputationTargetSpecification.NULL, properties);
   VolatilitySurface shiftedSurface =
       shifts.execute(new VolatilitySurface(surface), spec, new FunctionExecutionContext());
   assertEquals(1.0, shiftedSurface.getVolatility(1.1, 10), DELTA);
   assertEquals(2.2, shiftedSurface.getVolatility(1.2, 10), DELTA);
   assertEquals(3.3, shiftedSurface.getVolatility(1.2, 20), DELTA);
   assertEquals(4.8, shiftedSurface.getVolatility(1.3, 10), DELTA);
   assertEquals(6.0, shiftedSurface.getVolatility(1.3, 20), DELTA);
   assertEquals(7.2, shiftedSurface.getVolatility(1.3, 30), DELTA);
 }