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

# Cashflow measures

> How an application supplies projected cashflows to the PFE and xVA cubes, which cashflow measures read them, and why they do not change any exposure measure.

Cashflow measures represent the projected future cashflows of trades at each time point. The application supplies the cashflows through an `ICashflowsService`. This page describes the service, the measures that read it, and how to register it.

Understanding [exposure measures](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/developer-guide/cube/exposure-measures.md) is a prerequisite for this page.

## What is a projected cashflow?

A projected cashflow is a payment that a trade is expected to make or receive at a time point. The service returns one value per scenario for each trade and time point.

## Which measures read the cashflows?

The `SimulatedCashflow` measure (plugin key: `SimulatedCashflow`) calls the service for each trade and time point. It backs the hidden `Gross Cumulative Cashflow` and `Gross With Break Dates Cumulative Cashflow` measures, which two visible measures expand:

* `Gross Cumulative Cashflow (Scenario Level)`, which shows the cashflow of each scenario along the Scenarios dimension.
* `Gross With Break Dates Cumulative Cashflow (Scenario Level)`, the same measure for the gross with break dates family, which keeps only the time points before the break date of each trade.

The accessors are `cumulativeCashflow()` and `cumulativeCashflowScenarioLevel()` on the base gross exposure measures.

No gross, netted, or collateralized exposure formula reads the cashflows. Supplying cashflows does not change any exposure.

The service returns the cashflows in the trade's MTF currency, and the measure converts them to the display currency with the FX rates that convert the MtF vectors. The measure has values at the Trade ID level only. It is empty above the trade level, because the per-trade values are not aggregated upward. At the trade level, it accumulates the values that the service returns for each time point over the time points. The service returns the cashflow at each time point, not a running total.

## What happens when no service is supplied?

The cube uses a service that returns zero for every trade and time point, so the cumulative cashflow measures are zero at the Trade ID level.

## How to supply projected cashflows

The application implements `ICashflowsService` and registers it with `ICollateralCubeConfigurator.cashflows(...)`, which it gets from `ICollateralConfigurator.cube(...)` inside its `ICollateralConfigurer` bean. The method `getCashFlow(asOfDate, tradeId, timePoint)` returns one value per scenario, or null when the trade has no cashflow at that time point. The service does not need to be serializable.

The following class is an `ICashflowsService` that returns a scheduled amount for a trade and time point, and zero otherwise. It returns the same amount in every scenario. A source that depends on the scenario returns one value per scenario.

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
public final class ScheduledCashflows implements ICashflowsService {
  private final int scenarioCount;
  private final Map<String, Map<LocalDate, Double>> amountsByTrade;
  public ScheduledCashflows(
      final int scenarioCount, final Map<String, Map<LocalDate, Double>> amountsByTrade) {
    this.scenarioCount = scenarioCount;
    this.amountsByTrade = amountsByTrade;
  }
  // The same amount in every scenario; a scenario-dependent source returns one value per scenario.
  @Override
  public IVector getCashFlow(
      final LocalDate asOfDate, final String tradeId, final LocalDate timePoint) {
    final double amount =
        amountsByTrade.getOrDefault(tradeId, Map.of()).getOrDefault(timePoint, 0d);
    return SameValueVectorUtils.doubleVector(scenarioCount, amount);
  }
}
```

The service is built from `ICollateralServices`. Its `scenarioCount()` is the length that every vector must have. The following configurer registers the service. The same bean also adds a collateral algorithm, as described in [How to write your own collateral algorithm](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/developer-guide/cube/custom-collateral-algorithm.md).

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
@Configuration(proxyBeanMethods = false)
class CollateralCustomizationSnippetExample {
  @Bean
  static ICollateralConfigurer collateralConfigurer(final IPfeCubeProperties pfeProperties) {
    return configurator ->
        configurator
            .cube(pfeProperties.getName())
            .addEvaluator(new ThresholdCsaEvaluator())
            .cashflows(
                services ->
                    new ScheduledCashflows(
                        services.scenarioCount(),
                        Map.of("TRADE-1", Map.of(LocalDate.of(2025, Month.JANUARY, 31), 12_500d))));
  }
}
```

The service applies to the cube named in `cube(...)`. A later call to `cashflows(...)` for the same cube replaces an earlier one.

## Related pages

* [Exposure measures](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/developer-guide/cube/exposure-measures.md)
* [How to write your own collateral algorithm](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/developer-guide/cube/custom-collateral-algorithm.md)
* [Services](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/developer-guide/services.md)
