# Scenarios

> Ask what-if questions by changing the values you know ahead and comparing the forecasts.

A scenario is a version of the future you want to compare: a heatwave, a price change, a promotion. `scenarios` runs one forecast
per version of the [known covariates](https://yhatlabs.com/models/docs/time-series/covariates) and stacks the results, so you can compare them side
by side.

This compares tomorrow's electricity load under the weather forecast and under a heatwave 6°C warmer (synthetic data where load
rises with temperature):

```python
import numpy as np
import pandas as pd
from yhatlabs import Client
from yhatlabs.features import make_future

# the same synthetic hourly load as in Covariates: load rises with temperature
hours = pd.date_range("2026-06-01", periods=24 * 21, freq="h")
temperature = 20 + 6 * np.sin((hours.hour - 9) * np.pi / 12)
load = 500 + 12 * temperature + np.random.default_rng(0).normal(0, 5, len(hours))
df = pd.DataFrame({"ds": hours, "y": load, "temperature": temperature})

base = make_future(df, h=24)
base["temperature"] = 20 + 6 * np.sin((base["ds"].dt.hour - 9) * np.pi / 12)
heatwave = base.assign(temperature=base["temperature"] + 6)

yh = Client()
out = yh.scenarios(df, 24, {"forecast weather": base, "heatwave +6C": heatwave}, known=["temperature"])
print(out.groupby("scenario")["median"].agg(["mean", "max"]).round(1))
```

Output:

```
               mean    max
scenario                      
forecast weather  739.6  809.7
heatwave +6C      745.8  815.2
```

| Argument | Meaning |
|---|---|
| `df` | the history, with the known covariate columns |
| `24` | the horizon |
| `{"forecast weather": base, ...}` | one future table per scenario, each with the known covariates for every future step |
| `known=["temperature"]` | which columns are known ahead |

The result is a forecast table with a `scenario` column. Any other `forecast` argument (`level=`, `calendar=`, `static=`)
applies to every scenario.
