Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt

Use this file to discover all available pages before exploring further.

The Market Risk Application supports cube-level, fact-level, and roll-over adjustments for the Sensitivities, PnL, and VaR-ES cubes. As an example of how to configure a new custom adjustment, this page explains how PNL adjustments have been defined within the mr-application module in the mr-application/src/main/java/com/activeviam/mr/application/signoff/adjustments/ directory.
PNL adjustments are scalar adjustments.

Configure Adjustment Execution

All adjustment processes are defined within the AdjustmentExecutionConfig.java class. Other library classes are mentioned where relevant.

Fact-level adjustments

Fact-level adjustments are modifications of the underlying data held in the datastore. They operate directly on datastore rows, using Execution objects containing functional components. These functional components are defined in the ExecutionFunctionalComponents.java class.

The Execution object

FieldDescription
appliesOnAdjustmentsDetermines whether or not the current adjustment applies for rows created by a previous adjustment.
inputParserAn AdjustmentInputParser that takes the request and definition DTOs and matches the required definition inputs to the input provided in the request. The values of the request inputs are parsed using the IParser objects matching the type found in the definition.
inputRetrieverAn AdjustmentInputRetriever that takes a datastore row, the store format and a list of store fields and returns an object representing the value to be adjusted.
sourceTaggerA List of AdjustmentStoreTagger objects that take an execution ID and the initial values of the Source and Input type fields and return a map with the new values of those fields.
valueFieldThe datastore field that holds the values that will be adjusted by the execution.
expectedInputsThe List of expected inputs required by the execution.
inputConverterAn AdjustmentInputConverter that takes the result of the inputParser and the expectedInputs and generates the request inputs to be used in the adjustment steps.
stepsA list of AdjustmentStep objects that use the results of the inputRetriever and inputConverter to create the adjusted values that will be written to the datastore.
As PnL adjustments are scalar (i.e. a fact is a single value, as opposed to a vector), the scalar functions are used:
  • inputParser is parseInput()
  • inputRetriever is scalarInputRetriever() - given the base tuple, the store format and a list of fields, returns a double value held by the first field in the list
  • inputConverter is scalarInputConverter() - given a map of values and the expected input, returns a single double-typed value
For the PnL datastore:
  • valueField parameter is StoreFieldNames.DAILY
  • expectedInputs parameter only contains StoreFieldNames.DAILY

Add On Execution

  • appliesOnAdjustments is false
  • sourceTagger contains:
    • userInputSourceTagging() - tags the row as direct user input
  • steps contains:
    • doubleInputReplacer() - replaces the initial value with the request input value
    private final Execution<Double, Double, Double> pnlAddOnExecution = new Execution<>(
            false,
            executionFunctionalComponents.parseInput(),
            executionFunctionalComponents.scalarInputRetriever(),
            List.of(executionFunctionalComponents.userInputSourceTagging()),
            StoreFieldNames.DAILY,
            List.of(StoreFieldNames.DAILY),
            executionFunctionalComponents.scalarInputConverter(),
            List.of(executionFunctionalComponents.doubleInputReplacer())
    );

Scaling Execution

  • appliesOnAdjustments is true
  • sourceTagger contains:
    • inverseTagging() - tags a row as the inversion of the initial row
    • scaleTagging() - tags the row as a scaling of the initial row
  • steps contains:
    • doubleInverter() - the execution replaces the initial value with its inverse (initialValue * -1.0)
    • doubleScaler() - the execution replaces the initial value with the scaled value (initialValue * scalingFactor)
    private final Execution<Double, Double, Double> pnlScalingExecution = new Execution<>(
            true,
            executionFunctionalComponents.parseInput(),
            executionFunctionalComponents.scalarInputRetriever(),
            List.of(executionFunctionalComponents.inverseTagging(), executionFunctionalComponents.scaleTagging()),
            StoreFieldNames.DAILY,
            List.of(StoreFieldNames.DAILY),
            executionFunctionalComponents.scalarInputConverter(),
            List.of(executionFunctionalComponents.doubleInverter(), executionFunctionalComponents.doubleScaler())
    );

