net.finmath.montecarlo.interestrate.modelplugins.LIBORCorrelationModelThreeParameterExponentialDecay 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 20.05.2006
*/
package net.finmath.montecarlo.interestrate.modelplugins;
import net.finmath.functions.LinearAlgebra;
import net.finmath.time.TimeDiscretizationInterface;
/**
* Simple correlation model given by R, where R is a factor reduced matrix
* (see {@link net.finmath.functions.LinearAlgebra#factorReduction(double[][], int)}) created from the
* \( n \) Eigenvectors of \( \tilde{R} \) belonging to the \( n \) largest non-negative Eigenvalues,
* where \( \tilde{R} = \tilde{\rho}_{i,j} \) and
* \[ \tilde{\rho}_{i,j} = b + (1-b) * \exp(-a |T_{i} - T_{j}| - c \max(T_{i},T_{j}))
*
* @see net.finmath.functions.LinearAlgebra#factorReduction(double[][], int)
*
* @author Christian Fries
*/
public class LIBORCorrelationModelThreeParameterExponentialDecay extends LIBORCorrelationModel {
private static final long serialVersionUID = 5063076041285957177L;
private int numberOfFactors;
private double a;
private double b;
private double c;
private final boolean isCalibrateable;
private transient double[][] correlationMatrix;
private transient double[][] factorMatrix;
public LIBORCorrelationModelThreeParameterExponentialDecay(TimeDiscretizationInterface timeDiscretization, TimeDiscretizationInterface liborPeriodDiscretization, int numberOfFactors, double a, double b, double c, boolean isCalibrateable) {
super(timeDiscretization, liborPeriodDiscretization);
this.numberOfFactors = numberOfFactors;
this.a = a;
this.b = b;
this.c = c;
this.isCalibrateable = isCalibrateable;
}
@Override
public double[] getParameter() {
if(!isCalibrateable) return null;
double[] parameter = new double[3];
parameter[0] = a;
parameter[1] = b;
parameter[2] = c;
return parameter;
}
@Override
public void setParameter(double[] parameter) {
if(!isCalibrateable) return;
a = parameter[0];
b = parameter[1];
c = parameter[2];
factorMatrix = null;
correlationMatrix = null;
}
@Override
public double getFactorLoading(int timeIndex, int factor, int component) {
if(factorMatrix == null) initialize(numberOfFactors, a, b, c);
return factorMatrix[component][factor];
}
@Override
public double getCorrelation(int timeIndex, int component1, int component2) {
if(correlationMatrix == null) initialize(numberOfFactors, a, b, c);
return correlationMatrix[component1][component2];
}
@Override
public int getNumberOfFactors() {
return numberOfFactors;
}
private synchronized void initialize(int numberOfFactors, double a, double b, double c) {
/*
* Create instantaneous correlation matrix
*/
a = Math.max(a, 0.0);
b = Math.min(Math.max(b, 0.0), 1.0);
c = Math.max(c, 0.0);
correlationMatrix = new double[liborPeriodDiscretization.getNumberOfTimeSteps()][liborPeriodDiscretization.getNumberOfTimeSteps()];
for(int row=0; row
© 2015 - 2025 Weber Informatics LLC | Privacy Policy