@Override public int getScenarioCount() { return marketData.getScenarioCount(); }
@Override public int getScenarioCount() { return underlying.getScenarioCount(); }
/** * Creates a new instance. * * @param underlying1 the first underlying set of market data * @param underlying2 the second underlying set of market data */ CombinedScenarioMarketData(ScenarioMarketData underlying1, ScenarioMarketData underlying2) { this.underlying1 = underlying1; this.underlying2 = underlying2; if (underlying1.getScenarioCount() == 1) { scenarioCount = underlying2.getScenarioCount(); } else if (underlying2.getScenarioCount() == 1) { scenarioCount = underlying1.getScenarioCount(); } else if (underlying1.getScenarioCount() == underlying2.getScenarioCount()) { scenarioCount = underlying1.getScenarioCount(); } else { throw new IllegalArgumentException( Messages.format( "When combining scenario market data, both sets of data must have the same number of scenarios or one " + "of them must have one scenario. Found {} and {} scenarios", underlying1.getScenarioCount(), underlying2.getScenarioCount())); } }
/** * Returns a stream of market data, one for each scenario. * <p> * The stream will return instances of {@link MarketData}, where each represents * a single scenario view of the complete set of data. * * @return the stream of market data, one for the each scenario * @throws IndexOutOfBoundsException if the index is invalid */ public default Stream<MarketData> scenarios() { return IntStream.range(0, getScenarioCount()) .mapToObj(scenarioIndex -> SingleScenarioMarketData.of(this, scenarioIndex)); }
@ImmutableValidator private void validate() { ArgChecker.inRange(scenarioIndex, 0, marketData.getScenarioCount(), "scenarioIndex"); }
@ImmutableValidator private void validate() { if (value.isScenarioValue() && value.getScenarioCount() != underlying.getScenarioCount()) { throw new IllegalArgumentException(Messages.format( "Scenario count mismatch: value has {} scenarios but this market data has {}", value.getScenarioCount(), underlying.getScenarioCount())); } }
return id.createScenarioValue(box, getScenarioCount()); return (U) scenarioValue; return id.createScenarioValue(box, getScenarioCount());
ReferenceData refData) { if (perturbation.getScenarioCount() != 1 && perturbation.getScenarioCount() != getScenarioCount()) { throw new IllegalArgumentException(Messages.format( "Scenario count mismatch: perturbation has {} scenarios but this market data has {}", perturbation.getScenarioCount(), getScenarioCount()));
assertThat(combinedData.getScenarioCount()).isEqualTo(3); assertThat(combinedData.getValue(TEST_ID1).getValue(0)).isEqualTo(1.1); assertThat(combinedData.getValue(TEST_ID1).getValue(2)).isEqualTo(1.1);