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;
private RandomVariableArrayImplementation(RandomVariable[] elements) {
super();
if(elements.length == 0) throw new IllegalArgumentException("Empty array.");
// Ensure that all elements
int level = getLevel(elements[0]);
for(int i=1; i operator) {
RandomVariable[] newElments = new RandomVariable[getNumberOfElements()];
for(int i=1; i x.apply(operator));
}
@Override
public RandomVariable apply(DoubleBinaryOperator operator, RandomVariable argument) {
return map(x -> x.apply(operator, argument));
}
@Override
public RandomVariable apply(DoubleTernaryOperator operator, RandomVariable argument1, RandomVariable argument2) {
return map(x -> x.apply(operator, argument1, argument2));
}
@Override
public RandomVariable cap(double cap) {
return map(x -> x.cap(cap));
}
@Override
public RandomVariable floor(double floor) {
return map(x -> x.floor(floor));
}
@Override
public RandomVariable add(double value) {
return map(x -> x.add(value));
}
@Override
public RandomVariable sub(double value) {
return map(x -> x.sub(value));
}
@Override
public RandomVariable mult(double value) {
return map(x -> x.mult(value));
}
@Override
public RandomVariable div(double value) {
return map(x -> x.div(value));
}
@Override
public RandomVariable pow(double exponent) {
return map(x -> x.pow(exponent));
}
@Override
public RandomVariable average() {
return map(x -> x.average());
}
@Override
public RandomVariable squared() {
return map(x -> x.squared());
}
@Override
public RandomVariable sqrt() {
return map(x -> x.sqrt());
}
@Override
public RandomVariable exp() {
return map(x -> x.exp());
}
@Override
public RandomVariable log() {
return map(x -> x.log());
}
@Override
public RandomVariable sin() {
return map(x -> x.sin());
}
@Override
public RandomVariable cos() {
return map(x -> x.cos());
}
@Override
public RandomVariable add(RandomVariable randomVariable) {
return map(x -> x.add(randomVariable));
}
@Override
public RandomVariable sub(RandomVariable randomVariable) {
return map(x -> x.sub(randomVariable));
}
@Override
public RandomVariable bus(RandomVariable randomVariable) {
return map(x -> x.bus(randomVariable));
}
@Override
public RandomVariable mult(RandomVariable randomVariable) {
return map(x -> x.mult(randomVariable));
}
@Override
public RandomVariable div(RandomVariable randomVariable) {
return map(x -> x.div(randomVariable));
}
@Override
public RandomVariable vid(RandomVariable randomVariable) {
return map(x -> x.vid(randomVariable));
}
@Override
public RandomVariable cap(RandomVariable cap) {
return map(x -> x.cap(cap));
}
@Override
public RandomVariable floor(RandomVariable floor) {
return map(x -> x.cap(floor));
}
@Override
public RandomVariable accrue(RandomVariable rate, double periodLength) {
return map(x -> x.accrue(rate, periodLength));
}
@Override
public RandomVariable discount(RandomVariable rate, double periodLength) {
return map(x -> x.discount(rate, periodLength));
}
@Override
public RandomVariable choose(RandomVariable valueIfTriggerNonNegative, RandomVariable valueIfTriggerNegative) {
return map(x -> x.choose(valueIfTriggerNonNegative, valueIfTriggerNegative));
}
@Override
public RandomVariable invert() {
return map(x -> x.invert());
}
@Override
public RandomVariable abs() {
return map(x -> x.abs());
}
@Override
public RandomVariable addProduct(RandomVariable factor1, double factor2) {
return map(x -> x.addProduct(factor1, factor2));
}
@Override
public RandomVariable addProduct(RandomVariable factor1, RandomVariable factor2) {
return map(x -> x.addProduct(factor1, factor2));
}
@Override
public RandomVariable addRatio(RandomVariable numerator, RandomVariable denominator) {
return map(x -> x.addRatio(numerator, denominator));
}
@Override
public RandomVariable subRatio(RandomVariable numerator, RandomVariable denominator) {
return map(x -> x.subRatio(numerator, denominator));
}
@Override
public RandomVariable isNaN() {
return map(x -> x.isNaN());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy