@Override public <U, R> MarketDataBox<R> combineWith(MarketDataBox<U> other, BiFunction<T, U, R> fn) { return other.isSingleValue() ? combineWithSingle(other, fn) : combineWithMultiple(other, fn); }
/** * Obtains an instance containing the specified market data values, one for each scenario. * * @param <T> the type of the market data value * @param values single market data values, one for each scenario * @return a scenario market data box containing single market data values, one for each scenario */ public static <T> ScenarioMarketDataBox<T> of(List<T> values) { return new ScenarioMarketDataBox<>(ScenarioArray.of(values)); }
@Override public <U, R> MarketDataBox<R> combineWith(MarketDataBox<U> other, BiFunction<T, U, R> fn) { return other.isSingleValue() ? combineWithSingle(other, fn) : combineWithMultiple(other, fn); }
@Override public LocalDate getValuationDate() { return marketData.getValuationDate().getValue(scenarioIndex); }
private <U, R> MarketDataBox<R> combineWithSingle(MarketDataBox<U> other, BiFunction<T, U, R> fn) { U otherValue = other.getSingleValue(); return applyToScenarios(i -> fn.apply(value.get(i), otherValue)); }
@Override public ScenarioMarketData combinedWith(ScenarioMarketData other) { if (other instanceof ImmutableScenarioMarketData) { return combinedWith((ImmutableScenarioMarketData) other); } else { return ScenarioMarketData.super.combinedWith(other); } }
/** * Obtains an instance from a single value where the value applies to all scenarios. * * @param <T> the type of the value * @param scenarioCount the nnumber of scenarios * @param value the single value, used for all scenarios * @return an instance with the specified values */ public static <T> ScenarioArray<T> ofSingleValue(int scenarioCount, T value) { return SingleScenarioArray.of(scenarioCount, value); }
/** * Returns a builder used to create an instance of the bean. * @param <T> the type * @return the builder, not null */ static <T> SingleMarketDataBox.Builder<T> builder() { return new SingleMarketDataBox.Builder<>(); }
/** * Creates a mutable builder that can be used to create an instance of the market data. * * @param valuationDate the valuation dates associated with the market data, one for each scenario * @return the mutable builder */ public static ImmutableScenarioMarketDataBuilder builder(MarketDataBox<LocalDate> valuationDate) { return new ImmutableScenarioMarketDataBuilder(valuationDate); }
/** * Returns a scenario FX rate provider which takes its data from the provided market data. * * @param marketData market data containing FX rates * @return a scenario FX rate provider which takes its data from the provided market data */ public static ScenarioFxRateProvider of(ScenarioMarketData marketData) { return new DefaultScenarioFxRateProvider(marketData, ObservableSource.NONE); }
/** * Obtains an instance from the specified list of values. * * @param <T> the type of the value * @param values the values, one value for each scenario * @return an instance with the specified values */ public static <T> DefaultScenarioArray<T> of(List<T> values) { return new DefaultScenarioArray<>(values); }
/** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ Builder<T> toBuilder() { return new Builder<>(this); }
@Override public DoubleScenarioArray build() { return new DoubleScenarioArray( values); }
/** * Obtains a market data instance that contains no data and has no scenarios. * * @return an empty instance */ public static ScenarioMarketData empty() { return ImmutableScenarioMarketData.empty(); }
/** * Obtains an instance containing a single market data value. * * @param <T> the type of the value * @param value the market data value * @return a market data box containing a single market data value */ public static <T> SingleMarketDataBox<T> of(T value) { return new SingleMarketDataBox<>(value); }
/** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ Builder<T> toBuilder() { return new Builder<>(this); }
/** * Creates a mutable builder that can be used to create an instance of the market data. * * @param valuationDate the valuation date associated with the market data * @return the mutable builder */ public static ImmutableScenarioMarketDataBuilder builder(LocalDate valuationDate) { return new ImmutableScenarioMarketDataBuilder(valuationDate); }
/** * Returns a scenario FX rate provider which takes its data from the provided market data. * * @param marketData market data containing FX rates * @param source the source of the FX rates * @return a scenario FX rate provider which takes its data from the provided market data */ public static ScenarioFxRateProvider of(ScenarioMarketData marketData, ObservableSource source) { return new DefaultScenarioFxRateProvider(marketData, source); }
@Override public DefaultScenarioArray<T> build() { return new DefaultScenarioArray<>( values); }