/** Tests creating index shifts from a Groovy script. */ @Test public void index() { Scenario scenario = SimulationUtils.createScenarioFromDsl("src/test/groovy/SurfaceTest3.groovy", null); ScenarioDefinition definition = scenario.createDefinition(); assertEquals("surface index shifts", definition.getName()); Map<DistinctMarketDataSelector, FunctionParameters> map = definition.getDefinitionMap(); FunctionParameters params = map.get(new VolatilitySurfaceSelector(null, null, null, null, null, null, null)); assertNotNull(params); Object value = ((SimpleFunctionParameters) params) .getValue(StructureManipulationFunction.EXPECTED_PARAMETER_NAME); CompositeStructureManipulator manipulator = (CompositeStructureManipulator) value; List manipulators = manipulator.getManipulators(); assertEquals(1, manipulators.size()); List<Double> shifts = Lists.newArrayList(0d, 1e-4, 2e-4); VolatilitySurfaceIndexShifts expected = new VolatilitySurfaceIndexShifts(ScenarioShiftType.ABSOLUTE, shifts); assertEquals(expected, manipulators.get(0)); }
@Test public void absolute() { Scenario scenario = SimulationUtils.createScenarioFromDsl("src/test/groovy/SurfaceTest2.groovy", null); ScenarioDefinition definition = scenario.createDefinition(); assertEquals("absolute surface test", definition.getName()); Map<DistinctMarketDataSelector, FunctionParameters> map = definition.getDefinitionMap(); FunctionParameters params = map.get(new VolatilitySurfaceSelector(null, null, null, null, null, null, null)); assertNotNull(params); Object value = ((SimpleFunctionParameters) params) .getValue(StructureManipulationFunction.EXPECTED_PARAMETER_NAME); CompositeStructureManipulator manipulator = (CompositeStructureManipulator) value; List manipulators = manipulator.getManipulators(); assertEquals(1, manipulators.size()); List<VolatilitySurfaceShift> shifts = ImmutableList.of( new VolatilitySurfaceShift(0.5, 0.6, 0.1), new VolatilitySurfaceShift(1.5, 0.7, 0.2)); VolatilitySurfaceShiftManipulator expected = VolatilitySurfaceShiftManipulator.create(ScenarioShiftType.ABSOLUTE, shifts); assertEquals(expected, manipulators.get(0)); }