Interface ScenarioMarketData

    • 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 scenarios
        valuationDate - the valuation dates associated with all scenarios
        values - the market data values, one for each scenario
        timeSeries - 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 scenarios
        valuationDate - the valuation dates associated with the market data, one for each scenario
        values - the market data values, one for each scenario
        timeSeries - 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. See MarketDataFactory for the ability to apply multiple perturbations, including perturbations to calibration inputs, such as quotes.

        Parameters:
        scenarioCount - the number of scenarios, one or more
        marketData - 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 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.

        Type Parameters:
        T - the type of the individual market data values used when performing calculations for one scenario
        U - 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 identifier
        value - 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 perturb
        perturbation - the perturbation to apply
        refData - the reference data
        Returns:
        a parameterized data instance based on this with the specified perturbation applied
        Throws:
        IllegalArgumentException - if the scenario count does not match
        MarketDataNotFoundException - if the identifier is not found
        RuntimeException - if unable to perform the perturbation