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

# Data model

> The framework database tables (MarkToFuture, SimulationDates, CollateralAgreements, MasterAgreements, IndependentAmounts, FxScenarios), their fields, and joins.

The netting-set analytics framework defines a set of database tables that hold the exposure simulation data. These tables are specific to the framework and extend the universal common tables shared across all solutions.

For the other universal common tables (CounterpartyAttributes, OrganizationAttributes, and others), see the [common data model](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/common/developer-guide/database/database-model.md). This page documents the framework-specific tables and `TradeAttributes` in full, with base fields and framework-added fields listed together and the framework additions marked.

## What tables does the framework define?

The following tables are defined by the netting-set analytics framework.

| Table | Key fields | Description |
| - | - | - |
| [`MarkToFuture`](#marktofuture) | `AsOfDate`, `TradeId`, `TimePoint` | The facts table. Holds the MtF scenario vector for each trade at each future time point. |
| [`SimulationDates`](#simulationdates) | `AsOfDate`, `TimePoint` | The set of valid future simulation dates for a given as-of date, and whether each date is a reporting date or a collateral evaluation date. |
| [`CollateralAgreements`](#collateralagreements) | `AsOfDate`, `CSAId` | Collateral terms of each CSA. |
| [`MasterAgreements`](#masteragreements) | `AsOfDate`, `MasterAgreementId` | The master agreements (netting sets) and whether each one nets. |
| [`IndependentAmounts`](#independentamounts) | `AsOfDate`, `TradeId`, `CSAId` | Per-trade independent amount obligations for trades subject to initial margin. |
| [`FxScenarios`](#fxscenarios) | `AsOfDate`, `MarketDataSet`, `BaseCcy`, `CounterCcy`, `TimePoint` | FX rate scenario vectors used to convert the MtF vectors and the collateral between currencies. |

## What are the field definitions?

### MarkToFuture

The facts table. Each row holds the MtF simulation vector for one trade at one future time point, and the currency of that vector.

| Field | Type | Key | Notes |
| - | - | - | - |
| `AsOfDate` | `LocalDate` | Yes | Business date of the record. |
| `TradeId` | `String` | Yes | Unique trade identifier. |
| `TimePoint` | `LocalDate` | Yes | Future simulation date. |
| `Currency` | `String` | No | Currency of the row's MtF vector. A file without the `Currency` column gets the cube's base currency, which is the `default-currency` property of the cube's `currencies` properties (`EUR` by default). Cubes that share the table must have the same base currency, or the application fails to start. The XVA and PFE cubes convert the vector from this currency to the display currency. It is distinct from `NotionalCurrency` in `TradeAttributes`, the currency of the notional. |
| `MarkToFutureVector` | `double[]` | No | MtF scenario values. The vector length equals the `scenariosCount` value configured on the consuming cube. A blank value loads as a null vector, read as a zero vector. |

All non-blank vectors must use the same length. The vector length is set at startup and must match the consuming cube's scenarios count configuration.

A blank vector field loads a row with a null vector, which is read as a zero vector: the trade is present at that time point with a zero MtM, and the row takes no vector storage. A missing row means the trade is absent at that time point. For the gross and netted exposure, and for their incremental contributions, a blank vector and a missing row give the same values. For the collateralized exposure they can differ: the blank row still counts the trade as a contributor of its CSA at that time point, and toward the latest maturity of the CSA. When another trade of the CSA is left out, as in the incremental contributions, a CSA whose remaining trades are blank at that time point is still present with a zero MtM, and its collateral (the initial collateral, the independent amounts and the balance at t - MPOR) still produces exposure. When those rows are missing, the CSA has no exposure without that trade. To have a trade not count at a time point, such as for the time points after its maturity date, leave its row out instead of loading a blank vector. In a `NON EMPTY` query, cells with a zero vector appear as rows of zeros, while missing rows do not appear.

> [!NOTE]
>
> The collateral balance of a netting set is empty at every time point after the latest `TradeMaturityDate` of its trades, so the collateralized exposure is empty there too. When every trade has a `TradeMaturityDate`, the collateral results are the same whether or not the rows after maturity are loaded. For a trade without a `TradeMaturityDate`, the collateral results of its netting set depend on whether those rows are loaded.

The table is partitioned on `AsOfDate` and `TradeId`. To change this partitioning, see Partitioning and aggregate providers in the [PFE cube](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/solutions/counterparty-credit-risk/pfe/developer-guide/partitioning.md) or the [XVA cube](../../../../solutions/xva/xva/developer-guide/partitioning).

### SimulationDates

Defines the set of future time points available in the simulation grid for a given as-of date. Each time point is designated as a reporting date or a collateral evaluation date by the `ReportingOrCollateral` field. When the look-back date falls on a time point, reporting or collateral evaluation, the collateral algorithms read that time point. Otherwise they interpolate between the neighbouring reporting time points. The first reporting time point of each as-of date must be the as-of date itself: the collateral algorithms use the initial collateral when the look-back date is before the first reporting time point. A blank `ReportingOrCollateral` does not default to `R`: the time point counts as a collateral evaluation date only.

| Field | Type | Key | Notes |
| - | - | - | - |
| `AsOfDate` | `LocalDate` | Yes | Business date. |
| `TimePoint` | `LocalDate` | Yes | A future simulation date in the grid. |
| `ReportingOrCollateral` | `ReportingOrCollateral` | No | Whether the date is a reporting date (`R`) or a collateral evaluation date (`C`). See [Enums](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/reference/enums.md). |

### CollateralAgreements

Holds the collateral terms of each credit support annex (CSA). One row describes one CSA. A CSA belongs to exactly one master agreement, named in the `MasterAgreementId` field. The collateral balance calculation reads these parameters per CSA.

| Field | Type | Key | Default | Notes |
| - | - | - | - | - |
| `AsOfDate` | `LocalDate` | Yes | | Business date. |
| `CSAId` | `String` | Yes | `N/A` | Unique CSA identifier. The value `N/A` is the system default for trades without a CSA. |
| `MasterAgreementId` | `String` | No | | Master agreement that holds the CSA. Mandatory. It must be the `MasterAgreementId` of every trade of the CSA in `TradeAttributes`. This is not checked: the cube groups trades by their own `MasterAgreementId`, so a CSA whose trades name different master agreements gets a separate collateral balance in each. |
| `CSAName` | `String` | No | | Human-readable name. |
| `InitialCollateral` | `Double` | No | | Initial collateral balance, used when the margin-period-of-risk look-back date is before the business date. |
| `BankThreshold` | `Double` | No | | Exposure threshold above which the bank must post collateral to the counterparty. |
| `BankMinimumTransferAmount` | `Double` | No | | Minimum amount below which no collateral transfer to the counterparty is called. |
| `BankMPOR` | `Integer` | No | `20` | Margin period of risk for the bank side, in days. |
| `BankIndependentAmountConstant` | `Double` | No | | Fixed independent amount posted by the bank. |
| `BankIndependentAmountScaleFactor` | `Double` | No | | Scale factor applied to the bank independent amount. |
| `BankIndependentAmountFloor` | `Double` | No | | Floor on the bank independent amount. |
| `BankRounding` | `Double` | No | | Bank side rounding value. Loaded, but not yet passed to the collateral algorithms: `getBankRounding()` returns `0`. |
| `CounterpartyThreshold` | `Double` | No | | Exposure threshold above which the counterparty must post collateral to the bank. |
| `CounterpartyMinimumTransferAmount` | `Double` | No | | Minimum amount below which no collateral transfer to the bank is called. |
| `CptyMPOR` | `Integer` | No | `20` | Margin period of risk for the counterparty side, in days. |
| `CptyIndependentAmountConstant` | `Double` | No | | Fixed independent amount posted by the counterparty. |
| `CptyIndependentAmountScaleFactor` | `Double` | No | | Scale factor applied to the counterparty independent amount. |
| `CptyIndependentAmountFloor` | `Double` | No | | Floor on the counterparty independent amount. |
| `CptyRounding` | `Double` | No | | Counterparty side rounding value. Loaded, but not yet passed to the collateral algorithms: `getCptyRounding()` returns `0`. |
| `HaircutScaleFactor` | `Double` | No | `1.0` | Haircut applied to the value of the posted collateral. The built-in collateral algorithms do not read it. |
| `CSAParamCurrency` | `String` | No | `USD` | Currency of the CSA threshold and MTA parameters. |

Additional CSA parameters declared in the `additional-csa-parameters` configuration property add fields to this table. See [How to add custom CSA parameters](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/developer-guide/cube/exposure-measures.md#how-to-add-custom-csa-parameters).

### MasterAgreements

Holds one row per master agreement. A master agreement is the netting set: close-out netting and the zero floor on the exposure apply per master agreement. A master agreement holds any number of CSAs, plus trades that have no CSA.

| Field | Type | Key | Default | Notes |
| - | - | - | - | - |
| `AsOfDate` | `LocalDate` | Yes | | Business date. |
| `MasterAgreementId` | `String` | Yes | | Unique master agreement identifier. |
| `MasterAgreementName` | `String` | No | | Human-readable name. |
| `MasterAgreementType` | `String` | No | | Type of the agreement, for example ISDA. |
| `Netted` | `Boolean` | No | `false` | Whether the trades of the master agreement net against each other. When `false`, each trade counts on its own. |

### IndependentAmounts

Holds per-trade independent amount obligations. Trades subject to initial margin requirements have one or more rows in this table, one per CSA membership. The framework declares no topic or channel for this table: it stays empty unless the application loads it.

| Field | Type | Key | Notes |
| - | - | - | - |
| `AsOfDate` | `LocalDate` | Yes | Business date. |
| `TradeId` | `String` | Yes | Trade identifier. |
| `CSAId` | `String` | Yes | CSA to which this independent amount belongs. |
| `IndependentAmount` | `Double` | No | The independent amount value. |
| `IndependentAmountMaturity` | `LocalDate` | No | Maturity date of the independent amount obligation. |
| `IndependentAmountCurrency` | `String` | No | Currency of the independent amount. |

### FxScenarios

Holds FX rate scenario vectors used to convert the MtF vectors from their MTF currency to the display currency, and the collateral between the display currency and the CSA parameter currency. The table is the FX rate table of the market data library, with a vector of rates per key and the time point as an extra key.

| Field | Type | Key | Notes |
| - | - | - | - |
| `AsOfDate` | `LocalDate` | Yes | Business date. |
| `MarketDataSet` | `String` | Yes | Market data set of the rates. Rows loaded without a value take the default market data set of the cube, `Official EOD` by default. Cubes that share the table must have the same default market data set, or the application fails to start. |
| `BaseCcy` | `String` | Yes | Currency that the rates convert from. |
| `CounterCcy` | `String` | Yes | Currency that the rates convert to. |
| `TimePoint` | `LocalDate` | Yes | Future simulation date. |
| `Quote` | `double[]` | No | FX rate vector across scenarios. The vector length must match `scenariosCount`. |

### TradeAttributes

`TradeAttributes` is a universal common table that the framework extends. Rows in the Customization column marked with `✓` are added by the framework; the rest are base fields from the common layer.

| Field | Type | Key | Customization | Notes |
| - | - | - | - | - |
| `AsOfDate` | `LocalDate` | Yes | | Business date of the record. |
| `TradeId` | `String` | Yes | | Unique trade identifier. |
| `Trader` | `String` | No | | Name of the trader responsible for the trade. |
| `Sales` | `String` | No | | Name of the sales person associated with the trade. |
| `TradeDate` | `LocalDate` | No | | Date the trade was booked. |
| `TradeMaturityDate` | `LocalDate` | No | | Maturity date of the trade. When blank, the collateral balance of the trade's netting set continues to the last time point. |
| `CounterpartyId` | `String` | No | | Foreign key to `CounterpartyAttributes`. |
| `OrganizationUnitId` | `String` | No | | Foreign key to `OrganizationAttributes`. |
| `BookId` | `String` | No | | Foreign key to `BookAttributes`. Inherited from the common `TradeAttributes` table. |
| `Notional` | `Double` | No | ✓ | Trade notional. |
| `NotionalCurrency` | `String` | No | ✓ | Currency of the notional. |
| `AssetClass` | `String` | No | ✓ | Asset class of the instrument. |
| `InstrumentType` | `String` | No | ✓ | Instrument type. |
| `InstrumentSubType` | `String` | No | ✓ | Instrument subtype. |
| `CSAId` | `String` | No | ✓ | CSA of the trade. Defaults to `N/A` for trades without a CSA. A CSA without a `CollateralAgreements` row on the trade's as-of date holds no collateral. |
| `MasterAgreementId` | `String` | No | ✓ | Foreign key to `MasterAgreements`. Mandatory. A trade whose master agreement has no `MasterAgreements` row on its as-of date is in the `N/A` master agreement. This is not checked: if its CSA has a `CollateralAgreements` row, its collateral is pooled with that of every other CSA in `N/A`, across counterparties. |
| `BreakDate` | `LocalDate` | No | ✓ | Optional trade termination date for break-date-aware exposure aggregation. Nullable. |

The framework adds the fields marked in the Customization column.

For the full common reference, see [TradeAttributes](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/common/reference/tables.md#tradeattributes) and the [common data model](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/common/developer-guide/database/database-model.md).

> The framework also adds a `Counterparty` object field to `CounterpartyAttributes`.

## How are the tables joined?

| From table | To table | Join fields |
| - | - | - |
| `MarkToFuture` | `TradeAttributes` | `AsOfDate`, `TradeId` |
| `MarkToFuture` | `SimulationDates` | `AsOfDate`, `TimePoint` |
| `TradeAttributes` | `MasterAgreements` | `AsOfDate`, `MasterAgreementId` |
| `TradeAttributes` | `IndependentAmounts` | `AsOfDate`, `TradeId`, `CSAId` |

`FxScenarios` is not joined to other tables via a database reference. The FX Rate measure reads it at query time to convert the MtF vectors. The collateral algorithms use the rates loaded in `FxScenarios` too. Both use the market data set selected in the query, or the default market data set when none is selected. A pair of identical currencies needs no row, and a missing pair is derived from its inverse or through the default currency.

## Related pages

* [Common data model](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/common/developer-guide/database/database-model.md)
* [How to customize the data model](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/common/developer-guide/database/customizing-data-model.md)
* [Dimensions](https://docs.activeviam.com/solutions/enterprise-risk-suite/1.1/libs/netting-set-analytics/developer-guide/cube/dimensions.md)
