net.finmath.stochastic.RandomVariableArrayImplementation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of finmath-lib Show documentation
Show all versions of finmath-lib Show documentation
finmath lib is a Mathematical Finance Library in Java.
It provides algorithms and methodologies related to mathematical finance.
/*
* (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
*
* Created on 09.02.2009
*/
package net.finmath.stochastic;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleUnaryOperator;
import java.util.function.Function;
import java.util.function.IntToDoubleFunction;
import java.util.stream.DoubleStream;
import net.finmath.functions.DoubleTernaryOperator;
/**
* An implementation of RandomVariableArray
implementing an array of RandomVariable
objects,
* implementing the RandomVariable
interface.
*
* @author Christian Fries
*/
public class RandomVariableArrayImplementation implements RandomVariableArray {
private static final long serialVersionUID = -5718980901166760522L;
private final RandomVariable[] elements;
public static RandomVariableArray of(final RandomVariable[] elements) {
return new RandomVariableArrayImplementation(elements.clone());
}
private RandomVariableArrayImplementation(final RandomVariable[] elements) {
super();
if(elements.length == 0) {
throw new IllegalArgumentException("Empty array.");
}
// Ensure that all elements
final int level = getLevel(elements[0]);
for(int i=1; i operator) {
final RandomVariable[] newElments = new RandomVariable[getNumberOfElements()];
for(int i=1; i() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.apply(operator);
}
});
}
@Override
public RandomVariable apply(final DoubleBinaryOperator operator, final RandomVariable argument) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.apply(operator, argument);
}
});
}
@Override
public RandomVariable apply(final DoubleTernaryOperator operator, final RandomVariable argument1, final RandomVariable argument2) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.apply(operator, argument1, argument2);
}
});
}
@Override
public RandomVariable cap(final double cap) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.cap(cap);
}
});
}
@Override
public RandomVariable floor(final double floor) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.floor(floor);
}
});
}
@Override
public RandomVariable add(final double value) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.add(value);
}
});
}
@Override
public RandomVariable sub(final double value) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.sub(value);
}
});
}
@Override
public RandomVariable mult(final double value) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.mult(value);
}
});
}
@Override
public RandomVariable div(final double value) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.div(value);
}
});
}
@Override
public RandomVariable pow(final double exponent) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.pow(exponent);
}
});
}
@Override
public RandomVariable average() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.average();
}
});
}
@Override
public RandomVariable squared() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.squared();
}
});
}
@Override
public RandomVariable sqrt() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.sqrt();
}
});
}
@Override
public RandomVariable exp() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.exp();
}
});
}
@Override
public RandomVariable log() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.log();
}
});
}
@Override
public RandomVariable sin() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.sin();
}
});
}
@Override
public RandomVariable cos() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.cos();
}
});
}
@Override
public RandomVariable add(final RandomVariable randomVariable) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.add(randomVariable);
}
});
}
@Override
public RandomVariable sub(final RandomVariable randomVariable) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.sub(randomVariable);
}
});
}
@Override
public RandomVariable bus(final RandomVariable randomVariable) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.bus(randomVariable);
}
});
}
@Override
public RandomVariable mult(final RandomVariable randomVariable) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.mult(randomVariable);
}
});
}
@Override
public RandomVariable div(final RandomVariable randomVariable) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.div(randomVariable);
}
});
}
@Override
public RandomVariable vid(final RandomVariable randomVariable) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.vid(randomVariable);
}
});
}
@Override
public RandomVariable cap(final RandomVariable cap) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.cap(cap);
}
});
}
@Override
public RandomVariable floor(final RandomVariable floor) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.cap(floor);
}
});
}
@Override
public RandomVariable accrue(final RandomVariable rate, final double periodLength) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.accrue(rate, periodLength);
}
});
}
@Override
public RandomVariable discount(final RandomVariable rate, final double periodLength) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.discount(rate, periodLength);
}
});
}
@Override
public RandomVariable choose(final RandomVariable valueIfTriggerNonNegative, final RandomVariable valueIfTriggerNegative) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.choose(valueIfTriggerNonNegative, valueIfTriggerNegative);
}
});
}
@Override
public RandomVariable invert() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.invert();
}
});
}
@Override
public RandomVariable abs() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.abs();
}
});
}
@Override
public RandomVariable addProduct(final RandomVariable factor1, final double factor2) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.addProduct(factor1, factor2);
}
});
}
@Override
public RandomVariable addProduct(final RandomVariable factor1, final RandomVariable factor2) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.addProduct(factor1, factor2);
}
});
}
@Override
public RandomVariable addRatio(final RandomVariable numerator, final RandomVariable denominator) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.addRatio(numerator, denominator);
}
});
}
@Override
public RandomVariable subRatio(final RandomVariable numerator, final RandomVariable denominator) {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.subRatio(numerator, denominator);
}
});
}
@Override
public RandomVariable isNaN() {
return map(new Function() {
@Override
public RandomVariable apply(final RandomVariable x) {
return x.isNaN();
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy