net.finmath.fouriermethod.calibration.BoundConstraint 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.
The newest version!
package net.finmath.fouriermethod.calibration;
/**
* A class applying a bound constraint to a parameter.
*
* @author Alessandro Gnoatto
*
*/
public class BoundConstraint implements ScalarConstraint {
private final double lowerBound;
private final double upperBound;
public BoundConstraint(final double lowerBound, final double upperBound) {
super();
this.lowerBound = lowerBound;
this.upperBound = upperBound;
}
/**
* Return the lower bound.
* @return the lower bound.
*/
@Override
public double getLowerBound() {
return lowerBound;
}
/**
* Return the upper bound.
* @return the upper bound.
*/
@Override
public double getUpperBound() {
return upperBound;
}
@Override
public double apply(final double parameterToTest) {
if(parameterToTest > upperBound || parameterToTest < lowerBound) {
final double u = 1.0/(Math.exp(parameterToTest)+1.0); //maps R to to [0,1];
return lowerBound + u*(upperBound - lowerBound); //maps from [0,1] to [lowerBound, upperBound]
}else {
return parameterToTest;
}
}
}