Override Execution

  • appliesOnAdjustments is true
  • sourceTagger contains:
    • inverseTagging() - tags a row as the inversion of the initial row
    • userInputSourceTagging() - tags the row as direct user input
  • steps contains:
    • doubleInverter() - the execution replaces the initial value with its inverse (initialValue * -1.0)
    • doubleInputReplacer() - replaces the initial value with the request input value
    private final Execution<Double, Double, Double> pnlOverrideExecution = new Execution<>(
            true,
            executionFunctionalComponents.parseInput(),
            executionFunctionalComponents.scalarInputRetriever(),
            List.of(executionFunctionalComponents.inverseTagging(), executionFunctionalComponents.userInputSourceTagging()),
            StoreFieldNames.DAILY,
            List.of(StoreFieldNames.DAILY),
            executionFunctionalComponents.scalarInputConverter(),
            List.of(executionFunctionalComponents.doubleInverter(), executionFunctionalComponents.doubleInputReplacer())
    );

Cube-level adjustments

Cube-level adjustments rely on the creation of facts added to the base store (and on entries added to stores referenced by the base store if needed) to define the location at which they are applied, and on entries in an isolated store to define the measures for which they are defined, along with the adjusted values. Only add-ons are supported for cube-level adjustments. The add-ons are aggregated using dynamic aggregation on the adjustment source field of the base store of the cube for which the adjustment is created. The notion of location digest has been removed from the logic used for cube-level adjustments. Cube-level adjustments work by submitting entries into:
  1. the CubeLevelAdjustments store to specify:
  • the ID of the entry, which corresponds to the value of the adjustment source field in the base store
  • the measure for which to provide an add-on value
  • the value used for the add-on
  • the currency in which that add-on value is expressed
  1. the base store (and if needed referenced stores) A fact is created in the base store of the cube for which a cube-level adjustment is created. The value of its adjustment source field corresponds to the id of the associated entry in the CubeLevelAdjustments store. If the cube-level adjustment is created for a level whose value comes form a store referenced by the base store, an entry is also created in the referenced store.
For instance, if the base store has the following entries:
AsOfDateTradeIdRiskFactorSensitivity NameSensitivity ValueSource
06/01/2025T001RF1Equity Delta1000.0Unadjusted
06/01/2025T001RF2Equity Delta2000.0Unadjusted
and the user John wants to create an add-on cube level adjustment in cube Cube1 of 3000.0 euros for the measure measure1 at the trade id level for T001 for the task Task1 , the following entry will be created in the base store:
AsOfDateTradeIdRiskFactorSensitivity NameSensitivity ValueSource
06/01/2025T001John_Task1_execution_id_001
and the following entry is added to the CubeLevelAdjustments store:
IdTaskIdAsOfDatePivotIdCurrencyMeasureValue
John_Task1_execution_id_001Task106/01/2025Cube1EURmeasure13000.0
If the base store references a TradeAttributes store with the foreign key defined by (AsOfDate, TradeId), and the base store has this content:
AsOfDateTradeIdRiskFactorSensitivity NameSensitivity ValueSource
06/01/2025T001RF1Equity Delta1000.0Unadjusted
06/01/2025T001RF2Equity Delta2000.0Unadjusted
06/01/2025T002RF3Equity Delta5000.0Unadjusted
06/01/2025T003RF4Equity Delta7000.0Unadjusted
and the TradeAttributes store this content:
AsOfDateTradeIdBook
06/01/2025T001BookA
06/01/2025T002BookA
06/01/2025T003BookB
and the user John wants to create an add-on cube level adjustment in cube Cube1 of 8000.0 euros for the measure measure1 at the book level for ‘BookA’ for the task Task2 , the following entry will be created in the base store:
AsOfDateTradeIdRiskFactorSensitivity NameSensitivity ValueSource
06/01/2025John_Task1_execution_id_002John_Task1_execution_id_002
The following entry will be added to the TradeAttributes store:
AsOfDateTradeIdBook
06/01/2025John_Task1_execution_id_002BookA
And the following entry will be added to the CubeLevelAdjustments store:
IdTaskIdAsOfDatePivotIdCurrencyMeasureValue
John_Task1_execution_id_002Task106/01/2025Cube1EURmeasure18000.0
The executor used for cube-level adjustments does not take any argument into account.

Roll-over adjustments

Roll-over adjustments operate on the datastore, replacing the rows corresponding to the current as-of date with the approved rows from the input as-of date. The executors use the rollOver() method with the following arguments:
ArgumentDescription
invertersA Map of inverter Function objects for the datastore fields that should be inverted by the roll-over.
inverseTaggingTagging TriFunction to generate the source and input tags for an inverted datastore row.
rollOverTaggingTagging TriFunction to generate the source and input tags for a rolled-over row.
For the PnL roll-over adjustment, the inverters are as follows:
    private final Map<String, AdjustmentConverterOperator> pnlInverters = Map.of(
            StoreFieldNames.DAILY, executionFunctionalComponents.inPlaceDoubleOrArrayInverter(),
            MONTHLY, executionFunctionalComponents.inPlaceDoubleOrArrayInverter(),
            YEARLY, executionFunctionalComponents.inPlaceDoubleOrArrayInverter(),
            LIFETIME, executionFunctionalComponents.inPlaceDoubleOrArrayInverter()
    );
The inPlaceDoubleOrArrayInverter() function returns input * 1.0 for double inputs and ((IVector) input).scale(-1.0) for IVector inputs.

Include Defined Executions in Executors Map

Now that we have defined our adjustment executions we need to add them to our executors Map which will be accessed by the services defined in the Sign-off API library. We want to include our executors in the bean with the qualifier SP_QUALIFIER__EXECUTORS Note that our executors are included in both profiles.
    @Bean
    @Qualifier(SP_QUALIFIER__EXECUTORS)
    public Map<String, AdjustmentExecutor> executors() {
        executionFunctionalComponentsConfig.getExecutionFunctionalComponents().setStatusService(statusService);
        Map<String, AdjustmentExecutor> executors = new HashMap<>();
		...
        executors.put(PNL_ADD_ON, execution(onBranch, pnlAddOnExecution));
        executors.put(PNL_OVERRIDE, execution(onBranch, pnlOverrideExecution));
        executors.put(PNL_SCALING, execution(onBranch, pnlScalingExecution));
        executors.put(PNL_ROLL_OVER, rollOver(
                pnlInverters,
                executionFunctionalComponents.inverseTagging(),
                executionFunctionalComponents.rollOverTagging()));
        executors.put(PNL_CUBE_LEVEL, cubeLevelAdjustment());
        ...
        return executors;
    }

Define required dimensions for sign-off adjustments

Navigate to AdjustmentPivotConfig.java We add SignOff Source Dimension to the appropriate schema in this case PnlSchema.
    @Bean
    @Qualifier("aPnlDimension")
    @Order(75)
    public HierarchyBuilderConsumer signOffPnlDimensionAdder() {
        return AdjustmentPivotConfig::getSignOffSourceDimension;
    }

Add source tagging fields

Navigate to SignOffDatastoreCustomisations
    public static void loadCustomisations(IDatastoreConfigurator configurator) {
	    ...
        addTagging(configurator, PnLDatastoreDescriptionConfig.SCHEMA, StoreNames.PNL_STORE_NAME);
        addTagging(configurator, PnLDatastoreDescriptionConfig.SCALAR_SCHEMA, StoreNames.PNL_STORE_NAME);
        addTaggingAfterField(configurator, PnLFlatDatastoreDescriptionConfig.SCHEMA, StoreNames.PNL_BASE_STORE, StoreFieldNames.INSTRUMENT_SUB_TYPE);
        addTaggingAfterField(configurator, PnLFlatDatastoreDescriptionConfig.SCALAR_SCHEMA, StoreNames.PNL_BASE_STORE, StoreFieldNames.INSTRUMENT_SUB_TYPE);
        addTaggingAfterField(configurator, PnLAggregatedDatastoreDescriptionConfig.SCHEMA, StoreNames.PNL_BASE_STORE, StoreFieldNames.INSTRUMENT_SUB_TYPE);
        addTaggingAfterField(configurator, PnLAggregatedDatastoreDescriptionConfig.SCALAR_SCHEMA, StoreNames.PNL_BASE_STORE, StoreFieldNames.INSTRUMENT_SUB_TYPE);
        ...
    }

Define supported Adjustment

Navigate to SupportedAdjustmentsConfig Define a SupportedAdjustmentDTO bean.

Add-on

    @Bean
    public SupportedAdjustmentDTO pnlAddOn() {
        return new SupportedAdjustmentDTO(
                ADD_ON_NAME,
                PNL_ADD_ON,
                true,
                PnLCubeConfig.CUBE_NAME,
                Set.of(StoreNames.PNL_STORE_NAME),
                Set.of(
                        new TypedFieldDTO(AS_OF_LEVEL, StoreFieldNames.AS_OF_DATE, LOCAL_DATE),
                        new TypedFieldDTO(TRADE_LEVEL, StoreFieldNames.TRADE_ID, STRING),
                        new TypedFieldDTO(TYPE_LEVEL, StoreFieldNames.TYPE, STRING),
                        new TypedFieldDTO(RISK_FACTOR_LEVEL, StoreFieldNames.RISK_FACTOR, STRING),
                        new TypedFieldDTO(CURRENCY_LEVEL, StoreFieldNames.VALUE_CCY, STRING)
                ),
                Set.of(DTD_PNL_NATIVE),
                Set.of(new TypedFieldDTO(StoreFieldNames.DAILY, DOUBLE))
        );
    }

Scaling

    @Bean
    public SupportedAdjustmentDTO pnlScaling() {
        return new SupportedAdjustmentDTO(
                SCALING_NAME,
                PNL_SCALING,
                true,
                PnlCubeConfig.CUBE_NAME,
                Set.of(StoreNames.PNL_STORE_NAME),
                Set.of(
                        new TypedFieldDTO(AS_OF_LEVEL, StoreFieldNames.AS_OF_DATE, LOCAL_DATE),
                        new TypedFieldDTO(TRADE_LEVEL, StoreFieldNames.TRADE_ID, STRING),
                        new TypedFieldDTO(TYPE_LEVEL, StoreFieldNames.TYPE, STRING),
                        new TypedFieldDTO(RISK_FACTOR_LEVEL, StoreFieldNames.RISK_FACTOR, STRING),
                        new TypedFieldDTO(CURRENCY_LEVEL, StoreFieldNames.VALUE_CCY, STRING)
                ),
                Set.of(DTD_PNL_NATIVE),
                Set.of(new TypedFieldDTO(StoreFieldNames.DAILY, DOUBLE))
        );
    }

Override

    @Bean
    public SupportedAdjustmentDTO pnlOverride() {
        return new SupportedAdjustmentDTO(
                OVERRIDE_NAME,
                PNL_OVERRIDE,
                true,
                PnlCubeConfig.CUBE_NAME,
                Set.of(StoreNames.PNL_STORE_NAME),
                Set.of(
                        new TypedFieldDTO(AS_OF_LEVEL, StoreFieldNames.AS_OF_DATE, LOCAL_DATE),
                        new TypedFieldDTO(TRADE_LEVEL, StoreFieldNames.TRADE_ID, STRING),
                        new TypedFieldDTO(TYPE_LEVEL, StoreFieldNames.TYPE, STRING),
                        new TypedFieldDTO(RISK_FACTOR_LEVEL, StoreFieldNames.RISK_FACTOR, STRING),
                        new TypedFieldDTO(CURRENCY_LEVEL, StoreFieldNames.VALUE_CCY, STRING)
                ),
                Set.of(DTD_PNL_NATIVE),
                Set.of(new TypedFieldDTO(StoreFieldNames.DAILY, DOUBLE))
        );
    }

Roll-over

    @Bean
    public SupportedAdjustmentDTO pnlRollOver() {
        return new SupportedAdjustmentDTO(
                ROLL_OVER_NAME,
                PNL_ROLL_OVER,
                false,
                PnlCubeConfig.CUBE_NAME,
                Set.of(StoreNames.PNL_STORE_NAME),
                Set.of(
                        new TypedFieldDTO(AS_OF_LEVEL, StoreFieldNames.AS_OF_DATE, LOCAL_DATE),
                        new TypedFieldDTO(DESK_LEVEL, StoreFieldNames.DESK, STRING),
                        new TypedFieldDTO(BOOK_LEVEL, StoreFieldNames.BOOK, STRING, true),
                        new TypedFieldDTO(TRADE_LEVEL, StoreFieldNames.TRADE_ID, STRING, true),
                        new TypedFieldDTO(SIGNOFF_STATUS_LEVEL, ADJUSTMENT_LEVEL_STATUS, LEVEL_PATH, true),
                        new TypedFieldDTO(SIGNOFF_TASK_LEVEL, ADJUSTMENT_LEVEL_TASK, LEVEL_PATH, true),
                        new TypedFieldDTO(SIGNOFF_SOURCE_LEVEL, SOURCE_FIELD, LEVEL_PATH, true),
                        new TypedFieldDTO(SIGNOFF_INPUT_TYPE_LEVEL, INPUT_FIELD, LEVEL_PATH, true)
                ),
                null,
                Set.of(new TypedFieldDTO(StoreFieldNames.AS_OF_DATE, LOCAL_DATE))
        );
    }

Cube-level

    @Bean
    public SupportedAdjustmentDTO pnlCubeLevelAdjustment() {
        return new SupportedAdjustmentDTO(
                CUBE_LEVEL_NAME,
                PNL_CUBE_LEVEL,
                false,
                PnlCubeConfig.CUBE_NAME,
                null,
                Set.of(
                        new TypedFieldDTO(AS_OF_LEVEL, StoreFieldNames.AS_OF_DATE, LEVEL_PATH),
                        new TypedFieldDTO(DESK_LEVEL, StoreFieldNames.DESK, LEVEL_PATH),
                        new TypedFieldDTO(BOOK_LEVEL, StoreFieldNames.BOOK, LEVEL_PATH, true),
                        new TypedFieldDTO(TRADE_LEVEL, StoreFieldNames.TRADE_ID, LEVEL_PATH, true),
                        new TypedFieldDTO(SIGNOFF_STATUS_LEVEL, ADJUSTMENT_LEVEL_STATUS, LEVEL_PATH, true),
                        new TypedFieldDTO(SIGNOFF_TASK_LEVEL, ADJUSTMENT_LEVEL_TASK, LEVEL_PATH, true),
                        new TypedFieldDTO(SIGNOFF_SOURCE_LEVEL, SOURCE_FIELD, LEVEL_PATH, true),
                        new TypedFieldDTO(SIGNOFF_INPUT_TYPE_LEVEL, INPUT_FIELD, LEVEL_PATH, true)
                ),
                null,
                Set.of( new TypedFieldDTO(CURRENCY, STRING),
                        new TypedFieldDTO(StoreFieldNames.SENSITIVITY_VALUES, DOUBLE))
        );
    }