> ## 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.

# Measures

> Reference for the common and netting-set-analytics measure factories, their plugin keys, and how to override a factory implementation.

This page lists the measure factories provided by the common layer. Each factory is identified by a plugin key. Registering a custom factory under the same plugin key for the cube replaces the default implementation. See [How to override a factory](#how-to-override-a-factory).

For solution-specific measure factories, see the reference documentation for each solution.

## Common core factories

These factories are provided by the common layer.

| Plugin key | Description |
| - | - |
| `NamedMeasure` | Wraps an existing named measure as a factory input, allowing it to be referenced and composed by other factories. |
| `LastIndex` | Extracts the last value from a numerical vector, with an optional absolute-value transformation. |
| `ParentValue` | Creates a parent value measure with drill-up and location shift post-processors, optionally honoring query filters on the drilled hierarchy. Used as a building block for inframarginal and incremental-contribution calculations. |
| `LinearInframarginal` | Computes the linear inframarginal value as `parentValue(underlying) - underlying` for a given marginal level, with a parent value that honors query filters. |
| `ScenarioExpansion` | Expands a scenario vector into individual scenario rows and extracts scenario-specific values. |

## Netting set analytics factories

These factories are provided by [Netting Set Analytics](/solutions/enterprise-risk-suite/1.0/libs/netting-set-analytics/introduction/overview.md). They are used by solutions that perform exposure and counterparty-level calculations.

### Exposure metrics

| Plugin key | Description |
| - | - |
| `ExpectedExposure` | Calculates expected exposure (EE) by averaging scenario exposures with optional discounting. |
| `ExpectedNegativeExposure` | Calculates expected negative exposure (ENE), counting only negative exposures. |
| `ExpectedShortfall` | Computes expected shortfall (ES) from exposure vectors at a given confidence level. |
| `PotentialFutureExposure` | Creates potential future exposure (PFE) measures at a given confidence level. |
| `PFEIndex` | Extracts the scenario index corresponding to the PFE percentile. |
| `PFEScenarioName` | Generates the scenario name for the PFE scenario index. |

### Inframarginal

| Plugin key | Description |
| - | - |
| `NettedInframarginal` | Computes the netted inframarginal value of a trade within a netting set. |
| `NonLinearInframarginal` | Calculates the non-linear inframarginal value by re-aggregating the parent excluding the current trade. |

Incremental contribution measures are not factory-based: they are defined directly with the Atoti Configuration API as `parent - inframarginal`.

### Exposure

| Plugin key | Description |
| - | - |
| `NettedExposure` | Computes netted exposure at the netting set level. |

## How to override a factory

To replace a built-in factory, register a new `IMeasureFactory` implementation with the same plugin key for the cube, by exposing a `MeasureFactoryRegistration` Spring bean. Each cube registers its built-in factories for itself, and a factory registered for a cube takes precedence over a global one, so the replacement must be registered for the cube too. The solution registers its built-in factories before any `MeasureFactoryRegistration` bean, so the application's factory always replaces the built-in one. Two application beans registering the same key for the same cube replace each other in bean registration order. Because the factory is instantiated by Spring, it can depend on other Spring-managed objects.

The following example overrides the `LastIndex` factory with a custom implementation that returns null for an empty vector:

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
public static class CustomLastIndexFactory implements IMeasureFactory<LastIndexMeasureInput> {
  @Override
  public CopperMeasure create(
      final LastIndexMeasureInput input, final IMeasureFactoryContext context) {
    return context
        .createMeasure(input.vectorMeasure())
        .map(
            (reader, writer) -> {
              final var vector = reader.isNull(0) ? null : reader.readVector(0);
              if (vector == null || vector.size() == 0) {
                writer.writeNull();
              } else {
                final var value = vector.readDouble(vector.size() - 1);
                writer.writeDouble(input.absolute() ? Math.abs(value) : value);
              }
            },
            ILiteralType.DOUBLE);
  }
  @Override
  public String key() {
    return LastIndexMeasureInput.KEY;
  }
}
```

To register it, expose a `MeasureFactoryRegistration` bean. Its first argument holds the factories to register globally, and the map holds the factories to register for each cube, keyed by cube name:

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
private static final String CUBE_NAME = "VaR";
@Bean
MeasureFactoryRegistration customFactories() {
  return new MeasureFactoryRegistration(
      List.of(), Map.of(CUBE_NAME, List.of(new CustomLastIndexFactory())));
}
```

## Related pages

* [Measures developer guide](/solutions/enterprise-risk-suite/1.0/common/developer-guide/cube/measures.md)
* [Atoti Configuration API: Measures reference](/solutions/enterprise-risk-suite/1.0/foundry/cube/measures.md)
* [Configuration properties](/solutions/enterprise-risk-suite/1.0/common/reference/configuration-properties.md)
