- All Superinterfaces:
Serializable
- All Known Subinterfaces:
RandomVariableAccumulator
,RandomVariableArray
,RandomVariableDifferentiable
- All Known Implementing Classes:
RandomVariableArrayImplementation
,RandomVariableDifferentiableAAD
,RandomVariableDifferentiableAD
,RandomVariableFromDoubleArray
,RandomVariableFromFloatArray
,RandomVariableLazyEvaluation
,Scalar
This interface describes the methods implemented by an immutable random variable.
The random variable is immutable, i.e. method calls like add, sub, mult will return
a new instance and leave the method receiver random variable unchanged (immutable).
This is used to ensure that arguments or return values are not changed.
- Version:
- 1.6
- Author:
- Christian Fries
-
Method Summary
Modifier and TypeMethodDescriptionabs()
Applies x → Math.abs(x), i.e.accrue(RandomVariable rate, double periodLength)
Applies x → x * (1.0 + rate * periodLength) to this random variable.add(double value)
Applies x → x + value to this random variable.add(RandomVariable randomVariable)
Applies x → x+randomVariable to this random variable.addProduct(RandomVariable factor1, double factor2)
Applies x → x + factor1 * factor2addProduct(RandomVariable factor1, RandomVariable factor2)
Applies x → x + factor1 * factor2addRatio(RandomVariable numerator, RandomVariable denominator)
Applies x → x + numerator / denominatordefault RandomVariable
addSumProduct(List<RandomVariable> factor1, List<RandomVariable> factor2)
Applies \( x \mapsto x + \sum_{i=0}^{n-1} factor1_{i} * factor2_{i}default RandomVariable
addSumProduct(RandomVariable[] factor1, RandomVariable[] factor2)
Applies \( x \mapsto x + \sum_{i=0}^{n-1} factor1_{i} * factor2_{i}apply(DoubleBinaryOperator operator, RandomVariable argument)
Applies x → operator(x,y) to this random variable, where x is this random variable and y is a given random variable.apply(DoubleUnaryOperator operator)
Applies x → operator(x) to this random variable.apply(DoubleTernaryOperator operator, RandomVariable argument1, RandomVariable argument2)
Applies x → operator(x,y,z) to this random variable, where x is this random variable and y and z are given random variable.default RandomVariable
appy(RandomOperator operator)
Applies x → operator(x) to this random variable.average()
Returns a random variable which is deterministic and corresponds the expectation of this random variable.default RandomVariable
bus(double value)
Applies x → value - x to this random variable.bus(RandomVariable randomVariable)
Applies x → randomVariable-x to this random variable.cache()
Return a cacheable version of this object (often a self-reference).cap(double cap)
Applies x → min(x,cap) to this random variable.cap(RandomVariable cap)
Applies x → min(x,cap) to this random variable.choose(RandomVariable valueIfTriggerNonNegative, RandomVariable valueIfTriggerNegative)
Applies x → (x ≥ 0 ? valueIfTriggerNonNegative : valueIfTriggerNegative)cos()
Applies x → cos(x) to this random variable.default RandomVariable
covariance(RandomVariable value)
Returns a random variable which is deterministic and corresponds the covariance of this random variable and the argument.discount(RandomVariable rate, double periodLength)
Applies x → x / (1.0 + rate * periodLength) to this random variable.div(double value)
Applies x → x / value to this random variable.div(RandomVariable randomVariable)
Applies x → x/randomVariable to this random variable.Returns the double value if isDeterministic() is true.boolean
equals(RandomVariable randomVariable)
Compare this random variable with a given oneexp()
Applies x → exp(x) to this random variable.default RandomVariable
Returns a random variable which is deterministic and corresponds the expectation of this random variable.default RandomVariable
expm1()
Applies x → expm1(x) (that is x → exp(x)-1.0) to this random variable.floor(double floor)
Applies x → max(x,floor) to this random variable.floor(RandomVariable floor)
Applies x → max(x,floor) to this random variable.double
get(int pathOrState)
Evaluate at a given path or state.double
Returns the expectation of this random variable.double
getAverage(RandomVariable probabilities)
Returns the expectation of this random variable for a given probability measure (weight).default RandomVariable
getConditionalExpectation(ConditionalExpectationEstimator conditionalExpectationOperator)
Returns the conditional expectation using a given conditional expectation estimator.double
Returns the filtration time.double[]
getHistogram(double[] intervalPoints)
Generates a Histogram based on the realizations stored in this random variable.double[][]
getHistogram(int numberOfPoints, double standardDeviations)
Generates a histogram based on the realizations stored in this random variable using interval points calculated from the arguments, see alsogetHistogram(double[])
.double
getMax()
Returns the maximum value attained by this random variable.double
getMin()
Returns the minimum value attained by this random variable.Returns the operator path → this.get(path) corresponding to this random variable.double
getQuantile(double quantile)
Returns the quantile value for this given random variable, i.e., the value x such that P(this < x) = quantile, where P denotes the probability measure.double
getQuantile(double quantile, RandomVariable probabilities)
Returns the quantile value for this given random variable, i.e., the value x such that P(this < x) = quantile, where P denotes the probability measure.double
getQuantileExpectation(double quantileStart, double quantileEnd)
Returns the expectation over a quantile for this given random variable.double[]
Returns a vector representing the realization of this random variable.Returns a stream of doubles corresponding to the realizations of this random variable.double
Returns the sample variance of this random variable, i.e., V * size()/(size()-1) where V = getVariance().double
Returns the standard deviation of this random variable, i.e., sqrt(V) where V = ((X-m)^2).getAverage() and X = this and m = X.getAverage().double
getStandardDeviation(RandomVariable probabilities)
Returns the standard deviation of this random variable, i.e., sqrt(V) where V = ((X-m)^2).getAverage(probabilities) and X = this and m = X.getAverage(probabilities).double
Returns the standard error (discretization error) of this random variable.double
getStandardError(RandomVariable probabilities)
Returns the standard error (discretization error) of this random variable.int
Returns the type priority.default RandomVariable
Returns the underlying values and a random variable.double
Returns the variance of this random variable, i.e., V where V = ((X-m)^2).getAverage() and X = this and m = X.getAverage().double
getVariance(RandomVariable probabilities)
Returns the variance of this random variable, i.e., V where V = ((X-m)^2).getAverage(probabilities) and X = this and m = X.getAverage(probabilities).invert()
Applies x → 1/x to this random variable.boolean
Check if this random variable is deterministic in the sense that it is represented by a single double value.isNaN()
Applies x → (Double.isNaN(x) ? 1.0 : 0.0)log()
Applies x → log(x) to this random variable.mult(double value)
Applies x → x * value to this random variable.mult(RandomVariable randomVariable)
Applies x → x*randomVariable to this random variable.pow(double exponent)
Applies x → pow(x,exponent) to this random variable.sin()
Applies x → sin(x) to this random variable.int
size()
Returns the number of paths or states.sqrt()
Applies x → sqrt(x) to this random variable.squared()
Applies x → x * x to this random variable.sub(double value)
Applies x → x - value to this random variable.sub(RandomVariable randomVariable)
Applies x → x-randomVariable to this random variable.subRatio(RandomVariable numerator, RandomVariable denominator)
Applies x → x - numerator / denominatordefault RandomVariable
variance()
Returns a random variable which is deterministic and corresponds the variance of this random variable.default RandomVariable
vid(double value)
Applies x → value / x to this random variable.vid(RandomVariable randomVariable)
Applies x → randomVariable/x to this random variable.
-
Method Details
-
equals
Compare this random variable with a given one- Parameters:
randomVariable
- Random variable to compare with.- Returns:
- True if this random variable and the given one are equal, otherwise false
-
getFiltrationTime
double getFiltrationTime()Returns the filtration time.- Returns:
- The filtration time.
-
getTypePriority
int getTypePriority()Returns the type priority.- Returns:
- The type priority.
- See Also:
- ssrn abstract 3246127
-
get
double get(int pathOrState)Evaluate at a given path or state.- Parameters:
pathOrState
- Index of the path or state.- Returns:
- Value of this random variable at the given path or state.
-
size
int size()Returns the number of paths or states.- Returns:
- Number of paths or states.
-
isDeterministic
boolean isDeterministic()Check if this random variable is deterministic in the sense that it is represented by a single double value. Note that the methods returns false, if the random variable is represented by a vector where each element has the same value.- Returns:
- True if this random variable is deterministic.
-
getValues
Returns the underlying values and a random variable. If the implementation supports an "inner representation", returns the inner representation. Otherwise just returns this.- Returns:
- The underling values.
-
getRealizations
double[] getRealizations()Returns a vector representing the realization of this random variable. This method is merely useful for analysis. Its interpretation depends on the context (Monte-Carlo or lattice). The method does not expose an internal data model.- Returns:
- Vector of realizations of this random variable.
-
doubleValue
Double doubleValue()Returns the double value if isDeterministic() is true. otherwise throws anUnsupportedOperationException
.- Returns:
- The double value if isDeterministic() is true, otherwise throws an an
UnsupportedOperationException
.
-
getOperator
IntToDoubleFunction getOperator()Returns the operator path → this.get(path) corresponding to this random variable.- Returns:
- The operator path → this.get(path) corresponding to this random variable.
-
getRealizationsStream
DoubleStream getRealizationsStream()Returns a stream of doubles corresponding to the realizations of this random variable.- Returns:
- A stream of doubles corresponding to the realizations of this random variable.
-
getMin
double getMin()Returns the minimum value attained by this random variable.- Returns:
- The minimum value.
-
getMax
double getMax()Returns the maximum value attained by this random variable.- Returns:
- The maximum value.
-
getAverage
double getAverage()Returns the expectation of this random variable. The result of this method has to agrees withaverage().doubleValue()
.- Returns:
- The average assuming equi-distribution.
-
getAverage
Returns the expectation of this random variable for a given probability measure (weight). The result of this method is (mathematically) equivalent to
this.mult(probabilities).getAverage() / probabilities.getAverage()
while the internal implementation may differ, e.g. being more efficient by performing multiplication and summation in the same loop.- Parameters:
probabilities
- The probability weights.- Returns:
- The average assuming the given probability weights.
-
getVariance
double getVariance()Returns the variance of this random variable, i.e., V where V = ((X-m)^2).getAverage() and X = this and m = X.getAverage().- Returns:
- The average assuming equi-distribution.
-
getVariance
Returns the variance of this random variable, i.e., V where V = ((X-m)^2).getAverage(probabilities) and X = this and m = X.getAverage(probabilities).- Parameters:
probabilities
- The probability weights.- Returns:
- The average assuming the given probability weights.
-
getSampleVariance
double getSampleVariance()Returns the sample variance of this random variable, i.e., V * size()/(size()-1) where V = getVariance().- Returns:
- The sample variance.
-
getStandardDeviation
double getStandardDeviation()Returns the standard deviation of this random variable, i.e., sqrt(V) where V = ((X-m)^2).getAverage() and X = this and m = X.getAverage().- Returns:
- The standard deviation assuming equi-distribution.
-
getStandardDeviation
Returns the standard deviation of this random variable, i.e., sqrt(V) where V = ((X-m)^2).getAverage(probabilities) and X = this and m = X.getAverage(probabilities).- Parameters:
probabilities
- The probability weights.- Returns:
- The standard error assuming the given probability weights.
-
getStandardError
double getStandardError()Returns the standard error (discretization error) of this random variable. For a Monte-Carlo simulation this is 1/Math.sqrt(n) *getStandardDeviation()
.- Returns:
- The standard error assuming equi-distribution.
-
getStandardError
Returns the standard error (discretization error) of this random variable. For a Monte-Carlo simulation this is 1/Math.sqrt(n) *getStandardDeviation(RandomVariable)
.- Parameters:
probabilities
- The probability weights.- Returns:
- The standard error assuming the given probability weights.
-
getQuantile
double getQuantile(double quantile)Returns the quantile value for this given random variable, i.e., the value x such that P(this < x) = quantile, where P denotes the probability measure. The method will consider picewise constant values (with constant extrapolation) in the random variable. That is getQuantile(0) wiil return the smallest value and getQuantile(1) will return the largest value.- Parameters:
quantile
- The quantile level.- Returns:
- The quantile value assuming equi-distribution.
-
getQuantile
Returns the quantile value for this given random variable, i.e., the value x such that P(this < x) = quantile, where P denotes the probability measure.- Parameters:
quantile
- The quantile level.probabilities
- The probability weights.- Returns:
- The quantile value assuming the given probability weights.
-
getQuantileExpectation
double getQuantileExpectation(double quantileStart, double quantileEnd)Returns the expectation over a quantile for this given random variable. The method will consider picewise constant values (with constant extrapolation) in the random variable. For a ≤ b the method returns (Σa ≤ i ≤ b x[i]) / (b-a+1), where- a = min(max((n+1) * quantileStart - 1, 0, 1);
- b = min(max((n+1) * quantileEnd - 1, 0, 1);
- n = this.size();
- Parameters:
quantileStart
- Lower bound of the integral.quantileEnd
- Upper bound of the integral.- Returns:
- The (conditional) expectation of the values between two quantile levels assuming equi-distribution.
-
getHistogram
double[] getHistogram(double[] intervalPoints)Generates a Histogram based on the realizations stored in this random variable. The returnedresult
array's length isintervalPoints.length+1
.- The value result[0] equals the relative frequency of values observed in the interval ( -infinity, intervalPoints[0] ].
- The value result[i] equals the relative frequency of values observed in the interval ( intervalPoints[i-1], intervalPoints[i] ].
- The value result[n] equals the relative frequency of values observed in the interval ( intervalPoints[n-1], infinity ).
possibleValues
, thenresult = getHistogram(possibleValues)
returns an array whereresult[i]
is the relative frequency of occurrence ofpossibleValues[i]
. The sum of result[i] over all i is equal to 1, except for uninitialized random variables where all values are 0.- Parameters:
intervalPoints
- Array of ascending values defining the interval boundaries.- Returns:
- A histogram with respect to a provided interval.
-
getHistogram
double[][] getHistogram(int numberOfPoints, double standardDeviations)Generates a histogram based on the realizations stored in this random variable using interval points calculated from the arguments, see alsogetHistogram(double[])
. The interval points are set with equal distance over an the interval of the specified standard deviation. The interval points used arex[i] = mean + alpha[i] * standardDeviations * sigma
where- i = 0,..., numberOfPoints-1,
- alpha[i] = (i - (numberOfPoints-1)/2.0) / ((numberOfPoints-1)/2.0),
- mean =
getAverage()
, - sigma =
getStandardDeviation()
.
result
is an array of two vectors, where result[0] are the intervals center points ('anchor points') and result[1] contains the relative frequency for the interval. The 'anchor point' for the interval (-infinity, x[0]) is x[0] - 1/2 (x[1]-x[0]) and the 'anchor point' for the interval (x[n], infinity) is x[n] + 1/2 (x[n]-x[n-1]). Here n = numberOfPoints is the number of interval points.- Parameters:
numberOfPoints
- The number of interval points.standardDeviations
- The number of standard deviations defining the discretization radius.- Returns:
- A histogram, given as double[2][], where result[0] are the center point of the intervals and result[1] is the value of
getHistogram(double[])
for the given the interval points. The length of result[0] and result[1] is numberOfPoints+1.
-
cache
RandomVariable cache()Return a cacheable version of this object (often a self-reference). This method should be called when you store the object for later use, i.e., assign it, or when the object is consumed in a function, but later used also in another function.- Returns:
- A cacheable version of this object (often a self-reference).
-
appy
Applies x → operator(x) to this random variable. It returns a new random variable with the result.- Parameters:
operator
- An unary operator/function, mapping RandomVariable to RandomVariable.- Returns:
- New random variable with the result of the function.
-
apply
Applies x → operator(x) to this random variable. It returns a new random variable with the result.- Parameters:
operator
- An unary operator/function, mapping double to double.- Returns:
- New random variable with the result of the function.
-
apply
Applies x → operator(x,y) to this random variable, where x is this random variable and y is a given random variable. It returns a new random variable with the result.- Parameters:
operator
- A binary operator/function, mapping (double,double) to double.argument
- A random variable.- Returns:
- New random variable with the result of the function.
-
apply
RandomVariable apply(DoubleTernaryOperator operator, RandomVariable argument1, RandomVariable argument2)Applies x → operator(x,y,z) to this random variable, where x is this random variable and y and z are given random variable. It returns a new random variable with the result.- Parameters:
operator
- A ternary operator/function, mapping (double,double,double) to double.argument1
- A random variable representing y.argument2
- A random variable representing z.- Returns:
- New random variable with the result of the function.
-
cap
Applies x → min(x,cap) to this random variable. It returns a new random variable with the result.- Parameters:
cap
- The cap.- Returns:
- New random variable with the result of the function.
-
floor
Applies x → max(x,floor) to this random variable. It returns a new random variable with the result.- Parameters:
floor
- The floor.- Returns:
- New random variable with the result of the function.
-
add
Applies x → x + value to this random variable. It returns a new random variable with the result.- Parameters:
value
- The value to add.- Returns:
- New random variable with the result of the function.
-
sub
Applies x → x - value to this random variable.- Parameters:
value
- The value to subtract.- Returns:
- New random variable with the result of the function.
-
bus
Applies x → value - x to this random variable.- Parameters:
value
- The value from which this is subtracted.- Returns:
- New random variable with the result of the function.
-
mult
Applies x → x * value to this random variable.- Parameters:
value
- The value to multiply.- Returns:
- New random variable with the result of the function.
-
div
Applies x → x / value to this random variable.- Parameters:
value
- The value to divide.- Returns:
- New random variable with the result of the function.
-
vid
Applies x → value / x to this random variable.- Parameters:
value
- The numerator of the ratio where this is the denominator.- Returns:
- New random variable with the result of the function.
-
pow
Applies x → pow(x,exponent) to this random variable.- Parameters:
exponent
- The exponent.- Returns:
- New random variable with the result of the function.
-
average
RandomVariable average()Returns a random variable which is deterministic and corresponds the expectation of this random variable.- Returns:
- New random variable being the expectation of this random variable.
-
expectation
Returns a random variable which is deterministic and corresponds the expectation of this random variable.- Returns:
- New random variable being the expectation of this random variable.
-
variance
Returns a random variable which is deterministic and corresponds the variance of this random variable. Note: The default implementation is a biased estimator. Use the factor n/(n-1) to convert to an unbiased estimator.- Returns:
- New random variable being the variance of this random variable and the argument.
-
covariance
Returns a random variable which is deterministic and corresponds the covariance of this random variable and the argument. Note: The default implementation is a biased estimator. Use the factor n/(n-1) to convert to an unbiased estimator.- Parameters:
value
- The random variable Y to be used in Cov(X,Y) with X being this.- Returns:
- New random variable being the covariance of this random variable and the argument.
-
getConditionalExpectation
default RandomVariable getConditionalExpectation(ConditionalExpectationEstimator conditionalExpectationOperator)Returns the conditional expectation using a given conditional expectation estimator.- Parameters:
conditionalExpectationOperator
- A given conditional expectation estimator.- Returns:
- The conditional expectation of this random variable (as a random variable)
-
squared
RandomVariable squared()Applies x → x * x to this random variable.- Returns:
- New random variable with the result of the function.
-
sqrt
RandomVariable sqrt()Applies x → sqrt(x) to this random variable.- Returns:
- New random variable with the result of the function.
-
exp
RandomVariable exp()Applies x → exp(x) to this random variable.- Returns:
- New random variable with the result of the function.
-
expm1
Applies x → expm1(x) (that is x → exp(x)-1.0) to this random variable.- Returns:
- New random variable with the result of the function.
-
log
RandomVariable log()Applies x → log(x) to this random variable.- Returns:
- New random variable with the result of the function.
-
sin
RandomVariable sin()Applies x → sin(x) to this random variable.- Returns:
- New random variable with the result of the function.
-
cos
RandomVariable cos()Applies x → cos(x) to this random variable.- Returns:
- New random variable with the result of the function.
-
add
Applies x → x+randomVariable to this random variable.- Parameters:
randomVariable
- A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
sub
Applies x → x-randomVariable to this random variable.- Parameters:
randomVariable
- A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
bus
Applies x → randomVariable-x to this random variable.- Parameters:
randomVariable
- A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
mult
Applies x → x*randomVariable to this random variable.- Parameters:
randomVariable
- A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
div
Applies x → x/randomVariable to this random variable.- Parameters:
randomVariable
- A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
vid
Applies x → randomVariable/x to this random variable.- Parameters:
randomVariable
- A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
cap
Applies x → min(x,cap) to this random variable.- Parameters:
cap
- The cap. A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
floor
Applies x → max(x,floor) to this random variable.- Parameters:
floor
- The floor. A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
accrue
Applies x → x * (1.0 + rate * periodLength) to this random variable.- Parameters:
rate
- The accruing rate. A random variable (compatible with this random variable).periodLength
- The period length- Returns:
- New random variable with the result of the function.
-
discount
Applies x → x / (1.0 + rate * periodLength) to this random variable.- Parameters:
rate
- The discounting rate. A random variable (compatible with this random variable).periodLength
- The period length- Returns:
- New random variable with the result of the function.
-
choose
RandomVariable choose(RandomVariable valueIfTriggerNonNegative, RandomVariable valueIfTriggerNegative)Applies x → (x ≥ 0 ? valueIfTriggerNonNegative : valueIfTriggerNegative)- Parameters:
valueIfTriggerNonNegative
- The value used if this is greater or equal 0valueIfTriggerNegative
- The value used if the this is less than 0- Returns:
- New random variable with the result of the function.
-
invert
RandomVariable invert()Applies x → 1/x to this random variable.- Returns:
- New random variable with the result of the function.
-
abs
RandomVariable abs()Applies x → Math.abs(x), i.e. x → |x| to this random variable.- Returns:
- New random variable with the result of the function.
-
addProduct
Applies x → x + factor1 * factor2- Parameters:
factor1
- The factor 1. A random variable (compatible with this random variable).factor2
- The factor 2.- Returns:
- New random variable with the result of the function.
-
addProduct
Applies x → x + factor1 * factor2- Parameters:
factor1
- The factor 1. A random variable (compatible with this random variable).factor2
- The factor 2. A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
addRatio
Applies x → x + numerator / denominator- Parameters:
numerator
- The numerator of the ratio to add. A random variable (compatible with this random variable).denominator
- The denominator of the ratio to add. A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
subRatio
Applies x → x - numerator / denominator- Parameters:
numerator
- The numerator of the ratio to sub. A random variable (compatible with this random variable).denominator
- The denominator of the ratio to sub. A random variable (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
addSumProduct
Applies \( x \mapsto x + \sum_{i=0}^{n-1} factor1_{i} * factor2_{i}- Parameters:
factor1
- The factor 1. A list of random variables (compatible with this random variable).factor2
- The factor 2. A list of random variables (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
addSumProduct
Applies \( x \mapsto x + \sum_{i=0}^{n-1} factor1_{i} * factor2_{i}- Parameters:
factor1
- The factor 1. A list of random variables (compatible with this random variable).factor2
- The factor 2. A list of random variables (compatible with this random variable).- Returns:
- New random variable with the result of the function.
-
isNaN
RandomVariable isNaN()Applies x → (Double.isNaN(x) ? 1.0 : 0.0)- Returns:
- A random variable which is 1.0 for all states that are NaN, otherwise 0.0.
-