net.finmath.montecarlo.interestrate.modelplugins.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.modelplugins;
import java.util.ArrayList;
import net.finmath.montecarlo.AbstractRandomVariableFactory;
import net.finmath.montecarlo.RandomVariableFactory;
import net.finmath.stochastic.RandomVariableInterface;
import net.finmath.time.TimeDiscretizationInterface;
/**
* Implements a simple volatility model using given piece-wise constant values on
* a given discretization grid.
*
* @author Christian Fries
*/
public class LIBORVolatilityModelFromGivenMatrix extends LIBORVolatilityModel {
private static final long serialVersionUID = -8017326082950665302L;
private final AbstractRandomVariableFactory randomVariableFactory;
private final double[][] volatilityMatrix;
/**
* A cache for the parameter associated with this model, it is only used when getParameter is
* called repeatedly.
*/
private transient double[] parameter;
// A lazy init cache
private transient RandomVariableInterface[][] volatility;
/**
* 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 timeDiscretization and componentIndex from liborPeriodDiscretization
*/
public LIBORVolatilityModelFromGivenMatrix(
AbstractRandomVariableFactory randomVariableFactory,
TimeDiscretizationInterface timeDiscretization,
TimeDiscretizationInterface liborPeriodDiscretization,
double[][] volatility) {
super(timeDiscretization, liborPeriodDiscretization);
this.randomVariableFactory = randomVariableFactory;
this.volatilityMatrix = volatility;
this.volatility = new RandomVariableInterface[timeDiscretization.getNumberOfTimeSteps()][liborPeriodDiscretization.getNumberOfTimeSteps()];
}
/**
* 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 timeDiscretization and componentIndex from liborPeriodDiscretization
*/
public LIBORVolatilityModelFromGivenMatrix(
TimeDiscretizationInterface timeDiscretization,
TimeDiscretizationInterface liborPeriodDiscretization,
double[][] volatility) {
this(new RandomVariableFactory(), timeDiscretization, liborPeriodDiscretization, volatility);
}
/* (non-Javadoc)
* @see net.finmath.montecarlo.interestrate.modelplugins.LIBORVolatilityModel#getVolatility(int, int)
*/
@Override
public RandomVariableInterface getVolatility(int timeIndex, int component) {
synchronized (volatility) {
if(volatility[timeIndex][component] == null) {
volatility[timeIndex][component] = randomVariableFactory.createRandomVariable(getTimeDiscretization().getTime(timeIndex), volatilityMatrix[timeIndex][component]);
}
}
return volatility[timeIndex][component];
}
@Override
public double[] getParameter() {
synchronized (this) {
if(parameter == null) {
ArrayList parameterArray = new ArrayList();
for(int timeIndex = 0; timeIndex
© 2015 - 2025 Weber Informatics LLC | Privacy Policy