Joint Probability over Hyperrectangles: From Theory to Trading Concepts
Abstract
This post explores how joint probabilities over bounded regions — known as hyperrectangles — can be expressed as combinations of cumulative distribution functions (CDFs). A general formula is presented and illustrated through a simplified three-variable cases. We demonstrate how this structure can be used in practice with toy data, using my R function (jp()) to automate the calculation. Finally, we discuss its relevance in algorithmic trading, where such joint probabilities may serve as reliable triggers for short-term allocation strategies.
Table of Contents
ToggleJoint Probability as Sum of CDFs
The joint probability \(\mathbb{P}\left( \mathrm{a}_1<\mathrm{X}_1\le \mathrm{b}_1,\cdots ,\mathrm{a}_{\mathrm{d}}<\mathrm{X}_{\mathrm{d}}\le \mathrm{b}_{\mathrm{d}} \right) \) is expressed as the sum of \(2^{\mathrm{d}}\) sign-alternating CDFs, where the CDFs are calculated for different d-element variations of all bounds: \(\mathrm{a}_1,...,\mathrm{ a}_{\mathrm{d}},...,\mathrm{ b}_1,...,\mathrm{ b}_{\mathrm{d}}\). According to Mai & Scherer (2014), this joint probability can be written as:
\[ \begin{aligned} \mathbb{P}\big( \mathrm{a}_1 < \mathrm{X}_1 \le \mathrm{b}_1, \dots, \mathrm{a}_d < \mathrm{X}_d \le \mathrm{b}_d \big) &= \sum_{\left( \mathrm{s}_1, \dots, \mathrm{s}_d \right) \in \prod_{j=1}^{d} \left\{ \mathrm{a}_j, \mathrm{b}_j \right\}} (-1)^{\left| \left\{ j: \mathrm{s}_j = \mathrm{a}_j \right\} \right|} \mathrm{F}\left( \mathrm{s}_1, \dots, \mathrm{s}_d \right) \\[16pt] &= \mathrm{F}\left( \mathrm{b}_1, \dots, \mathrm{b}_d \right) - \mathrm{F}\left( \mathrm{a}_1, \mathrm{b}_2, \dots, \mathrm{b}_d \right) - \dots - \mathrm{F}\left( \mathrm{b}_1, \dots, \mathrm{b}_{d-1}, \mathrm{a}_d \right) \\[12pt] &\quad + \mathrm{F}\left( \mathrm{a}_1, \mathrm{a}_2, \mathrm{b}_3, \dots, \mathrm{b}_d \right) + \dots + \mathrm{F}\left( \mathrm{b}_1, \dots, \mathrm{b}_{d-2}, \mathrm{a}_{d-1}, \mathrm{a}_d \right) \\[12pt] &\quad - \mathrm{F}\left( \mathrm{a}_1, \mathrm{a}_2, \mathrm{a}_3, \mathrm{b}_4, \dots, \mathrm{b}_d \right) - \dots + (-1)^d \mathrm{F}\left( \mathrm{a}_1, \dots, \mathrm{a}_d \right). \end{aligned} \]
Here, \(\mathrm{F(s}_1,...,\mathrm{ s}_{\mathrm{d}})\) denotes the joint CDF of the random vector \((\mathrm{X}_1,...,\mathrm{ X}_{\mathrm{d}})\). Although the formula might seem extraordinarily complicated at first glance, its construction is surprisingly simple:
Three-Variable Decomposition Example
Let's consider computing the joint probability:
\[\mathbb{P}\left( \mathrm{a}_1<\mathrm{X}_1\le \mathrm{b}_1,\mathrm{a}_2<\mathrm{X}_2\le \mathrm{b}_2,\mathrm{a}_3<\mathrm{X}_3\le \mathrm{b}_3 \right).\]
We evaluate 8 terms of the joint CDF \(\mathrm{F}\left( \mathrm{s}_1,\mathrm{s}_2,\mathrm{s}_3 \right) \), where each \(\mathrm{s}_{\mathrm{j}}\) is either \(\mathrm{a}_{\mathrm{j}}\) or \(\mathrm{b}_{\mathrm{j}}\):
Term | Lower bounds used (k) | Sign | Contribution |
\(\mathrm{F}\left( \mathrm{b}_1,\mathrm{b}_2,\mathrm{b}_3 \right) \) | 0 | +1 | Added |
\(\mathrm{F}\left( \mathrm{a}_1,\mathrm{b}_2,\mathrm{b}_3 \right) \) | 1 | -1 | Subtracted |
\(\mathrm{F}\left( \mathrm{b}_1,\mathrm{a}_2,\mathrm{b}_3 \right) \) | 1 | -1 | Subtracted |
\(\mathrm{F}\left( \mathrm{b}_1,\mathrm{b}_2,\mathrm{a}_3 \right) \) | 1 | -1 | Subtracted |
\(\mathrm{F}\left( \mathrm{a}_1,\mathrm{a}_2,\mathrm{b}_3 \right) \) | 2 | +1 | Added |
\(\mathrm{F}\left( \mathrm{a}_1,\mathrm{b}_2,\mathrm{a}_3 \right) \) | 2 | +1 | Added |
\(\mathrm{F}\left( \mathrm{b}_1,\mathrm{a}_2,\mathrm{a}_3 \right) \) | 2 | +1 | Added |
\(\mathrm{F}\left( \mathrm{a}_1,\mathrm{a}_2,\mathrm{a}_3 \right) \) | 3 | -1 | Subtracted |
Drawing on the table above, we can now express the joint probability \(\mathbb{P}\left( \mathrm{a}_1<\mathrm{X}_1\le \mathrm{b}_1,\mathrm{a}_2<\mathrm{X}_2\le \mathrm{b}_2,\mathrm{a}_3<\mathrm{X}_3\le \mathrm{b}_3 \right) \) in a quite straightforward manner:
\[ \begin{aligned} &\mathbb{P}\left( \mathrm{a}_1 < \mathrm{X}_1 \le \mathrm{b}_1,\ \mathrm{a}_2 < \mathrm{X}_2 \le \mathrm{b}_2,\ \mathrm{a}_3 < \mathrm{X}_3 \le \mathrm{b}_3 \right) \\[12pt] &= \mathrm{F}\left( \mathrm{b}_1, \mathrm{b}_2, \mathrm{b}_3 \right) - \mathrm{F}\left( \mathrm{a}_1, \mathrm{b}_2, \mathrm{b}_3 \right) - \mathrm{F}\left( \mathrm{b}_1, \mathrm{a}_2, \mathrm{b}_3 \right) - \mathrm{F}\left( \mathrm{b}_1, \mathrm{b}_2, \mathrm{a}_3 \right) \\[12pt] &\quad + \mathrm{F}\left( \mathrm{a}_1, \mathrm{a}_2, \mathrm{b}_3 \right) + \mathrm{F}\left( \mathrm{a}_1, \mathrm{b}_2, \mathrm{a}_3 \right) + \mathrm{F}\left( \mathrm{b}_1, \mathrm{a}_2, \mathrm{a}_3 \right) - \mathrm{F}\left( \mathrm{a}_1, \mathrm{a}_2, \mathrm{a}_3 \right). \end{aligned} \]
Copula Representation of Joint Distribution
Continuing with the three-variable case, calculating the joint probability directly is often infeasible due to the lack of a closed-form cumulative distribution function (CDF) for multivariate distributions. However, Sklar's Theorem provides a solution: any multivariate distribution can be expressed as a copula function applied to its marginal distributions. In the case of three variables, this takes the form:
\[ \mathrm{F(s}_1,\ \mathrm{s}_2,\ \mathrm{s}_3) = \mathrm{C(F}_1(\mathrm{s}_1),\ \mathrm{F}_2(\mathrm{s}_2),\ \mathrm{F}_3(\mathrm{s}_3)) = \mathrm{C(u}_1,\ \mathrm{u}_2,\ \mathrm{u}_3) \]
where \(\mathrm{F}\) is the joint CDF, \(\mathrm{F}_1\), \(\mathrm{F}_2\), and \(\mathrm{F}_3\) are the marginal CDFs, and \(\mathrm{u}_{\mathrm{i}}\mathrm{ }=\mathrm{ F}_{\mathrm{i}}(\mathrm{s}_{\mathrm{i}})\) for \(\mathrm{i }=\mathrm{ }1,\mathrm{ }2,\mathrm{ }3\).
Practical Computation
This approach turns out to be highly useful. Suppose we are tasked with calculating the conditional probability:
\[ \mathbb{P}\left( X_1 > 0,\ -1 < X_2 \le 2 \,\middle|\, X_3 \le 1 \right). \]
This can be equivalently written in terms of upper and lower bounds as:
\[ \mathbb{P}\left( 0 < X_1 \le +\infty,\ -1 < X_2 \le 2 \,\middle|\, -\infty < X_3 \le 1 \right). \]
Applying the rule of conditional probability, we obtain:
Fully expanded with the bounds for the denominator, the formula becomes:
Now, we can quite straightforwardly apply the general joint probability formula for three variables to both the numerator and the denominator.
\[ \text{For the numerator: }\quad a_1 = 0,\ a_2 = -1,\ a_3 = -\infty,\quad b_1 = +\infty,\ b_2 = 2,\ b_3 = 1 \]\[ \text{For the denominator: }\quad a_1 = -\infty,\ a_2 = -\infty,\ a_3 = -\infty,\quad b_1 = +\infty,\ b_2 = +\infty,\ b_3 = 1 \]
It would be very useful to have a function that automatically calculates the required CDFs for both the numerator and the denominator.
I have developed such a function in R, called jp(). It computes the necessary CDFs using empirical data.
The function selects the best-fitting copula according to the AIC criterion to represent the joint CDF of the observed variables.
The choice is made from the following copulas: Gaussian, t-Student, Clayton, Gumbel, Frank, and Joe.
The function relies on the R packages: {copula} and {kde1d}.
It takes two arguments: a data frame containing the observations of each variable in columns, and a data frame where the first column contains the lower bounds and the second column contains the upper bounds.
Empirical Example with Toy Data
We observe values for three variables: \(\mathrm{X}_1\), \(\mathrm{X}_2\), and \(\mathrm{X}_3\). Below are the first six rows of the dataset used:
> head(X)
x1 x2 x3
[1,] -1.7928558 -1.8564848 -1.7891544
[2,] -0.8792268 -0.7166852 -0.4162663
[3,] -0.1309697 -0.1014559 -0.2922744
[4,] 0.5959354 0.7769484 0.4188956
[5,] -1.7139445 -1.6686546 -1.6626468
[6,] 0.3358360 0.9212948 0.8803213
Bounds for the numerator (num_bounds):
> num_bounds
l u
1 0 Inf
2 -1 2
3 -Inf 1
Bounds for the denominator (den_bounds):
> den_bounds
l u
1 -Inf Inf
2 -Inf Inf
3 -Inf 1
Thus, the conditional probability \(\mathbb{P}\left( X_1>0,-1<\mathrm{X}_2\le 2\,|\,\mathrm{X}_3\le 1 \right)\) is computed as follows using the jp() function:
> jp(data = X, bounds = num_bounds)/jp(data = X, bounds = den_bounds)
[1] 0.3890512
Lastly, we arrived at what looked like a messy conditional probability. We practically breezed through it.
Application in Algorithmic Trading
Assume we observe three financial time series: \(\mathrm{TS}_1,\mathrm{ TS}_2\), and \(\mathrm{TS}_3\), which together describe the current state of the market. The first two represent the behavior of asset prices and are classified into continuous intervals corresponding to two states: \(\mathrm{D}\) (indicating a downward movement potential) and \(\mathrm{U}\) (indicating an upward movement potential).
The third time series, \(\mathrm{TS}_3\), captures a broader market condition and is associated with a market regime labeled \(\mathrm{R}_i\), defined by a specific continuous interval.
We consider the joint conditional probability:
\[\mathbb{P}(\mathrm{TS}_1\in \mathrm{D},\mathrm{TS}_2\in \mathrm{U}\,|\,\mathrm{TS}_3\in \mathrm{R}_{\mathrm{i}}).\]
If this probability is relatively low, it indicates that under the current market regime \(\mathrm{R}_i\), the observed behavior — one asset trending down and the other up — is statistically unusual. Such an abnormality may signal a potential price reversal or even a forthcoming shift in market regime, triggered by unusual asset behavior.
This probabilistic insight provides a foundation for designing algorithmic strategies aimed at detecting such anomalies. Under the assumption that the market does not remain in abnormal states for extended periods, these setups can be exploited to enter optimal and potentially profitable positions.
Conclusion
Understanding joint probabilities through the lens of CDF decomposition and copulas offers both conceptual clarity and practical utility. By structuring multivariate probability in terms of hyperrectangles, we gain tools for strategy design via signal generation, as well as for regime detection. Whether implemented in code or applied conceptually, this framework promotes a shift from isolated indicators to dependence-aware decision-making — a critical mindset in quantitative trading models.
For a complementary statistical framework for validating trading hypotheses, see my post on G*Power for strategy validation.
For a comprehensive reference on copula theory and joint distributions, see my Copula Reference Guide.
To explore copula-based joint probability modeling in depth, check out my video course: Copulas: Theory, Project & R.
Resources
- Mai, J.-F., & Scherer, M. (2014). Financial Engineering with Copulas Explained. Springer. pp. 28–29.
- Joint Probability Hyperrectangles Script (R)

Related methodological resources
Continue Exploring Quantitative Finance Methodology
Explore PDF textbooks, implementation-oriented bundles, and methodological frameworks in quantitative investing, trading research, and scientific backtesting.
Explore PDF Textbooks & Bundles
