net.finmath.montecarlo.interestrate.models.covariance.LIBORVolatilityModelTwoParameterExponentialForm Maven / Gradle / Ivy
/*
* (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
*
* Created on 08.08.2005
*/
package net.finmath.montecarlo.interestrate.models.covariance;
import java.util.Map;
import net.finmath.montecarlo.AbstractRandomVariableFactory;
import net.finmath.montecarlo.RandomVariableFactory;
import net.finmath.stochastic.RandomVariable;
import net.finmath.time.TimeDiscretization;
/**
* Implements the volatility model σi(tj) = a * exp(-b (Ti-tj))
*
* @author Christian Fries
* @version 1.0
*/
public class LIBORVolatilityModelTwoParameterExponentialForm extends LIBORVolatilityModel {
private static final long serialVersionUID = 8398006103722351360L;
private final AbstractRandomVariableFactory randomVariableFactory;
private RandomVariable a;
private RandomVariable b;
private boolean isCalibrateable = false;
// A lazy init cache
private transient RandomVariable[][] volatility;
private Object volatilityLazyInitLock = new Object();
/**
* Creates the volatility model σi(tj) = a * exp(-b (Ti-tj))
*
* @param randomVariableFactory The random variable factor used to construct random variables from the parameters.
* @param timeDiscretization The simulation time discretization tj.
* @param liborPeriodDiscretization The period time discretization Ti.
* @param a The parameter a: an initial volatility level.
* @param b The parameter b: exponential decay of the volatility.
* @param isCalibrateable Set this to true, if the parameters are available for calibration.
*/
public LIBORVolatilityModelTwoParameterExponentialForm(AbstractRandomVariableFactory randomVariableFactory, TimeDiscretization timeDiscretization, TimeDiscretization liborPeriodDiscretization, RandomVariable a, RandomVariable b, boolean isCalibrateable) {
super(timeDiscretization, liborPeriodDiscretization);
this.randomVariableFactory = randomVariableFactory;
this.a = a;
this.b = b;
this.isCalibrateable = isCalibrateable;
}
/**
* Creates the volatility model σi(tj) = a * exp(-b (Ti-tj))
*
* @param randomVariableFactory The random variable factor used to construct random variables from the parameters.
* @param timeDiscretization The simulation time discretization tj.
* @param liborPeriodDiscretization The period time discretization Ti.
* @param a The parameter a: an initial volatility level.
* @param b The parameter b: exponential decay of the volatility.
* @param isCalibrateable Set this to true, if the parameters are available for calibration.
*/
public LIBORVolatilityModelTwoParameterExponentialForm(AbstractRandomVariableFactory randomVariableFactory, TimeDiscretization timeDiscretization, TimeDiscretization liborPeriodDiscretization, double a, double b, boolean isCalibrateable) {
this(randomVariableFactory, timeDiscretization, liborPeriodDiscretization, randomVariableFactory.createRandomVariable(a), randomVariableFactory.createRandomVariable(b), isCalibrateable);
}
/**
* Creates the volatility model σi(tj) = a * exp(-b (Ti-tj))
*
* @param timeDiscretization The simulation time discretization tj.
* @param liborPeriodDiscretization The period time discretization Ti.
* @param a The parameter a: an initial volatility level.
* @param b The parameter b: exponential decay of the volatility.
*/
public LIBORVolatilityModelTwoParameterExponentialForm(TimeDiscretization timeDiscretization, TimeDiscretization liborPeriodDiscretization, double a, double b) {
this(new RandomVariableFactory(), timeDiscretization, liborPeriodDiscretization, a, b, true);
}
@Override
public RandomVariable[] getParameter() {
if(!isCalibrateable) {
return null;
}
RandomVariable[] parameter = new RandomVariable[2];
parameter[0] = a;
parameter[1] = b;
return parameter;
}
@Override
public LIBORVolatilityModelTwoParameterExponentialForm getCloneWithModifiedParameter(RandomVariable[] parameter) {
if(!isCalibrateable) {
return this;
}
return new LIBORVolatilityModelTwoParameterExponentialForm(
randomVariableFactory,
getTimeDiscretization(),
getLiborPeriodDiscretization(),
parameter[0],
parameter[1],
isCalibrateable
);
}
@Override
public RandomVariable getVolatility(int timeIndex, int liborIndex) {
synchronized (volatilityLazyInitLock) {
if(volatility == null) {
volatility = new RandomVariable[getTimeDiscretization().getNumberOfTimeSteps()][getLiborPeriodDiscretization().getNumberOfTimeSteps()];
}
if(volatility[timeIndex][liborIndex] == null) {
double time = getTimeDiscretization().getTime(timeIndex);
double maturity = getLiborPeriodDiscretization().getTime(liborIndex);
double timeToMaturity = maturity-time;
RandomVariable volatilityInstanteaneous;
if(timeToMaturity <= 0)
{
volatilityInstanteaneous = randomVariableFactory.createRandomVariable(0.0); // This forward rate is already fixed, no volatility
}
else
{
volatilityInstanteaneous = a.mult(b.mult(-timeToMaturity).exp());
}
volatility[timeIndex][liborIndex] = volatilityInstanteaneous;
}
return volatility[timeIndex][liborIndex];
}
}
@Override
public Object clone() {
return new LIBORVolatilityModelTwoParameterExponentialForm(
randomVariableFactory,
getTimeDiscretization(),
getLiborPeriodDiscretization(),
a,
b,
isCalibrateable
);
}
@Override
public LIBORVolatilityModel getCloneWithModifiedData(Map dataModified) {
// TODO Auto-generated method stub
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy