public interface CalculationRunner extends AutoCloseable
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
}
| Modifier and Type | Method and Description |
|---|---|
Results |
calculate(CalculationRules calculationRules,
List<? extends CalculationTarget> targets,
List<Column> columns,
MarketData marketData,
ReferenceData refData)
Performs calculations for a single set of market data.
|
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.
|
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.
|
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.
|
void |
close()
Closes any resources held by the component.
|
CalculationTaskRunner |
getTaskRunner()
Gets the underlying task runner.
|
static CalculationRunner |
of(ExecutorService executor)
Creates a calculation runner capable of performing calculations, specifying the executor.
|
static CalculationRunner |
ofMultiThreaded()
Creates a standard multi-threaded calculation runner capable of performing calculations.
|
static CalculationRunner ofMultiThreaded()
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
}
static CalculationRunner of(ExecutorService executor)
It is the callers responsibility to manage the life-cycle of the executor.
executor - the executor to useResults calculate(CalculationRules calculationRules, List<? extends CalculationTarget> targets, List<Column> columns, MarketData marketData, ReferenceData refData)
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.
calculationRules - the rules defining how the calculation is performedtargets - the targets for which values of the measures will be calculatedcolumns - the configuration for the columns that will be calculated,
including the measure and any column-specific overridesmarketData - the market data to be used in the calculationsrefData - the reference data to be used in the calculationsvoid calculateAsync(CalculationRules calculationRules, List<? extends CalculationTarget> targets, List<Column> columns, MarketData marketData, ReferenceData refData, CalculationListener listener)
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.
calculationRules - the rules defining how the calculation is performedtargets - the targets for which values of the measures will be calculatedcolumns - the configuration for the columns that will be calculated,
including the measure and any column-specific overridesmarketData - the market data to be used in the calculationsrefData - the reference data to be used in the calculationslistener - listener that is invoked when individual results are calculatedResults calculateMultiScenario(CalculationRules calculationRules, List<? extends CalculationTarget> targets, List<Column> columns, ScenarioMarketData marketData, ReferenceData refData)
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.
calculationRules - the rules defining how the calculation is performedtargets - the targets for which values of the measures will be calculatedcolumns - the configuration for the columns that will be calculated,
including the measure and any column-specific overridesmarketData - the market data to be used in the calculationsrefData - the reference data to be used in the calculationsvoid calculateMultiScenarioAsync(CalculationRules calculationRules, List<? extends CalculationTarget> targets, List<Column> columns, ScenarioMarketData marketData, ReferenceData refData, CalculationListener listener)
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.
calculationRules - the rules defining how the calculation is performedtargets - the targets for which values of the measures will be calculatedcolumns - the configuration for the columns that will be calculated,
including the measure and any column-specific overridesmarketData - the market data to be used in the calculationsrefData - the reference data to be used in the calculationslistener - listener that is invoked when individual results are calculatedCalculationTaskRunner getTaskRunner()
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.
UnsupportedOperationException - if access to the task runner is not providedvoid close()
If the component holds an ExecutorService, this method will typically
call ExecutorService.shutdown().
close in interface AutoCloseableCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.