Interface ScenarioMarketData
-
- All Known Implementing Classes:
BuiltScenarioMarketData
,ImmutableScenarioMarketData
public interface ScenarioMarketData
Provides access to market data across one or more scenarios.Market data is looked up using subclasses of
MarketDataId
. All data is valid for a single date, defined bygetValuationDate()
.There are two ways to access the available market data.
The first way is to use the access methods on this interface that return the data associated with a single identifier for all scenarios. The two key methods are
getValue(MarketDataId)
andgetScenarioValue(ScenarioMarketDataId)
.The second way is to use the method
scenarios()
orscenario(int)
. These return all the data associated with a single scenario. This approach is convenient for single scenario pricers.The standard implementation is
ImmutableScenarioMarketData
.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ScenarioMarketData
combinedWith(ScenarioMarketData other)
Returns set of market data which combines the data from this set of data with another set.default boolean
containsValue(MarketDataId<?> id)
Checks if this market data contains a value for the specified identifier.static ScenarioMarketData
empty()
Obtains a market data instance that contains no data and has no scenarios.<T> Set<MarketDataId<T>>
findIds(MarketDataName<T> name)
Finds the market data identifiers associated with the specified name.<T> Optional<MarketDataBox<T>>
findValue(MarketDataId<T> id)
Finds the market data value associated with the specified identifier.Set<MarketDataId<?>>
getIds()
Gets the market data identifiers.int
getScenarioCount()
Gets the number of scenarios.default <T,U extends ScenarioArray<T>>
UgetScenarioValue(ScenarioMarketDataId<T,U> id)
Gets an object containing market data for multiple scenarios.LocalDateDoubleTimeSeries
getTimeSeries(ObservableId id)
Gets the time-series associated with the specified identifier, empty if not found.Set<ObservableId>
getTimeSeriesIds()
Gets the time-series identifiers.MarketDataBox<LocalDate>
getValuationDate()
Gets a box that can provide the valuation date of each scenario.default <T> MarketDataBox<T>
getValue(MarketDataId<T> id)
Gets the market data value associated with the specified identifier.static ScenarioMarketData
of(int scenarioCount, MarketData marketData)
Obtains an instance by wrapping a single set of market data.static ScenarioMarketData
of(int scenarioCount, MarketDataBox<LocalDate> valuationDate, Map<? extends MarketDataId<?>,MarketDataBox<?>> values, Map<? extends ObservableId,LocalDateDoubleTimeSeries> timeSeries)
Obtains an instance from a valuation date, map of values and time-series.static ScenarioMarketData
of(int scenarioCount, LocalDate valuationDate, Map<? extends MarketDataId<?>,MarketDataBox<?>> values, Map<? extends ObservableId,LocalDateDoubleTimeSeries> timeSeries)
Obtains an instance from a valuation date, map of values and time-series.default MarketData
scenario(int scenarioIndex)
Returns market data for a single scenario.default Stream<MarketData>
scenarios()
Returns a stream of market data, one for each scenario.default <T> ScenarioMarketData
withPerturbation(MarketDataId<T> id, ScenarioPerturbation<T> perturbation, ReferenceData refData)
Returns a copy of this market data with the specified value perturbed.default <T> ScenarioMarketData
withValue(MarketDataId<T> id, MarketDataBox<T> value)
Returns a copy of this market data with the specified value.
-
-
-
Method Detail
-
of
static ScenarioMarketData of(int scenarioCount, LocalDate valuationDate, Map<? extends MarketDataId<?>,MarketDataBox<?>> values, Map<? extends ObservableId,LocalDateDoubleTimeSeries> timeSeries)
Obtains an instance from a valuation date, map of values and time-series.The valuation date and map of values must have the same number of scenarios.
- Parameters:
scenarioCount
- the number of scenariosvaluationDate
- the valuation dates associated with all scenariosvalues
- the market data values, one for each scenariotimeSeries
- the time-series- Returns:
- a set of market data containing the values in the map
-
of
static ScenarioMarketData of(int scenarioCount, MarketDataBox<LocalDate> valuationDate, Map<? extends MarketDataId<?>,MarketDataBox<?>> values, Map<? extends ObservableId,LocalDateDoubleTimeSeries> timeSeries)
Obtains an instance from a valuation date, map of values and time-series.The valuation date and map of values must have the same number of scenarios.
- Parameters:
scenarioCount
- the number of scenariosvaluationDate
- the valuation dates associated with the market data, one for each scenariovalues
- the market data values, one for each scenariotimeSeries
- the time-series- Returns:
- a set of market data containing the values in the map
-
of
static ScenarioMarketData of(int scenarioCount, MarketData marketData)
Obtains an instance by wrapping a single set of market data.The result will consist of a
ScenarioMarketData
that returns the specified market data for each scenario.This can be used in association with the
withPerturbation
method to take a base set of market data and create a complete set of perturbations. SeeMarketDataFactory
for the ability to apply multiple perturbations, including perturbations to calibration inputs, such as quotes.- Parameters:
scenarioCount
- the number of scenarios, one or moremarketData
- the single set of market data- Returns:
- a set of market data containing the values in the map
-
empty
static ScenarioMarketData empty()
Obtains a market data instance that contains no data and has no scenarios.- Returns:
- an empty instance
-
getValuationDate
MarketDataBox<LocalDate> getValuationDate()
Gets a box that can provide the valuation date of each scenario.- Returns:
- the valuation dates of the scenarios
-
getScenarioCount
int getScenarioCount()
Gets the number of scenarios.- Returns:
- the number of scenarios
-
scenarios
default Stream<MarketData> scenarios()
Returns a stream of market data, one for each scenario.The stream will return instances of
MarketData
, where each represents a single scenario view of the complete set of data.- Returns:
- the stream of market data, one for the each scenario
- Throws:
IndexOutOfBoundsException
- if the index is invalid
-
scenario
default MarketData scenario(int scenarioIndex)
Returns market data for a single scenario.This returns a view of the market data for the single specified scenario.
- Parameters:
scenarioIndex
- the scenario index- Returns:
- the market data for the specified scenario
- Throws:
IndexOutOfBoundsException
- if the index is invalid
-
containsValue
default boolean containsValue(MarketDataId<?> id)
Checks if this market data contains a value for the specified identifier.- Parameters:
id
- the identifier to find- Returns:
- true if the market data contains a value for the identifier
-
getValue
default <T> MarketDataBox<T> getValue(MarketDataId<T> id)
Gets the market data value associated with the specified identifier.The result is a box that provides data for all scenarios. If this market data instance contains the identifier, the value will be returned. Otherwise, an exception will be thrown.
- Type Parameters:
T
- the type of the market data value- Parameters:
id
- the identifier to find- Returns:
- the market data value box providing data for all scenarios
- Throws:
MarketDataNotFoundException
- if the identifier is not found
-
findValue
<T> Optional<MarketDataBox<T>> findValue(MarketDataId<T> id)
Finds the market data value associated with the specified identifier.The result is a box that provides data for all scenarios. If this market data instance contains the identifier, the value will be returned. Otherwise, an empty optional will be returned.
- Type Parameters:
T
- the type of the market data value- Parameters:
id
- the identifier to find- Returns:
- the market data value box providing data for all scenarios, empty if not found
-
getIds
Set<MarketDataId<?>> getIds()
Gets the market data identifiers.- Returns:
- the set of market data identifiers
-
findIds
<T> Set<MarketDataId<T>> findIds(MarketDataName<T> name)
Finds the market data identifiers associated with the specified name.This returns the unique identifiers that refer to the specified name. There may be more than one identifier associated with a name as the name is not unique.
- Type Parameters:
T
- the type of the market data value- Parameters:
name
- the name to find- Returns:
- the set of market data identifiers, empty if name not found
-
getScenarioValue
default <T,U extends ScenarioArray<T>> U getScenarioValue(ScenarioMarketDataId<T,U> id)
Gets an object containing market data for multiple scenarios.There are many possible ways to store scenario market data for a data type. For example, if the single values are doubles, the scenario value might simply be a
List<Double>
or it might be a wrapper class that stores the values more efficiently in adouble[]
.If the market data contains a single value for the identifier or a scenario value of the wrong type, a value of the required type is created by invoking
ScenarioMarketDataId.createScenarioValue(com.opengamma.strata.data.scenario.MarketDataBox<T>, int)
.Normally this should not be necessary. It is assumed the required scenario values will be created by the perturbations that create scenario data. However there is no mechanism in the market data system to guarantee that scenario values of a particular type are available. If they are not they are created on demand.
Values returned from this method might be cached for efficiency.
- Type Parameters:
T
- the type of the individual market data values used when performing calculations for one scenarioU
- the type of the object containing the market data for all scenarios- Parameters:
id
- the identifier to find- Returns:
- an object containing market data for multiple scenarios
- Throws:
IllegalArgumentException
- if no value is found
-
combinedWith
default ScenarioMarketData combinedWith(ScenarioMarketData other)
Returns set of market data which combines the data from this set of data with another set.If the same item of data is available in both sets, it will be taken from this set.
Both sets of data must contain the same number of scenarios, or one of them must have one scenario. If one of the sets of data has one scenario, the combined set will have the scenario count of the other set.
- Parameters:
other
- another set of market data- Returns:
- a set of market data combining the data in this set with the data in the other
-
getTimeSeriesIds
Set<ObservableId> getTimeSeriesIds()
Gets the time-series identifiers.Time series are not affected by scenarios, therefore there is a single time-series for each identifier which is shared between all scenarios.
- Returns:
- the set of observable identifiers
-
getTimeSeries
LocalDateDoubleTimeSeries getTimeSeries(ObservableId id)
Gets the time-series associated with the specified identifier, empty if not found.Time series are not affected by scenarios, therefore there is a single time-series for each identifier which is shared between all scenarios.
- Parameters:
id
- the identifier to find- Returns:
- the time-series, empty if no time-series found
-
withValue
default <T> ScenarioMarketData withValue(MarketDataId<T> id, MarketDataBox<T> value)
Returns a copy of this market data with the specified value.When the result is queried for the specified identifier, the specified value will be returned.
The number of scenarios in the box must match this market data.
For example, this method could be used to replace a curve with a bumped curve.
- Type Parameters:
T
- the type of the market data value- Parameters:
id
- the identifiervalue
- the value to associate with the identifier- Returns:
- the derived market data with the specified identifier and value
- Throws:
IllegalArgumentException
- if the scenario count does not match
-
withPerturbation
default <T> ScenarioMarketData withPerturbation(MarketDataId<T> id, ScenarioPerturbation<T> perturbation, ReferenceData refData)
Returns a copy of this market data with the specified value perturbed.This finds the market data value using the identifier, throwing an exception if not found. It then perturbs the value and returns a new instance containing the value.
The number of scenarios of the perturbation must match this market data.
This method is intended for one off perturbations of calibrated market data, such as curves. See
MarketDataFactory
for the ability to apply multiple perturbations, including perturbations to calibration inputs, such as quotes.This instance is immutable and unaffected by this method call.
- Type Parameters:
T
- the type of the market data value- Parameters:
id
- the identifier to perturbperturbation
- the perturbation to applyrefData
- the reference data- Returns:
- a parameterized data instance based on this with the specified perturbation applied
- Throws:
IllegalArgumentException
- if the scenario count does not matchMarketDataNotFoundException
- if the identifier is not foundRuntimeException
- if unable to perform the perturbation
-
-