> ## Documentation Index
> Fetch the complete documentation index at: https://docs.energy.nlead.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# Core Algorithm

> From forecast to balanced schedules, deterministically

This is what happens to your data once it arrives. The computation is fully
deterministic — the same input always yields the same schedules. For each
quarter-hour `t` of the delivery day:

<Steps>
  <Step title="Net position per control area">
    ```text theme={null}
    net[a][t] = Σ production[a][t] − Σ consumption[a][t]
    ```

    Positive = long/surplus, negative = short/deficit.
  </Step>

  <Step title="Open position per control area">
    ```text theme={null}
    open_position[a][t] = −net[a][t]
    ```

    Positive = must buy, negative = must sell.
  </Step>

  <Step title="Total German open position">
    ```text theme={null}
    total_open[t] = Σ over a of open_position[a][t]
    ```

    This is the volume the trader executes on the EPEX day-ahead auction. It
    is delivered (via ECC) into the home balancing group.
  </Step>

  <Step title="Distribution transfers">
    ```text theme={null}
    transfer[home → a][t] = open_position[a][t]        for every a ≠ home
    ```

    Each transfer is a matched pair: an *out* trade in the home group's
    schedule and an *in* trade in the target group's schedule.
  </Step>

  <Step title="Schedule assembly">
    Every balancing group gets a schedule containing its production
    forecast, its consumption forecast and its trades, with trades
    **aggregated per direction and counterparty** (non-negative values; a
    negative quantity flips to the opposite direction).
  </Step>
</Steps>

## Why every schedule sums to zero

The home group receives the full EPEX volume and passes on exactly the
non-home shares, keeping its own:

```text theme={null}
home:      net[home] + total_open − Σ transfers out = net[home] + open[home] = 0
non-home:  net[a] + transfer in                     = net[a] + open[a]      = 0
```

Expressed on schedule components:
`production − consumption + trades = net + trades = 0`.

## Guaranteed properties

Two properties hold for every delivery day, and are verified continuously
against randomised data for every choice of home area and all three day
lengths (96 / 92 / 100 intervals):

1. Every balancing-group schedule sums to zero at every quarter-hour.
2. The net transfer out of the home group equals the sum of the other
   areas' open positions — nothing is created or lost in the distribution.

## When the auction fills differently

The requested and the executed EPEX volume are not assumed to be identical.
If the trader's fill deviates from the requested open position:

* the transfers to the other control areas stay unchanged — their needs are
  their needs,
* the home balancing group absorbs the difference, and the residual is
  recorded per quarter-hour as a visible imbalance rather than being
  silently discarded.
