## 3 Risk Assessment of Technical Constraints Violation  
An explicit and detailed assessment of the annual risk to violate technical constraints in a given distribution network requires a stochastic network analysis, which makes use of ad-hoc probabilistic descriptions of customers' uncertain behaviour. Firstly, their yearly variability has been represented through typical days (with discretization of one hour) that capture the daily, weekly, and seasonal changes in electricity consumption or production, so reproducing the positive and/or negative interactions among loads and non-dispatchable renewable energy sources and the operational impact of the flexibility services. Secondly, their hourly uncertainty has been modelled by assuming Gaussian probability distribution. Consequently, Probabilistic Load Flow (PLF) calculations have been solved for each time step of typical days [12], to identify any critical operating condition with its occurrence probability and to correctly assess the results of possible remedy actions. purchase from a local ancillary services market to solve network contingencies. In previous works, the problem of the optimal flexibility exploitation has been solved with a Linear Programming (LP) approach that minimizes a cost-function, \(C_{Flex}\), expressed as the weighted sum of the flexibility services subject to network constraints:  
\[ \begin{split}&\text{min}C_{Flex}=\sum\limits_{g=1}^{N_{RES}} \alpha_{g}\Delta P_{g}^{RES}+\sum\limits_{d=1}^{N_{DR}}\beta_{d}\Delta P_{d}^{ DR}\\ \text{s.t.}:&\hat{V}_{i}^{min}+\sum\limits_{g=1}^{N _{RES}}\left(\frac{d\
u}{d\beta}\right)_{i,\varphi(g)}\Delta P_{g}^{RES}-\sum \limits_{d=1}^{N_{DR}}\left(\frac{d\
u}{d\beta}\right)_{i,\varphi(d)}\Delta P_{ d}^{DR}\geq V^{min}\;\;\forall i=1,\ldots,N_{N}\\ &\hat{V}_{i}^{max}+\sum\limits_{g=1}^{N_{RES}}\left(\frac{d\
u}{d \beta}\right)_{i,\varphi(g)}\Delta P_{g}^{RES}-\sum\limits_{d=1}^{N_{DR}}\left( \frac{d\
u}{d\beta}\right)_{i,\varphi(d)}\Delta P_{d}^{DR}\leq V^{max}\;\; \forall i=1,\ldots,N_{N}\\ &\hat{I}_{j}^{max}+\sum\limits_{g=1}^{N_{RES}}\left(\frac{dI}{d \beta}\right)_{j,\varphi(g)}\Delta P_{g}^{RES}-\sum\limits_{d=1}^{N_{DR}}\left( \frac{dI}{d\beta}\right)_{j,\varphi(d)}\Delta P_{d}^{DR}\leq I_{j}^{max}\;\; \forall j=1,\ldots,N_{L}\\ &-\hat{I}_{j}^{max}-\sum\limits_{g=1}^{N_{RES}}\left(\frac{dI}{d \beta}\right)_{j,\varphi(g)}\Delta P_{g}^{RES}+\sum\limits_{d=1}^{N_{DR}}\left( \frac{dI}{d\beta}\right)_{j,\varphi(d)}\Delta P_{d}^{DR}\leq I_{j}^{max}\;\; \forall j=1,\ldots,N_{L}\\ & 0\leq\Delta P_{g}^{RES}\leq F_{g}^{RES}\;\;,\;\forall g=1,\ldots,N_{ RES}\;\;;\;0\leq\Delta P_{d}^{DR}\leq F_{d}^{DR}\;,\;\forall d=1,\ldots,N_{DR}\end{split}  \tag{10}\]  
In model (10), \(\alpha\) and \(\beta\) are weights proportional to the cost of the corresponding flexibility service, \(\Delta P_{g}^{RES}\) is the curtailed electricity production from the \(g\)th Renewable Energy Source (RES), \(\Delta P_{d}^{DR}\) is the curtailed electricity consumption from the \(d\)th customer involved on the DR programme, \(F_{g}^{RES}\) and \(F_{d}^{DR}\) are the maximum flexibility offered by the \(g\)th RES and the \(d\)th customer, \(N_{RES}\) and \(N_{DR}\) are respectively the number of RES and of customers available to provide flexibility services, \(N_{N}\) and \(N_{L}\) are respectively the total number of nodes and lines in the distribution network, \(\left(dV/dP\right)_{i,\psi(g\text{ or }d)}\) and \(\left(dI/dP\right)_{j,\psi(g\text{ or }d)}\) are the sensitivity coefficients of the voltage in the \(i\)th node and the current in the \(j\)th branch with respect to the active power variation of a generic DER, and \(\psi(g\text{ or }d)\) is a function that associates the ordinal number of a DER with the cardinal number of the network node where it is connected. To be more precise about the sensitivity coefficients, each of them has been assessed by comparing the PLF results in the initial conditions with those of a second PLF obtained by reducing the active power consumed in a single node.