final Set<ValueRequirement> desiredValues, final ComputationTargetSpecification targetSpec, final ValueProperties resultProperties) {
final ValueSpecification resultSpec = new ValueSpecification(getValueRequirementNames()[0], targetSpec, resultProperties);
final NodalDoublesSurface vegaSurface;
if (market.getVolatilitySurface() instanceof BlackVolatilitySurfaceMoneynessFcnBackedByGrid) {
// unpack the market data, including the interpolators
final BlackVolatilitySurfaceMoneynessFcnBackedByGrid surfaceBundle = (BlackVolatilitySurfaceMoneynessFcnBackedByGrid) market.getVolatilitySurface();
final VolatilitySurfaceInterpolator surfaceInterpolator = surfaceBundle.getInterpolator();
final GeneralSmileInterpolator strikeInterpolator = surfaceInterpolator.getSmileInterpolator();
final SmileSurfaceDataBundle volGrid = surfaceBundle.getGridData();
final double[] forwards = volGrid.getForwards();
final double[] expiries = volGrid.getExpiries();
final int nExpiries = volGrid.getNumExpiries();
final double optionExpiry = vanillaOptions.iterator().next().getTimeToExpiry();
final double[][] strikes = volGrid.getStrikes();
final double[][] vols = volGrid.getVolatilities();
// Prices of vanillas in base scenario
final int nVanillas = vanillaOptions.size();
final EquityIndexOption[] vanillas = vanillaOptions.toArray(new EquityIndexOption[nVanillas]);
final Double[] basePrices = new Double[nVanillas];
for (int v = 0; v < nVanillas; v++) {
basePrices[v] = PVC.visitEquityIndexOption(vanillas[v], market);
}
// Smile fits across strikes in base scenario, one per expiry
final Function1D<Double, Double>[] smileFitsBase = surfaceInterpolator.getIndependentSmileFits(volGrid);
// Bump market at each expiry and strike scenario
// In each scenario, reprice each of the underlying vanillaOptions
// NOTE: Only computing down-shift as this appears to produce more stable risk, and is faster
final List<Triple<Double, Double, Double>> triplesExpiryStrikeVega = new ArrayList<>();
final int expiryIndex = SurfaceArrayUtils.getLowerBoundIndex(expiries, optionExpiry);
for (int t = Math.max(0, expiryIndex - 3); t < Math.min(nExpiries, expiryIndex + 4); t++) {
final int nStrikes = strikes[t].length;
int idxLow = SurfaceArrayUtils.getLowerBoundIndex(strikes[t], vanillas[0].getStrike());
int idxHigh = idxLow;
for (int v = 1; v < nVanillas; v++) {
final int idxV = SurfaceArrayUtils.getLowerBoundIndex(strikes[t], vanillas[v].getStrike());
idxLow = Math.min(idxLow, idxV);
idxHigh = Math.max(idxHigh, idxV);
}
for (int k = Math.max(0, idxLow - 6); k < Math.min(nStrikes, idxHigh + 16); k++) {
// Scenario (t,k)
// TODO: REVIEW Each scenario only requires a single new smile fit in k. We only recompute the smile function for the expiry we are bumping..
final double[] bumpedVols = Arrays.copyOf(vols[t], nStrikes);
bumpedVols[k] = vols[t][k] - SHIFT;
final Function1D<Double, Double> thisExpirysSmile = strikeInterpolator.getVolatilityFunction(forwards[t], strikes[t], expiries[t], bumpedVols);
final Function1D<Double, Double>[] scenarioSmileFits = Arrays.copyOf(smileFitsBase, smileFitsBase.length);
scenarioSmileFits[t] = thisExpirysSmile;
final BlackVolatilitySurfaceMoneynessFcnBackedByGrid shiftedSurface = surfaceInterpolator.combineIndependentSmileFits(scenarioSmileFits, volGrid);
final StaticReplicationDataBundle shiftedMarket = market.withShiftedSurface(shiftedSurface);
// Sensitivities
for (int v = 0; v < nVanillas; v++) {
final Double shiftedPV = vanillas[v].accept(PVC, shiftedMarket);
Validate.notNull(shiftedPV, "Null PV in shifted scenario, T = " + expiries[t] + ", k = " + strikes[t][k]);