All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.finmath.stochastic.Scalar Maven / Gradle / Ivy

Go to download

finmath lib is a Mathematical Finance Library in Java. It provides algorithms and methodologies related to mathematical finance.

There is a newer version: 6.0.19
Show newest version
/*
 * (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.1
 */
public class Scalar implements RandomVariable {

	private static final long serialVersionUID = -729437972787062992L;

	private final double value;

	public static Scalar of(final double value) {
		return new Scalar(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);
	}

	@Override
	public String toString() {
		return "Scalar [value=" + value + ", filtrationTime=" + getFiltrationTime() + ", typePriority()="
				+ getTypePriority() + "]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy