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;
final double value;
public Scalar(double value) {
super();
this.value = value;
}
public static Scalar[] arrayOf(double[] arrayOfDoubles) {
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(RandomVariable factor1, double factor2) {
return factor1.mult(factor2).add(value);
}
@Override
public RandomVariable addProduct(RandomVariable factor1, RandomVariable factor2) {
return factor1.mult(factor2).add(value);
}
@Override
public RandomVariable addRatio(RandomVariable numerator, RandomVariable denominator) {
return numerator.div(denominator).add(value);
}
@Override
public RandomVariable subRatio(RandomVariable numerator, 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);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy