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

# Overrides with DirectQuery

> Guide to defining parameter set overrides in Atoti FRTB when using DirectQuery, including the required database table modifications

This section explains how to define overrides in Atoti FRTB using DirectQuery and also how to modify the relevant database tables.

Overrides allow for shifting data for a specific parameter set into a specific location.

There are two steps to defining overrides with DirectQuery:

1. Define the override in the override table.
2. Add the new override members to the base table.

## Step 1: Define override in the override Table

Simply add a row in the override table.

## Step 2: Add the new override member to the Base Table

Next, add data into the override table's base table. Details are in the ***Override Base Table*** section for each
override table in the [Database](../../../database/standardisedapproach/overrides/index) chapter.

Ensure the following:

* ***shift members*** exist in the base table, otherwise Atoti will not be able to shift the data as it cannot see the *shift member* of the
  ***shift member***'s hierarchy.

* The ***OVERRIDE KEY FIELD*** field of the base table is populated with a custom string in the format: "**`memberToShift::memberValue`**".\
  The ***memberToShift*** and ***memberValue*** come from the override's definition.

## Example

This example is based on the reference override defined in the input file:
`sample-data/data/2018-09-28/Sensitivities/samples/Underlying_Desc_Overrides.csv`

This example performs the following steps:

1. Define the override.
2. Populate the [Underlying Description Overrides](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md) table.
3. Populate the override base [Underlying Description](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description.md) table.

### Define the override

This simple example shifts the **"Carbon Emissions Trading"** *Underlying* of the **"Commodity"** *RiskClass* into *Bucket* **"3a"** for the **"CRR3"**
*Parameter Set*.

The desired override is thus as follows:

| Underlying | Risk Class | ParameterSet | Bucket |
| - | - | - | - |
| Carbon Emissions Trading | Commodity | CRR3 | 3a |

### Populate the override table

Start by defining the override in the appropriate override table. For this example, the override is defined in the
[Underlying Description Override](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md) table. An *AsOfDate* that the override is
effective for must also be defined. This example uses an *AsOfDate* of *`"2018-09-28"`* (the latest date in the provided reference data).

The table contains the following data (table is transposed for readability due to the large number of columns):

| Underlying Description Overrides Field | Not Null | Value |
| - | - | - |
| **UNDERLYING** | Yes | Carbon Emissions Trading |
| **RISK\_CLASS** | Yes | Commodity |
| **PARAMETER\_SET** | Yes | CRR3 |
| **BUCKET** | | 3a |
| **CSRQUALITY** | | |
| **CSRSECTOR** | | |
| **CSRRATING** | | |
| **EQUITY\_MARKET\_CAP** | | |
| **EQUITY\_ECONOMY** | | |
| **EQUITY\_SECTOR** | | |
| **POOL** | | |
| **ATTACHMENT** | | |
| **DETACHMENT** | | |
| **AS\_OF\_DATE** | Yes | 2018-09-28 |

### Populate the override base table

Next, inject some data into the override table's base table. The base table can be found in the
[Override Base Table](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md#override-base-table) section for the Underlying Description Overrides.\
The base table is the [Underlying Description](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description.md) table.

The members to shift the override into have to exist in the base table, otherwise Atoti will not be able to shift the data.
Atoti can be made aware of the new member by adding the new member to the base table.

An entry must be generated in the [Underlying Description](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description.md) table in the following sequence:

* Define the [Override Parameters](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md#override-parameters) fields from the base store.
* Create the [Override Tuples](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md#create-base-store-tuples).
* Map the override tuples back to the base table using the [Override Fields to Base Table Fields Mapping](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md#map-override-fields-to-base-table-fields).

#### Define override parameters base table fields

For Underlying Description overrides, the parameter fields can be found in
[Override Parameters](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md#override-parameters):

| Override Parameter | **Underlying Description** Field |
| - | - |
| **OVERRIDE KEY FIELD** | **UNDERLYING** |
| **OVERRIDE DATE FIELD** | **AS\_OF\_DATE** |

#### Create the override tuples

The [Create Base Store Tuples](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md#create-base-store-tuples)
section shows that the following fields are the override's fields to create tuples for:

| Underlying Description Override Field |
| - |
| **PARAMETER\_SET** |
| **BUCKET** |
| **CSRQUALITY** |
| **CSRSECTOR** |
| **CSRRATING** |
| **EQUITY\_MARKET\_CAP** |
| **EQUITY\_ECONOMY** |
| **EQUITY\_SECTOR** |
| **POOL** |
| **ATTACHMENT** |
| **DETACHMENT** |

The override tuples can be defined by going through each field in the override definition:

| Field | Tuple to generate |
| - | - |
| UNDERLYING RISK\_CLASS  | These do not exist in the Underlying Description override Fields, so we can skip them. |
| [PARAMETER\_SET](#parameter_set) | See below. |
| [BUCKET](#bucket) | See below. |
| CSRQUALITY CSRSECTOR CSRRATING EQUITY\_MARKET\_CAP EQUITY\_ECONOMY EQUITY\_SECTOR POOL ATTACHMENT DETACHMENT | These are not defined, so we can skip them. |
| AS\_OF\_DATE | Does not exist in the Underlying Description override Fields, so we can skip it. |

##### PARAMETER\_SET

The ParameterSet field does exist in the Underlying Description override Fields, so we generate the following tuple:

| Underlying Description Override Field | Value |
| - | - |
| OVERRIDE KEY FIELD | ParameterSet::CRR3 |
| OVERRIDE DATE FIELD | |
| ParameterSet | CRR3 |
| Bucket | |
| CSRQuality | |
| CSRRating | |
| EquityMarketCap | |
| EquityEconomy | |
| EquitySector | |
| Pool | |
| Attachment | |
| Detachment | |
| CSRSector | |

##### BUCKET

The Bucket field does exist in the Underlying Description override Fields, so we generate the following tuple:

| Underlying Description Override Field | Value |
| - | - |
| OVERRIDE KEY FIELD | Bucket::3a |
| OVERRIDE DATE FIELD | |
| ParameterSet | |
| Bucket | 3a |
| CSRQuality | |
| CSRRating | |
| EquityMarketCap | |
| EquityEconomy | |
| EquitySector | |
| Pool | |
| Attachment | |
| Detachment | |
| CSRSector | |

#### Map override tuples to base table

Now [map the override tuples to base table entries](https://docs.activeviam.com/solutions/frtb/6.0/database/underlying_description_overrides.md#map-override-fields-to-base-table-fields).
Use the following to map the override tuples back to the *Underlying Description* table:

> [!NOTE]
>
> There is no mapping for the **ParameterSet** field

| Underlying Description Override Field | Underlying Description Field | Note |
| - | - | - |
| OVERRIDE KEY FIELD | UNDERLYING | |
| OVERRIDE DATE FIELD | AS\_OF\_DATE | |
| PARAMETER\_SET | | No mapping exists |
| BUCKET | BUCKET | |
| CSRQUALITY | CSRQUALITY | |
| CSRSECTOR | CSRSECTOR | |
| CSRRATING | CSRRATING | |
| EQUITY\_MARKET\_CAP | EQUITY\_MARKET\_CAP | |
| EQUITY\_ECONOMY | EQUITY\_ECONOMY | |
| EQUITY\_SECTOR | EQUITY\_SECTOR | |
| POOL | POOL | |
| ATTACHMENT | ATTACHMENT | |
| DETACHMENT | DETACHMENT | |
| | RISK\_CLASS | No mapping exists |
| | GIRR\_CURVE\_TYPE | No mapping exists |
| | GIRR\_CCY | No mapping exists |
| | UNDERLYING\_FXORIGINAL\_CCY | No mapping exists |

Using the above mapping generates the following entries for the Underlying Description table. "N/A" is used for the **RISK\_CLASS** as it is a
non-nullable field:

| Underlying Description Field | Not Null | Entry 1 | Entry 2 |
| - | - | - | - |
| AS\_OF\_DATE | Y | 2018-09-28 | 2018-09-28 |
| UNDERLYING | Y | ParameterSet::CRR3 | Bucket::3a |
| RISK\_CLASS | Y | "N/A" | "N/A" |
| BUCKET | | | 3a |
| GIRR\_CURVE\_TYPE | | | |
| GIRR\_CCY | | | |
| CSRQUALITY | | | |
| CSRSECTOR | | | |
| CSRRATING | | | |
| EQUITY\_MARKET\_CAP | | | |
| EQUITY\_ECONOMY | | | |
| EQUITY\_SECTOR | | | |
| POOL | | | |
| ATTACHMENT | | | |
| DETACHMENT | | | |
| UNDERLYING\_FXORIGINAL\_CCY | | | |
