requirements.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, parameters.getFirstInitialVolatilityId()));
requirements.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, parameters.getSecondInitialVolatilityId()));
requirements.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, parameters.getCorrelationId()));
final Map<Tenor, Pair<ExternalId, ExternalId>> volatilityTermStructure = parameters.getVolatilityTermStructure();
for (final Map.Entry<Tenor, Pair<ExternalId, ExternalId>> entry : volatilityTermStructure.entrySet()) {
final ExternalScheme firstScheme = entry.getValue().getFirst().getScheme();
final ExternalScheme secondScheme = entry.getValue().getSecond().getScheme();
final String firstId = entry.getValue().getFirst().getValue();
final String secondId = entry.getValue().getSecond().getValue();
final ExternalId firstTenorAppendedId = ExternalId.of(firstScheme, createId(entry.getKey(), firstId));
final ExternalId secondTenorAppendedId = ExternalId.of(secondScheme, createId(entry.getKey(), secondId));
requirements.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, firstTenorAppendedId));
requirements.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, secondTenorAppendedId));
}
final ZonedDateTime atZDT = ZonedDateTime.ofInstant(atInstant, ZoneOffset.UTC);
return new AbstractInvokingCompiledFunction(atZDT.with(LocalTime.MIDNIGHT), atZDT.plusDays(1).with(LocalTime.MIDNIGHT).minusNanos(1000000)) {
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
final Clock snapshotClock = executionContext.getValuationClock();
final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
final Object firstMeanReversionObject = inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE,
ComputationTargetType.PRIMITIVE, parameters.getFirstMeanReversionId()));
if (firstMeanReversionObject == null) {
throw new OpenGammaRuntimeException("Could not get first mean reversion value");
}
final Object secondMeanReversionObject = inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE,
ComputationTargetType.PRIMITIVE, parameters.getSecondMeanReversionId()));
if (secondMeanReversionObject == null) {
throw new OpenGammaRuntimeException("Could not get second mean reversion value");
}
final Object firstInitialVolatilityObject = inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE,
ComputationTargetType.PRIMITIVE, parameters.getFirstInitialVolatilityId()));
if (firstInitialVolatilityObject == null) {
throw new OpenGammaRuntimeException("Could not get first initial volatility value");
}
final Object secondInitialVolatilityObject = inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE,
ComputationTargetType.PRIMITIVE, parameters.getSecondInitialVolatilityId()));
if (secondInitialVolatilityObject == null) {
throw new OpenGammaRuntimeException("Could not get second initial volatility value");
}
final Object correlationObject = inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE,
ComputationTargetType.PRIMITIVE, parameters.getCorrelationId()));
if (correlationObject == null) {
throw new OpenGammaRuntimeException("Could not get correlation value");
}
final Double firstMeanReversion = (Double) firstMeanReversionObject;
final Double secondMeanReversion = (Double) secondMeanReversionObject;
final Double firstInitialVolatility = (Double) firstInitialVolatilityObject;
final Double secondInitialVolatility = (Double) secondInitialVolatilityObject;
final Double correlation = (Double) correlationObject;
final DoubleArrayList firstVolatility = new DoubleArrayList();
firstVolatility.add(firstInitialVolatility);
final DoubleArrayList secondVolatility = new DoubleArrayList();
secondVolatility.add(secondInitialVolatility);
final DoubleArrayList volatilityTime = new DoubleArrayList();
for (final Map.Entry<Tenor, Pair<ExternalId, ExternalId>> entry : volatilityTermStructure.entrySet()) {
final ExternalScheme firstScheme = entry.getValue().getFirst().getScheme();
final ExternalScheme secondScheme = entry.getValue().getSecond().getScheme();
final String firstId = entry.getValue().getFirst().getValue();
final String secondId = entry.getValue().getSecond().getValue();
final ExternalId firstTenorAppendedId = ExternalId.of(firstScheme, createId(entry.getKey(), firstId));
final ExternalId secondTenorAppendedId = ExternalId.of(secondScheme, createId(entry.getKey(), secondId));
final Object firstVolatilityObject = inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE,