net.finmath.montecarlo.interestrate.modelplugins.AbstractLIBORCovarianceModel 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.io.Serializable;
import net.finmath.stochastic.RandomVariableInterface;
import net.finmath.time.TimeDiscretizationInterface;
/**
* A base class and interface description for the instantaneous covariance of
* an forward rate interest rate model.
*
* @author Christian Fries
*/
public abstract class AbstractLIBORCovarianceModel implements Serializable {
private static final long serialVersionUID = 5364544247367259329L;
private TimeDiscretizationInterface timeDiscretization;
private TimeDiscretizationInterface liborPeriodDiscretization;
private int numberOfFactors;
/**
* Constructor consuming time discretizations, which are handled by the super class.
*
* @param timeDiscretization The vector of simulation time discretization points.
* @param liborPeriodDiscretization The vector of tenor discretization points.
* @param numberOfFactors The number of factors to use (a factor reduction is performed)
*/
public AbstractLIBORCovarianceModel(TimeDiscretizationInterface timeDiscretization, TimeDiscretizationInterface liborPeriodDiscretization, int numberOfFactors) {
super();
this.timeDiscretization = timeDiscretization;
this.liborPeriodDiscretization = liborPeriodDiscretization;
this.numberOfFactors = numberOfFactors;
}
/**
* Return the factor loading for a given time and a given component.
*
* The factor loading is the vector fi such that the scalar product
* fjfk = fj,1fk,1 + ... + fj,mfk,m
* is the instantaneous covariance of the component j and k.
*
* With respect to simulation time t, this method uses a piece wise constant interpolation, i.e.,
* it calculates t_i such that t_i is the largest point in getTimeDiscretization
* such that t_i ≤ t .
*
* The component here, it given via a double T which may be associated with the LIBOR fixing date.
* With respect to component time T, this method uses a piece wise constant interpolation, i.e.,
* it calculates T_j such that T_j is the largest point in getTimeDiscretization
* such that T_j ≤ T .
*
* @param time The time t at which factor loading is requested.
* @param component The component time (as a double associated with the fixing of the forward rate) Ti.
* @param realizationAtTimeIndex The realization of the stochastic process (may be used to implement local volatility/covariance/correlation models).
* @return The factor loading fi(t).
*/
public RandomVariableInterface[] getFactorLoading(double time, double component, RandomVariableInterface[] realizationAtTimeIndex) {
int componentIndex = liborPeriodDiscretization.getTimeIndex(component);
if(componentIndex < 0) componentIndex = -componentIndex - 2;
return getFactorLoading(time, componentIndex, realizationAtTimeIndex);
}
/**
* Return the factor loading for a given time and component index.
* The factor loading is the vector fi such that the scalar product
* fjfk = fj,1fk,1 + ... + fj,mfk,m
* is the instantaneous covariance of the component j and k.
*
* With respect to simulation time t, this method uses a piece wise constant interpolation, i.e.,
* it calculates t_i such that t_i is the largest point in getTimeDiscretization
* such that t_i ≤ t .
*
* @param time The time t at which factor loading is requested.
* @param component The index of the component i. Note that this class may have its own LIBOR time discretization and that this index refers to this discretization.
* @param realizationAtTimeIndex The realization of the stochastic process (may be used to implement local volatility/covariance/correlation models).
* @return The factor loading fi(t).
*/
public RandomVariableInterface[] getFactorLoading(double time, int component, RandomVariableInterface[] realizationAtTimeIndex) {
int timeIndex = timeDiscretization.getTimeIndex(time);
if(timeIndex < 0) timeIndex = -timeIndex - 2;
return getFactorLoading(timeIndex, component, realizationAtTimeIndex);
}
/**
* Return the factor loading for a given time index and component index.
* The factor loading is the vector fi such that the scalar product
* fjfk = fj,1fk,1 + ... + fj,mfk,m
* is the instantaneous covariance of the component j and k.
*
* @param timeIndex The time index at which factor loading is requested.
* @param component The index of the component i.
* @param realizationAtTimeIndex The realization of the stochastic process (may be used to implement local volatility/covariance/correlation models).
* @return The factor loading fi(t).
*/
public abstract RandomVariableInterface[] getFactorLoading(int timeIndex, int component, RandomVariableInterface[] realizationAtTimeIndex);
/**
* Returns the pseudo inverse of the factor matrix.
*
* @param timeIndex The time index at which factor loading inverse is requested.
* @param factor The index of the factor j.
* @param component The index of the component i.
* @param realizationAtTimeIndex The realization of the stochastic process (may be used to implement local volatility/covariance/correlation models).
* @return The entry of the pseudo-inverse of the factor loading matrix.
*/
public abstract RandomVariableInterface getFactorLoadingPseudoInverse(int timeIndex, int component, int factor, RandomVariableInterface[] realizationAtTimeIndex);
/**
* Returns the instantaneous covariance calculated from factor loadings.
*
* @param time The time t at which covariance is requested.
* @param component1 Index of component i.
* @param component2 Index of component j.
* @param realizationAtTimeIndex The realization of the stochastic process.
* @return The instantaneous covariance between component i and j.
*/
public RandomVariableInterface getCovariance(double time, int component1, int component2, RandomVariableInterface[] realizationAtTimeIndex) {
int timeIndex = timeDiscretization.getTimeIndex(time);
if(timeIndex < 0) timeIndex = Math.abs(timeIndex)-2;
return getCovariance(timeIndex, component1, component2, realizationAtTimeIndex);
}
/**
* Returns the instantaneous covariance calculated from factor loadings.
*
* @param timeIndex The time index at which covariance is requested.
* @param component1 Index of component i.
* @param component2 Index of component j.
* @param realizationAtTimeIndex The realization of the stochastic process.
* @return The instantaneous covariance between component i and j.
*/
public RandomVariableInterface getCovariance(int timeIndex, int component1, int component2, RandomVariableInterface[] realizationAtTimeIndex) {
RandomVariableInterface[] factorLoadingOfComponent1 = getFactorLoading(timeIndex, component1, realizationAtTimeIndex);
RandomVariableInterface[] factorLoadingOfComponent2 = getFactorLoading(timeIndex, component2, realizationAtTimeIndex);
// Multiply first factor loading (this avoids that we have to init covariance to 0).
RandomVariableInterface covariance = factorLoadingOfComponent1[0].mult(factorLoadingOfComponent2[0]);
// Add others, if any
for(int factorIndex=1; factorIndex
© 2015 - 2025 Weber Informatics LLC | Privacy Policy