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 stratapricer 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 threadpool, thus care should be taken to ensure the threadpool is correctly managed. For example, trywithresources could be used:
try (CalculationRunner runner = CalculationRunner.ofMultiThreaded()) { // use the runner }


Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method 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 multithreaded calculation runner capable of performing calculations.



Method Detail

ofMultiThreaded
static CalculationRunner ofMultiThreaded()
Creates a standard multithreaded 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 trywithresources 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 lifecycle 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 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 columnspecific overridesmarketData
 the market data to be used in the calculationsrefData
 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 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 columnspecific 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 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 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 columnspecific overridesmarketData
 the market data to be used in the calculationsrefData
 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 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 columnspecific 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 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 lowerlevel 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

close
void close()
Closes any resources held by the component.If the component holds an
ExecutorService
, this method will typically callExecutorService.shutdown()
. Specified by:
close
in interfaceAutoCloseable

