net.finmath.montecarlo.interestrate.models.covariance.LIBORVolatilityModelFromGivenMatrix 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.models.covariance;
import java.util.ArrayList;
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 a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @author Christian Fries
* @version 1.0
*/
public class LIBORVolatilityModelFromGivenMatrix extends LIBORVolatilityModel {
private static final long serialVersionUID = -8017326082950665302L;
private final AbstractRandomVariableFactory randomVariableFactory;
private final RandomVariable[][] volatility;
private final boolean isCalibrateable;
/**
* A cache for the parameter associated with this model, it is only used when getParameter is called repeatedly.
*/
private transient RandomVariable[] parameter;
/**
* Creates a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @param randomVariableFactory The random variable factor used to construct random variables from the parameters.
* @param timeDiscretization Discretization of simulation time.
* @param liborPeriodDiscretization Discretization of tenor times.
* @param volatility Volatility matrix volatility[timeIndex][componentIndex] where timeIndex the index of the start time in timeDiscretizationFromArray and componentIndex from liborPeriodDiscretization
* @param isCalibrateable Set this to true, if the parameters are available for calibration.
*/
public LIBORVolatilityModelFromGivenMatrix(
AbstractRandomVariableFactory randomVariableFactory,
TimeDiscretization timeDiscretization,
TimeDiscretization liborPeriodDiscretization,
RandomVariable[][] volatility,
boolean isCalibrateable) {
super(timeDiscretization, liborPeriodDiscretization);
this.randomVariableFactory = randomVariableFactory;
this.volatility = volatility.clone();
this.isCalibrateable = isCalibrateable;
}
/**
* Creates a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @param timeDiscretization Discretization of simulation time.
* @param liborPeriodDiscretization Discretization of tenor times.
* @param volatility Volatility matrix volatility[timeIndex][componentIndex] where timeIndex the index of the start time in timeDiscretizationFromArray and componentIndex from liborPeriodDiscretization
* @param isCalibrateable Set this to true, if the parameters are available for calibration.
*/
public LIBORVolatilityModelFromGivenMatrix(
TimeDiscretization timeDiscretization,
TimeDiscretization liborPeriodDiscretization,
RandomVariable[][] volatility,
boolean isCalibrateable) {
super(timeDiscretization, liborPeriodDiscretization);
randomVariableFactory = new RandomVariableFactory();
this.volatility = volatility.clone();
this.isCalibrateable = isCalibrateable;
}
/**
* Creates a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @param timeDiscretization Discretization of simulation time.
* @param liborPeriodDiscretization Discretization of tenor times.
* @param volatility Volatility matrix volatility[timeIndex][componentIndex] where timeIndex the index of the start time in timeDiscretizationFromArray and componentIndex from liborPeriodDiscretization
*/
public LIBORVolatilityModelFromGivenMatrix(
TimeDiscretization timeDiscretization,
TimeDiscretization liborPeriodDiscretization,
RandomVariable[][] volatility) {
this(timeDiscretization, liborPeriodDiscretization, volatility, false);
}
/**
* Creates a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @param randomVariableFactory The random variable factor used to construct random variables from the parameters.
* @param timeDiscretization Discretization of simulation time.
* @param liborPeriodDiscretization Discretization of tenor times.
* @param volatility Volatility matrix volatility[timeIndex][componentIndex] where timeIndex the index of the start time in timeDiscretizationFromArray and componentIndex from liborPeriodDiscretization
* @param isCalibrateable Set this to true, if the parameters are available for calibration.
*/
public LIBORVolatilityModelFromGivenMatrix(
AbstractRandomVariableFactory randomVariableFactory,
TimeDiscretization timeDiscretization,
TimeDiscretization liborPeriodDiscretization,
double[][] volatility,
boolean isCalibrateable) {
super(timeDiscretization, liborPeriodDiscretization);
this.randomVariableFactory = randomVariableFactory;
this.volatility = randomVariableFactory.createRandomVariableMatrix(volatility);
this.isCalibrateable = isCalibrateable;
}
/**
* Creates a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @param randomVariableFactory The random variable factor used to construct random variables from the parameters.
* @param timeDiscretization Discretization of simulation time.
* @param liborPeriodDiscretization Discretization of tenor times.
* @param volatility Volatility matrix volatility[timeIndex][componentIndex] where timeIndex the index of the start time in timeDiscretizationFromArray and componentIndex from liborPeriodDiscretization
*/
public LIBORVolatilityModelFromGivenMatrix(
AbstractRandomVariableFactory randomVariableFactory,
TimeDiscretization timeDiscretization,
TimeDiscretization liborPeriodDiscretization,
double[][] volatility) {
this(randomVariableFactory, timeDiscretization, liborPeriodDiscretization, volatility, true);
}
/**
* Creates a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @param timeDiscretization Discretization of simulation time.
* @param liborPeriodDiscretization Discretization of tenor times.
* @param volatility Volatility matrix volatility[timeIndex][componentIndex] where timeIndex the index of the start time in timeDiscretizationFromArray and componentIndex from liborPeriodDiscretization
*/
public LIBORVolatilityModelFromGivenMatrix(
TimeDiscretization timeDiscretization,
TimeDiscretization liborPeriodDiscretization,
double[][] volatility) {
this(new RandomVariableFactory(), timeDiscretization, liborPeriodDiscretization, volatility);
}
@Override
public RandomVariable getVolatility(int timeIndex, int component) {
return volatility[timeIndex][component];
}
@Override
public RandomVariable[] getParameter() {
synchronized (volatility) {
if(parameter == null) {
ArrayList parameterArray = new ArrayList();
for(int timeIndex = 0; timeIndex dataModified) {
AbstractRandomVariableFactory randomVariableFactory = null;
TimeDiscretization timeDiscretization = this.getTimeDiscretization();
TimeDiscretization liborPeriodDiscretization = this.getLiborPeriodDiscretization();
RandomVariable[][] volatility = this.volatility;
boolean isCalibrateable = this.isCalibrateable;
if(dataModified != null) {
// Explicitly passed covarianceModel has priority
randomVariableFactory = (AbstractRandomVariableFactory)dataModified.getOrDefault("randomVariableFactory", randomVariableFactory);
timeDiscretization = (TimeDiscretization)dataModified.getOrDefault("timeDiscretization", timeDiscretization);
liborPeriodDiscretization = (TimeDiscretization)dataModified.getOrDefault("liborPeriodDiscretization", liborPeriodDiscretization);
isCalibrateable = (boolean)dataModified.getOrDefault("isCalibrateable", isCalibrateable);
if(dataModified.containsKey("randomVariableFactory")) {
// Possible to do this using streams?
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy