net.finmath.stochastic.Scalar 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 12.08.2017
*/
package net.finmath.stochastic;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleUnaryOperator;
import java.util.function.IntToDoubleFunction;
import java.util.stream.DoubleStream;
import net.finmath.functions.DoubleTernaryOperator;
/**
* A scalar value implementing the RandomVariable.
*
* @author Christian Fries
* @version 1.0
*/
public class Scalar implements RandomVariable {
private static final long serialVersionUID = -729437972787062992L;
private final double value;
public Scalar(final double value) {
super();
this.value = value;
// if(Double.isNaN(value)) {
// throw new ArithmeticException("Not a Numbber");
// }
}
public static Scalar[] arrayOf(final double[] arrayOfDoubles) {
final Scalar[] array = new Scalar[arrayOfDoubles.length];
for(int i=0; i= 0) {
return valueIfTriggerNonNegative;
} else {
return valueIfTriggerNegative;
}
}
@Override
public RandomVariable invert() {
return new Scalar(1.0/value);
}
@Override
public RandomVariable abs() {
return new Scalar(Math.abs(value));
}
@Override
public RandomVariable addProduct(final RandomVariable factor1, final double factor2) {
return factor1.mult(factor2).add(value);
}
@Override
public RandomVariable addProduct(final RandomVariable factor1, final RandomVariable factor2) {
return factor1.mult(factor2).add(value);
}
@Override
public RandomVariable addRatio(final RandomVariable numerator, final RandomVariable denominator) {
return numerator.div(denominator).add(value);
}
@Override
public RandomVariable subRatio(final RandomVariable numerator, final RandomVariable denominator) {
return numerator.div(denominator).sub(value).mult(-1.0);
}
@Override
public RandomVariable isNaN() {
return new Scalar(Double.isNaN(value) ? 1.0 : 0.0);
}
}