arXiv:2609.21495stat.COSep 2026

Manuscript Offprint

arXiv:2609.21495

Scentree: a framework for generating scenario trees for multistage stochastic programming

Cristian Pachón-García, Albert Solà Vilalta, F. -Javier Heredia

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Abstract

We present scentree, an open-source Python package for constructing scenario trees for multistage stochastic programming models using either historical data or samples drawn from a probability distribution. It combines machine learning and multivariate time series models to obtain a scenario fan that captures dependencies in the stochastic processes. This scenario fan is subsequently reduced into a scenario tree that preserves representativeness of the stochastic process, providing a flexible and extensible framework for uncertainty modeling in stochastic programming problems. The framework can also be naturally applied to two-stage stochastic programming problems. Key contributions are the joint modeling of the stochastic process, preserving correlations between all random variables, and the automation of the complete workflow, including forecasting model selection, parameter estimation, scenario fan generation, and scenario tree construction. In addition, scentree does not assume any underlying data distribution, reducing the statistical expertise required to produce a scenario tree, and is modular by design, allowing external forecasts and other partial executions of the workflow.

Keywords: scenario tree, multistage stochastic programming, uncertainty estimation, machine learning, multivariate time series models.

1 Introduction

Uncertainty arises naturally in many situations where decision must be made before all relevant information is available. For instance, in finance, investment decisions are made under uncertainty about future market conditions (Dixit and Pindyck, 2012). Similarly, in energy system operation, decisions regarding electricity generation must be made before future demand is known (Roald et al., 2023). In these and other applications, uncertain quantities evolve over time, and new information becomes available as the decision-making process progresses.

Multistage stochastic programming (Birge and Louveaux, 2011; Pflug and Pichler, 2014) provides a mathematical framework for addressing these decision problems by explicitly incorporating the evolution of uncertain parameters across multiple stages. At each stage, decisions can be adjusted according to the information available up to that point, allowing the model to account for the sequential revelation of uncertainty.

A key component of a multistage stochastic program is the representation of the underlying uncertainty. In its most general form, uncertain quantities can be described by a stochastic process. Usually, these stochastic processes admit infinitely many possible realizations, making their direct incorporation into a mathematical optimization model impractical. Consequently, a discrete approximation of the stochastic process is required. Such an approximation can be represented by a finite collection of scenarios (Dupačová et al., 2000), where each scenario corresponds to one possible realization of the stochastic process over the planning horizon.

In multistage problems, scenarios must capture the structure of the underlying uncertain process, which is typically defined over an index set representing time or other relevant dimensions. A scenario fan consists of a collection of possible trajectories of the uncertain process, with each scenario representing one possible evolution across the stages. A scenario tree provides the structured representation of these scenarios following the multistage decision-taking process defined in the associated stochastic programming problem, where scenarios can share nodes at a given stage and branch into different possible subsequent evolutions. Probabilities are assigned to the nodes to quantify the likelihood of the corresponding realizations, allowing the resulting discrete representation to be incorporated into a multistage stochastic programming model.

The construction of representative scenarios and, subsequently, a suitable scenario tree is therefore an essential step in the practical application of multistage stochastic programming. A scenario representation should capture the main characteristics of the underlying stochastic process. When historical observations of the uncertain process are available, scenario generation can be approached directly from data rather than by assuming a predefined probability distribution. This approach is particularly relevant when the underlying process is multivariate or exhibits complex temporal dependencies.

Building on these considerations, we present scentree, an open-source Python (Python Software Foundation, 2026) framework for generating scenario fans and scenario trees for multistage stochastic programming problems from historical data. The package is equally applicable to both two-stage and multistage stochastic problems. However, this work focuses on the multistage setting, as it is more general, complex, interesting and challenging from a methodological perspective, than two-stage problems, and fewer software tools are available for it.

In this context, the main contributions are (i) a data-driven approach based on historical data for developing predictive models; (ii) the integration of statistical and machine learning models; (iii) the ability to account for dependencies, such as correlations, among variables; (iv) a modular design supporting external forecasting tools; and (v) a fully automated workflow that reduces the expertise required from users to develop and apply forecasting algorithms.

To establish the mathematical framework used throughout the paper, we introduce the notation for the decision process, the optimization problem, the underlying stochastic process, and the scenario tree. Multistage stochastic programming models sequential decision-making under uncertainty, in which decisions are made as random information is revealed across stages. Following Pflug and Pichler (2014, Section 1.2), we represent this sequential structure as

x0⟶ξ1⟶x1⟶⋯⟶xs−1⟶ξs,\mathbf{x}_{0}\longrightarrow\boldsymbol{\xi}_{1}\longrightarrow\mathbf{x}_{1}\longrightarrow\cdots\longrightarrow\mathbf{x}_{s-1}\longrightarrow\boldsymbol{\xi}_{s},

possibly followed by a terminal decision xs\mathbf{x}_{s}. The initial decision, x0\mathbf{x}_{0}, is deterministic, and each subsequent decision xi\mathbf{x}_{i}, 1≤i≤s1\leq i\leq s, depends only on the observed random variables (ξ1,…,ξi)(\boldsymbol{\xi}_{1},\ldots,\boldsymbol{\xi}_{i}), ensuring nonanticipativity.

A multistage stochastic programming problem optimizes this decision process; in the risk-neutral case, its general formulation is

min⁡x nonanticipativeE ⁣[f(x,ξ)]subject to  x∈X(ξ)almost surely,\displaystyle\min_{\mathbf{x}\ \mathrm{nonanticipative}}\mathbb{E}\!\left[f(\mathbf{x},\boldsymbol{\xi})\right]\quad\text{subject to}\;\mathbf{x}\in\mathcal{X}(\boldsymbol{\xi})\quad\text{almost surely},

where x\mathbf{x} denotes the sequence of decisions, ξ≔(ξ1,…,ξs)\boldsymbol{\xi}\coloneqq(\boldsymbol{\xi}_{1},\ldots,\boldsymbol{\xi}_{s}) the sequence of random variables, ff the total cost, and X(ξ)\mathcal{X}(\boldsymbol{\xi}) the feasible set. We model the uncertainty through a multivariate stochastic process

ξ ⁣:D×Ω→Rp,\boldsymbol{\xi}\colon\mathcal{D}\times\Omega\to\mathbb{R}^{p},

where D\mathcal{D} is the index set and Ω\Omega is the sample space. Each stage ii is associated with a stochastic process

ξi ⁣:D×Ω→Rpi\boldsymbol{\xi}_{i}\colon\mathcal{D}\times\Omega\to\mathbb{R}^{p_{i}}

with

∑i=1spi=p.\sum_{i=1}^{s}p_{i}=p.

Our objective is to obtain a discrete approximation ξtr\boldsymbol{\xi}_{\mathrm{tr}} of the underlying stochastic process ξ\boldsymbol{\xi}, represented by a scenario tree. We define

ξtr ⁣:D×Ωtr→Rp,\boldsymbol{\xi}_{\mathrm{tr}}\colon\mathcal{D}\times\Omega_{\mathrm{tr}}\to\mathbb{R}^{p},

where Ωtr\Omega_{\mathrm{tr}} is a finite sample space whose elements correspond to the scenarios of the tree. A discrete probability distribution is defined over Ωtr\Omega_{\mathrm{tr}}, assigning a probability to each scenario.

In practice, the stochastic process is inferred from historical data, represented by a matrix Y\mathbf{Y} of size d×pd\times p, where dd denotes the number of observed realizations of the stochastic process and pp is the dimension of each realization.

To the best of our knowledge, scentree is the first Python framework specifically designed for scenario fan and tree generation using statistical and machine learning algorithms. The framework is also well suited to two-stage stochastic programming problems, as it provides a systematic approach for generating data-driven representations of uncertainty from historical observations.

The remainder of this paper is organized as follows. Section 2 presents and discusses the state of the art in scenario generation software. Section 3 provides a detailed description of the scentree package, followed by an illustrative example in Section 4. Finally, Section 5 presents the conclusions and discusses potential directions for future research.