final ValueRequirement desiredValue = desiredValues.iterator().next();
final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
final String curveCalculationConfig = desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
// 1. Build the analytic derivative to be priced
final EquityVarianceSwapSecurity security = (EquityVarianceSwapSecurity) target.getSecurity();
final Clock snapshotClock = executionContext.getValuationClock();
final ZonedDateTime now = ZonedDateTime.now(snapshotClock).minusYears(2); //TODO remove me - just for testing
final VarianceSwapDefinition defn = security.accept(_converter);
final HistoricalTimeSeries timeSeries = (HistoricalTimeSeries) inputs.getValue(ValueRequirementNames.HISTORICAL_TIME_SERIES);
final VarianceSwap deriv = defn.toDerivative(now, timeSeries.getTimeSeries());
// 2. Build up the market data bundle
final Object volSurfaceObject = inputs.getValue(getVolatilitySurfaceRequirement(security, surfaceName));
if (volSurfaceObject == null) {
throw new OpenGammaRuntimeException("Could not get Volatility Surface");
}
final VolatilitySurface volSurface = (VolatilitySurface) volSurfaceObject;
//TODO no choice of other surfaces
final BlackVolatilitySurface<?> blackVolSurf = new BlackVolatilitySurfaceStrike(volSurface.getSurface());
final Object discountObject = inputs.getValue(getDiscountCurveRequirement(security, curveName, curveCalculationConfig));
if (discountObject == null) {
throw new OpenGammaRuntimeException("Could not get Discount Curve");
}
if (!(discountObject instanceof YieldCurve)) { //TODO: make it more generic
throw new IllegalArgumentException("Can only handle YieldCurve");
}
final YieldCurve discountCurve = (YieldCurve) discountObject;
final Object spotObject = inputs.getValue(getSpotRequirement(security));
if (spotObject == null) {
throw new OpenGammaRuntimeException("Could not get Underlying's Spot value");
}
final double spot = (Double) spotObject;
final double expiry = TimeCalculator.getTimeBetween(ZonedDateTime.now(executionContext.getValuationClock()), security.getLastObservationDate());
final double discountFactor = discountCurve.getDiscountFactor(expiry);
ArgumentChecker.isTrue(Double.doubleToLongBits(discountFactor) != 0, "The discount curve has returned a zero value for a discount bond. Check rates.");
final ForwardCurve forwardCurve = new ForwardCurve(spot, discountCurve.getCurve()); //TODO change this
final StaticReplicationDataBundle market = new StaticReplicationDataBundle(blackVolSurf, discountCurve, forwardCurve);