final RegionSource regionSource = OpenGammaCompilationContext.getRegionSource(context);
final ConventionBundleSource conventionBundleSource = OpenGammaCompilationContext.getConventionBundleSource(context);
final ConventionSource conventionSource = OpenGammaCompilationContext.getConventionSource(context);
final HistoricalTimeSeriesResolver timeSeriesResolver = OpenGammaCompilationContext.getHistoricalTimeSeriesResolver(context);
final InterestRateFutureOptionSecurityConverter irFutureOptionConverter = new InterestRateFutureOptionSecurityConverter(holidaySource, conventionSource, regionSource, securitySource);
final InterestRateFutureOptionTradeConverter optionTradeToTxnDefnConverter = new InterestRateFutureOptionTradeConverter(irFutureOptionConverter);
final FutureTradeConverter futureTradeConverter = new FutureTradeConverter(securitySource, holidaySource, conventionSource, conventionBundleSource, regionSource);
final FixedIncomeConverterDataProvider definitionConverter = new FixedIncomeConverterDataProvider(conventionBundleSource, timeSeriesResolver);
return new AbstractInvokingCompiledFunction() {
@Override
public final 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 ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
final Trade trade = target.getTrade();
final Security security = trade.getSecurity();
final InstrumentDefinition<?> definition;
if (security instanceof IRFutureOptionSecurity) {
definition = optionTradeToTxnDefnConverter.convert(trade);
} else {
definition = futureTradeConverter.convert(trade);
}
final HistoricalTimeSeriesBundle timeSeries = HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
final InstrumentDerivative derivative = definitionConverter.convert(security, definition, now, timeSeries);
final Double price = derivative.accept(s_priceVisitor);
final ValueSpecification spec = new ValueSpecification(MARGIN_PRICE, target.toSpecification(), desiredValue.getConstraints().copy().get());
return Collections.singleton(new ComputedValue(spec, price));
}
@Override
public ComputationTargetType getTargetType() {
return ComputationTargetType.TRADE;
}
@Override
public boolean canApplyTo(final FunctionCompilationContext compilationContext, final ComputationTarget target) {
final Security security = target.getTrade().getSecurity();
return security instanceof IRFutureOptionSecurity ||
security instanceof InterestRateFutureSecurity;
}
@Override
public Set<ValueSpecification> getResults(final FunctionCompilationContext compilationContext, final ComputationTarget target) {
return Collections.singleton(new ValueSpecification(MARGIN_PRICE, target.toSpecification(), createValueProperties().get()));
}
@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext compilationContext, final ComputationTarget target, final ValueRequirement desiredValue) {
try {
final Trade trade = target.getTrade();
final Security security = trade.getSecurity();
Set<ValueRequirement> tsRequirements = null;
if (security instanceof IRFutureOptionSecurity) {
tsRequirements = definitionConverter.getConversionTimeSeriesRequirements(security, optionTradeToTxnDefnConverter.convert(trade));
} else {
tsRequirements = definitionConverter.getConversionTimeSeriesRequirements(security, futureTradeConverter.convert(trade));
}
if (tsRequirements == null) {
return null;