public interface ScenarioMarketData
Market data is looked up using subclasses of MarketDataId
.
All data is valid for a single date, defined by getValuationDate()
.
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)
and getScenarioValue(ScenarioMarketDataId)
.
The second way is to use the method scenarios()
or scenario(int)
.
These return all the data associated with a single scenario.
This approach is convenient for single scenario pricers.
The standard implementation is ImmutableScenarioMarketData
.
Modifier and Type | Method and 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>> |
getScenarioValue(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,
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,
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.
|
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.
|
static ScenarioMarketData of(int scenarioCount, LocalDate valuationDate, Map<? extends MarketDataId<?>,MarketDataBox<?>> values, Map<? extends ObservableId,LocalDateDoubleTimeSeries> timeSeries)
The valuation date and map of values must have the same number of scenarios.
scenarioCount
- the number of scenariosvaluationDate
- the valuation dates associated with all scenariosvalues
- the market data values, one for each scenariotimeSeries
- the time-seriesstatic ScenarioMarketData of(int scenarioCount, MarketDataBox<LocalDate> valuationDate, Map<? extends MarketDataId<?>,MarketDataBox<?>> values, Map<? extends ObservableId,LocalDateDoubleTimeSeries> timeSeries)
The valuation date and map of values must have the same number of scenarios.
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-seriesstatic ScenarioMarketData of(int scenarioCount, MarketData marketData)
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.
See MarketDataFactory
for the ability to apply multiple perturbations, including
perturbations to calibration inputs, such as quotes.
scenarioCount
- the number of scenarios, one or moremarketData
- the single set of market datastatic ScenarioMarketData empty()
MarketDataBox<LocalDate> getValuationDate()
int getScenarioCount()
default Stream<MarketData> scenarios()
The stream will return instances of MarketData
, where each represents
a single scenario view of the complete set of data.
IndexOutOfBoundsException
- if the index is invaliddefault MarketData scenario(int scenarioIndex)
This returns a view of the market data for the single specified scenario.
scenarioIndex
- the scenario indexIndexOutOfBoundsException
- if the index is invaliddefault boolean containsValue(MarketDataId<?> id)
id
- the identifier to finddefault <T> MarketDataBox<T> getValue(MarketDataId<T> id)
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.
T
- the type of the market data valueid
- the identifier to findMarketDataNotFoundException
- if the identifier is not found<T> Optional<MarketDataBox<T>> findValue(MarketDataId<T> id)
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.
T
- the type of the market data valueid
- the identifier to findSet<MarketDataId<?>> getIds()
<T> Set<MarketDataId<T>> findIds(MarketDataName<T> 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.
T
- the type of the market data valuename
- the name to finddefault <T,U extends ScenarioArray<T>> U getScenarioValue(ScenarioMarketDataId<T,U> id)
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 a double[]
.
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.
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 scenariosid
- the identifier to findIllegalArgumentException
- if no value is founddefault ScenarioMarketData combinedWith(ScenarioMarketData other)
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.
other
- another set of market dataSet<ObservableId> getTimeSeriesIds()
Time series are not affected by scenarios, therefore there is a single time-series for each identifier which is shared between all scenarios.
LocalDateDoubleTimeSeries getTimeSeries(ObservableId id)
Time series are not affected by scenarios, therefore there is a single time-series for each identifier which is shared between all scenarios.
id
- the identifier to finddefault <T> ScenarioMarketData withValue(MarketDataId<T> id, MarketDataBox<T> 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.
T
- the type of the market data valueid
- the identifiervalue
- the value to associate with the identifierIllegalArgumentException
- if the scenario count does not matchdefault <T> ScenarioMarketData withPerturbation(MarketDataId<T> id, ScenarioPerturbation<T> perturbation, ReferenceData refData)
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.
T
- the type of the market data valueid
- the identifier to perturbperturbation
- the perturbation to applyrefData
- the reference dataIllegalArgumentException
- if the scenario count does not matchMarketDataNotFoundException
- if the identifier is not foundRuntimeException
- if unable to perform the perturbationCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.