MarketDataCovarianceMatrixFunction extends SampledCovarianceMatrixFunction { @Override public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) { final HistoricalViewEvaluationMarketData marketData = (HistoricalViewEvaluationMarketData) inputs.getValue(ValueRequirementNames.HISTORICAL_TIME_SERIES); final ValueSpecification[] marketDataSpecs = marketData.getValueSpecifications().toArray(new ValueSpecification[marketData.getValueSpecifications().size()]); final LocalDateDoubleTimeSeries[] timeSeries = new LocalDateDoubleTimeSeries[marketDataSpecs.length]; for (int i = 0; i < marketDataSpecs.length; i++) { timeSeries[i] = marketData.getDoubleTimeSeries(marketDataSpecs[i]); } final ValueRequirement desiredValueReq = desiredValues.iterator().next(); final ValueSpecification desiredValueSpec = new ValueSpecification(ValueRequirementNames.COVARIANCE_MATRIX, target.toSpecification(), desiredValueReq.getConstraints()); return Collections.singleton(new ComputedValue(desiredValueSpec, createCovarianceMatrix(timeSeries, marketDataSpecs))); }  @Override Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testExecuteNoData() { final HistoricalViewEvaluationMarketData input = new HistoricalViewEvaluationMarketData(); final FunctionInputs inputs = new FunctionInputsImpl(null, new ComputedValue(INPUT_VALUE, input)); FUNCTION.execute(new FunctionExecutionContext(), inputs, ComputationTarget.NULL, Collections.singleton(DESIRED_VALUE)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testExecuteTotalMisalignedData() { final HistoricalViewEvaluationMarketData input = new HistoricalViewEvaluationMarketData(); input.addTimeSeries(timeSeriesSpecification(0), localDateDoubleTimeSeries(LocalDate.of(2013, 1, 1), 10)); input.addTimeSeries(timeSeriesSpecification(1), localDateDoubleTimeSeries(LocalDate.of(2013, 1, 1), 15)); input.addTimeSeries(timeSeriesSpecification(2), localDateDoubleTimeSeries(LocalDate.of(2013, 2, 1), 10)); input.addTimeSeries(timeSeriesSpecification(3), localDateDoubleTimeSeries(LocalDate.of(2013, 2, 1), 15)); final FunctionInputs inputs = new FunctionInputsImpl(null, new ComputedValue(INPUT_VALUE, input)); FUNCTION.execute(new FunctionExecutionContext(), inputs, ComputationTarget.NULL, Collections.singleton(DESIRED_VALUE)); }