@Override
 public Set<ComputedValue> execute(
     final FunctionExecutionContext executionContext,
     final FunctionInputs inputs,
     final ComputationTarget target,
     final Set<ValueRequirement> desiredValues) {
   final Object positionOrNode = getTarget(target);
   final ConventionBundleSource conventionSource =
       OpenGammaExecutionContext.getConventionBundleSource(executionContext);
   final ConventionBundle bundle =
       conventionSource.getConventionBundle(
           ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, "USD_CAPM"));
   final Clock snapshotClock = executionContext.getValuationClock();
   final LocalDate now = snapshotClock.zonedDateTime().toLocalDate();
   final ValueRequirement desiredValue = desiredValues.iterator().next();
   final ValueProperties constraints = desiredValue.getConstraints();
   final Period samplingPeriod =
       getSamplingPeriod(constraints.getValues(ValuePropertyNames.SAMPLING_PERIOD));
   final LocalDate startDate = now.minus(samplingPeriod);
   final HistoricalTimeSeries riskFreeRateTSObject =
       (HistoricalTimeSeries) inputs.getValue(ValueRequirementNames.HISTORICAL_TIME_SERIES);
   final Object assetPnLObject =
       inputs.getValue(
           new ValueRequirement(
               ValueRequirementNames.PNL_SERIES,
               positionOrNode)); // TODO replace with return series when portfolio weights are in
   if (assetPnLObject == null) {
     throw new OpenGammaRuntimeException("Asset P&L was null");
   }
   final Object assetFairValueObject =
       inputs.getValue(new ValueRequirement(ValueRequirementNames.FAIR_VALUE, positionOrNode));
   if (assetFairValueObject == null) {
     throw new OpenGammaRuntimeException("Asset fair value was null");
   }
   final Object betaObject =
       inputs.getValue(new ValueRequirement(ValueRequirementNames.CAPM_BETA, positionOrNode));
   if (betaObject == null) {
     throw new OpenGammaRuntimeException("Beta was null");
   }
   final double beta = (Double) betaObject;
   final double fairValue = (Double) assetFairValueObject;
   DoubleTimeSeries<?> assetReturnTS = ((DoubleTimeSeries<?>) assetPnLObject).divide(fairValue);
   DoubleTimeSeries<?> riskFreeReturnTS =
       riskFreeRateTSObject.getTimeSeries().divide(100 * DAYS_PER_YEAR);
   DoubleTimeSeries<?>[] series = TimeSeriesIntersector.intersect(riskFreeReturnTS, assetReturnTS);
   riskFreeReturnTS = series[0];
   assetReturnTS = series[1];
   final TreynorRatioCalculator calculator =
       getCalculator(constraints.getValues(ValuePropertyNames.EXCESS_RETURN_CALCULATOR));
   final double ratio = calculator.evaluate(assetReturnTS, riskFreeReturnTS, beta);
   final ValueProperties resultProperties = getResultProperties(desiredValues.iterator().next());
   return Sets.newHashSet(
       new ComputedValue(
           new ValueSpecification(
               new ValueRequirement(
                   ValueRequirementNames.TREYNOR_RATIO, positionOrNode, resultProperties),
               getUniqueId()),
           ratio));
 }
 @SuppressWarnings("synthetic-access")
 @Override
 public InstrumentDerivative convert(
     final FRASecurity security,
     final ForwardRateAgreementDefinition definition,
     final ZonedDateTime now,
     final String[] curveNames,
     final HistoricalTimeSeriesBundle timeSeries) {
   final ExternalId indexId = security.getUnderlyingId();
   final ConventionBundle indexConvention = _conventionSource.getConventionBundle(indexId);
   if (indexConvention == null) {
     throw new OpenGammaRuntimeException(
         "No conventions found for floating reference rate " + indexId);
   }
   final ExternalIdBundle indexIdBundle = indexConvention.getIdentifiers();
   final HistoricalTimeSeries ts =
       timeSeries.get(MarketDataRequirementNames.MARKET_VALUE, indexIdBundle);
   if (ts == null) {
     throw new OpenGammaRuntimeException(
         "Could not get price time series for " + indexIdBundle);
   }
   FastBackedDoubleTimeSeries<LocalDate> localDateTS = ts.getTimeSeries();
   // TODO this normalization should not be done here
   localDateTS = localDateTS.divide(100);
   final FastLongDoubleTimeSeries convertedTS =
       localDateTS.toFastLongDoubleTimeSeries(DateTimeNumericEncoding.TIME_EPOCH_MILLIS);
   final LocalTime fixingTime = LocalTime.of(0, 0);
   final DoubleTimeSeries<ZonedDateTime> indexTS =
       new ArrayZonedDateTimeDoubleTimeSeries(
           new ZonedDateTimeEpochMillisConverter(now.getZone(), fixingTime), convertedTS);
   // TODO: remove the zone
   return definition.toDerivative(now, indexTS, curveNames);
 }
 public static Set<ValueRequirement> buildRequirements(
     final InterpolatedYieldCurveSpecification specification,
     final FunctionCompilationContext context) {
   final Set<ValueRequirement> result = new HashSet<ValueRequirement>();
   for (final FixedIncomeStripWithIdentifier strip : specification.getStrips()) {
     result.add(
         new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, strip.getSecurity()));
   }
   final ConventionBundleSource conventionBundleSource =
       OpenGammaCompilationContext.getConventionBundleSource(context);
   final ConventionBundle conventionBundle =
       conventionBundleSource.getConventionBundle(
           Identifier.of(
               InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME,
               specification.getCurrency().getCode() + "_SWAP"));
   final ConventionBundle referenceRateConvention =
       conventionBundleSource.getConventionBundle(
           IdentifierBundle.of(conventionBundle.getSwapFloatingLegInitialRate()));
   final Identifier initialRefRateId =
       SecurityUtils.bloombergTickerSecurityId(
           referenceRateConvention.getIdentifiers().getIdentifier(SecurityUtils.BLOOMBERG_TICKER));
   result.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, initialRefRateId));
   return Collections.unmodifiableSet(result);
 }
 @Override
 public Set<ValueRequirement> getRequirements(
     final FunctionCompilationContext context,
     final ComputationTarget target,
     final ValueRequirement desiredValue) {
   final Object positionOrNode = getTarget(target);
   final Set<ValueRequirement> result = new HashSet<ValueRequirement>();
   final ValueProperties constraints = desiredValue.getConstraints();
   final Set<String> samplingPeriodNames =
       constraints.getValues(ValuePropertyNames.SAMPLING_PERIOD);
   if (samplingPeriodNames == null || samplingPeriodNames.size() != 1) {
     return null;
   }
   final Set<String> scheduleCalculatorNames =
       constraints.getValues(ValuePropertyNames.SCHEDULE_CALCULATOR);
   if (scheduleCalculatorNames == null || scheduleCalculatorNames.size() != 1) {
     return null;
   }
   final Set<String> samplingFunctionNames =
       constraints.getValues(ValuePropertyNames.SAMPLING_FUNCTION);
   if (samplingFunctionNames == null || samplingFunctionNames.size() != 1) {
     return null;
   }
   final Set<String> returnCalculatorNames =
       constraints.getValues(ValuePropertyNames.RETURN_CALCULATOR);
   if (returnCalculatorNames == null || returnCalculatorNames.size() != 1) {
     return null;
   }
   final Set<String> stdDevCalculatorNames =
       constraints.getValues(ValuePropertyNames.STD_DEV_CALCULATOR);
   if (stdDevCalculatorNames == null || stdDevCalculatorNames.size() != 1) {
     return null;
   }
   final Set<String> covarianceCalculatorNames =
       constraints.getValues(ValuePropertyNames.COVARIANCE_CALCULATOR);
   if (covarianceCalculatorNames == null || covarianceCalculatorNames.size() != 1) {
     return null;
   }
   final Set<String> varianceCalculatorNames =
       constraints.getValues(ValuePropertyNames.VARIANCE_CALCULATOR);
   if (varianceCalculatorNames == null || varianceCalculatorNames.size() != 1) {
     return null;
   }
   final String samplingPeriodName = samplingPeriodNames.iterator().next();
   final String scheduleCalculatorName = scheduleCalculatorNames.iterator().next();
   final String samplingFunctionName = samplingFunctionNames.iterator().next();
   final String returnCalculatorName = returnCalculatorNames.iterator().next();
   final ValueProperties pnlSeriesProperties =
       ValueProperties.builder()
           .withAny(ValuePropertyNames.CURRENCY)
           .with(ValuePropertyNames.SAMPLING_PERIOD, samplingPeriodName)
           .with(ValuePropertyNames.SCHEDULE_CALCULATOR, scheduleCalculatorName)
           .with(ValuePropertyNames.SAMPLING_FUNCTION, samplingFunctionName)
           .with(ValuePropertyNames.RETURN_CALCULATOR, returnCalculatorName)
           .get();
   final ValueProperties betaProperties =
       ValueProperties.builder()
           .with(ValuePropertyNames.SAMPLING_PERIOD, samplingPeriodName)
           .with(ValuePropertyNames.SCHEDULE_CALCULATOR, scheduleCalculatorName)
           .with(ValuePropertyNames.SAMPLING_FUNCTION, samplingFunctionName)
           .with(ValuePropertyNames.RETURN_CALCULATOR, returnCalculatorName)
           .with(
               ValuePropertyNames.COVARIANCE_CALCULATOR,
               covarianceCalculatorNames.iterator().next())
           .with(ValuePropertyNames.VARIANCE_CALCULATOR, varianceCalculatorNames.iterator().next())
           .get();
   result.add(
       new ValueRequirement(
           ValueRequirementNames.PNL_SERIES, positionOrNode, pnlSeriesProperties));
   result.add(new ValueRequirement(ValueRequirementNames.FAIR_VALUE, positionOrNode));
   result.add(
       new ValueRequirement(ValueRequirementNames.CAPM_BETA, positionOrNode, betaProperties));
   final HistoricalTimeSeriesResolver resolver =
       OpenGammaCompilationContext.getHistoricalTimeSeriesResolver(context);
   final ConventionBundleSource conventionSource =
       OpenGammaCompilationContext.getConventionBundleSource(context);
   final ConventionBundle bundle =
       conventionSource.getConventionBundle(
           ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, "USD_CAPM"));
   final HistoricalTimeSeriesResolutionResult timeSeries =
       resolver.resolve(
           bundle.getCAPMMarket(),
           null,
           null,
           null,
           MarketDataRequirementNames.MARKET_VALUE,
           _resolutionKey);
   if (timeSeries == null) {
     return null;
   }
   result.add(
       HistoricalTimeSeriesFunctionUtils.createHTSRequirement(
           timeSeries,
           MarketDataRequirementNames.MARKET_VALUE,
           DateConstraint.VALUATION_TIME.minus(samplingPeriodName),
           true,
           DateConstraint.VALUATION_TIME,
           true));
   return result;
 }