The *automatic tracking of measurability* has been part of finmath-lib since its earliest version ( 2004). It adds a method to random variables to inspect their measurability. Its concept and implementation is similar to a forward mode automatic differentiation, in the sense that each operator is augmented with a corresponding operation on measurability and certain random variables (constants, Brownian increments) are initialized with specific values.

For a random variable X we define a map T : X → [-∞ , ∞) such that for for t ≥ T(X) it is guaranteed that X is F_{t}-measurable. It is not guaranteed that T(X) is the smallest such number, although in most cases the implementation can provide the smallest time.

Originally the concept was introduces as a safe-guard in least-square-estimates of the conditional expectation (American Monte-Carlo), to ensure that the regression basis functions are F_{t}-measurable if used in an F_{t}-conditional expectation. However, the concept allows for important optimizations in the context of *stochastic automatic differentiation*: it may be used to detect cases where the computationally expensive conditional expectation operator can be avoided. It is:

Then random variable interface provides a method `getFiltrationTime()` implementing T(X) such that for a random variable X represented by the object `X` and t calculated by t = `X.getFiltrationTime()` it is guaranteed that X is F_{t}-measurable (note again: it is not guaranteed that t is the smallest such number, although in most cases the implementation can provide the smallest time).

The implementation is similar to a forward mode automatic differentiation, where the operator on random variables is augmented by additional operations on the filtration time:

Let T(X) denote the filtration time of X, i.e., T(X) = `X.getFiltrationTime()`. We apply the following definitions:

- For constant (deterministic) random variables C we set T(C) = -∞
- For Brownian increments W(t+Δt)-W(t) we set T(W(t+Δt)-W(t)) = t+Δ
- For operators f on random variables X
_{1},…,X_{n}with Z = f(X_{1},…,X_{n}) we set T(Z) = max(T(X_{1}),…,T(X_{n}))

This definition of T already fulfills the requirement that t = T(Z) is a time guaranteeing that Z is F_{t}-measurable, however it may not give the smallest such filtration time. There are a few optimizations or special cases which can be implemented, e.g. for Z = 0 * X we have T(Z) = T(0) (instead of T(Z) = max(T(0),T(X)) = T(X). Note: This definition already covers the generation of the correct filtration times for an Euler-scheme of an Ito process.

An implementation may achieve this by augmenting (extending) the type X by (X,t) with t = T(X) and overloading operators on X.

The method is implemented in `RandomVariable` implementing the interface `RandomVariableInterface` in finmath-lib. The interface is given as (extract)

public interface RandomVariableInterface { double getFiltrationTime(); public RandomVariableInterface add(RandomVariableInterface randomVariable); // ... (declaration of other methods) }

and the implementation is given as (extract)

public class RandomVariable implements RandomVariableInterface { private final double time; // Time (filtration) @Override public double getFiltrationTime() { return time; } // ... (implementation of other methods) @Override public RandomVariableInterface add(RandomVariableInterface randomVariable) { // Set time of this random variable to maximum of time with respect to which measurability is known. double newTime = Math.max(time, randomVariable.getFiltrationTime()); // ... (calculate newRealizations as sum of this and randomVariable) return new RandomVariable(newTime, newRealizations); } }

For an application to AAD for American Monte-Carlo simulation see

Fries, Christian P., Automatic Backward Differentiation for American Monte-Carlo Algorithms - ADD for Conditional Expectations and Indicator Functions (June 27, 2017). Available at SSRN: https://ssrn.com/abstract=3000822