Interface CalculationRunner

  • All Superinterfaces:
    AutoCloseable

    public interface CalculationRunner
    extends AutoCloseable
    Component that provides the ability to perform calculations on multiple targets, measures and scenarios.

    The strata-pricer module provides the ability to calculate results for a single trade, single measure and single set of market data. CalculationRunner provides the ability to calculate results for many trades, many measures and many sets of market data.

    Once obtained, the CalculationRunner instance may be used to calculate results. The four "calculate" methods handle the combination of single versus scenario market data, and synchronous versus asynchronous.

    A calculation runner is typically obtained using the static methods on this interface. The instance contains an executor thread-pool, thus care should be taken to ensure the thread-pool is correctly managed. For example, try-with-resources could be used:

      try (CalculationRunner runner = CalculationRunner.ofMultiThreaded()) {
        // use the runner
      }
     
    • Method Detail

      • ofMultiThreaded

        static CalculationRunner ofMultiThreaded()
        Creates a standard multi-threaded calculation runner capable of performing calculations.

        This factory creates an executor basing the number of threads on the number of available processors. It is recommended to use try-with-resources to manage the runner:

          try (CalculationRunner runner = CalculationRunner.ofMultiThreaded()) {
            // use the runner
          }
         
        Returns:
        the calculation runner
      • of

        static CalculationRunner of​(ExecutorService executor)
        Creates a calculation runner capable of performing calculations, specifying the executor.

        It is the callers responsibility to manage the life-cycle of the executor.

        Parameters:
        executor - the executor to use
        Returns:
        the calculation runner
      • calculate

        Results calculate​(CalculationRules calculationRules,
                          List<? extends CalculationTarget> targets,
                          List<Column> columns,
                          MarketData marketData,
                          ReferenceData refData)
        Performs calculations for a single set of market data.

        This returns a grid of results based on the specified targets, columns, rules and market data. The grid will contain a row for each target and a column for each measure.

        Parameters:
        calculationRules - the rules defining how the calculation is performed
        targets - the targets for which values of the measures will be calculated
        columns - the configuration for the columns that will be calculated, including the measure and any column-specific overrides
        marketData - the market data to be used in the calculations
        refData - the reference data to be used in the calculations
        Returns:
        the grid of calculation results, based on the targets and columns
      • calculateAsync

        void calculateAsync​(CalculationRules calculationRules,
                            List<? extends CalculationTarget> targets,
                            List<Column> columns,
                            MarketData marketData,
                            ReferenceData refData,
                            CalculationListener listener)
        Performs calculations asynchronously for a single set of market data, invoking a listener as each calculation completes.

        This method requires the listener to assemble the results, but it can be much more memory efficient when calculating aggregate results. If the individual results are discarded after they are incorporated into the aggregate they can be garbage collected.

        Parameters:
        calculationRules - the rules defining how the calculation is performed
        targets - the targets for which values of the measures will be calculated
        columns - the configuration for the columns that will be calculated, including the measure and any column-specific overrides
        marketData - the market data to be used in the calculations
        refData - the reference data to be used in the calculations
        listener - listener that is invoked when individual results are calculated
      • calculateMultiScenario

        Results calculateMultiScenario​(CalculationRules calculationRules,
                                       List<? extends CalculationTarget> targets,
                                       List<Column> columns,
                                       ScenarioMarketData marketData,
                                       ReferenceData refData)
        Performs calculations for multiple scenarios, each with a different set of market data.

        This returns a grid of results based on the specified targets, columns, rules and market data. The grid will contain a row for each target and a column for each measure.

        Parameters:
        calculationRules - the rules defining how the calculation is performed
        targets - the targets for which values of the measures will be calculated
        columns - the configuration for the columns that will be calculated, including the measure and any column-specific overrides
        marketData - the market data to be used in the calculations
        refData - the reference data to be used in the calculations
        Returns:
        the grid of calculation results, based on the targets and columns
      • calculateMultiScenarioAsync

        void calculateMultiScenarioAsync​(CalculationRules calculationRules,
                                         List<? extends CalculationTarget> targets,
                                         List<Column> columns,
                                         ScenarioMarketData marketData,
                                         ReferenceData refData,
                                         CalculationListener listener)
        Performs calculations asynchronously for a multiple scenarios, each with a different set of market data, invoking a listener as each calculation completes.

        This method requires the listener to assemble the results, but it can be much more memory efficient when calculating aggregate results. If the individual results are discarded after they are incorporated into the aggregate they can be garbage collected.

        Parameters:
        calculationRules - the rules defining how the calculation is performed
        targets - the targets for which values of the measures will be calculated
        columns - the configuration for the columns that will be calculated, including the measure and any column-specific overrides
        marketData - the market data to be used in the calculations
        refData - the reference data to be used in the calculations
        listener - listener that is invoked when individual results are calculated
      • getTaskRunner

        CalculationTaskRunner getTaskRunner()
        Gets the underlying task runner.

        In most cases, this runner will be implemented using an instance of CalculationTaskRunner. That interface provides a lower-level API, with the ability optimize if similar calculations are being made repeatedly.

        Returns:
        the underlying task runner
        Throws:
        UnsupportedOperationException - if access to the task runner is not provided