net.finmath.montecarlo.interestrate.models.covariance.TermStructCovarianceModelFromLIBORCovarianceModelParametric 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.
The newest version!
/*
* (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
*
* Created on 22.12.2016
*/
package net.finmath.montecarlo.interestrate.models.covariance;
import net.finmath.montecarlo.interestrate.TermStructureModel;
import net.finmath.stochastic.RandomVariable;
import net.finmath.time.TimeDiscretization;
/**
* @author Christian Fries
*
* @version 1.0
*/
public class TermStructCovarianceModelFromLIBORCovarianceModelParametric extends TermStructureCovarianceModelParametric {
private final TermStructureTenorTimeScaling tenorTimeScalingModel;
private final AbstractLIBORCovarianceModelParametric covarianceModel;
/**
* @param tenorTimeScalingModel The model used for the tenor time re-scaling (providing the scaling coefficients).
* @param covarianceModel The model implementing AbstractLIBORCovarianceModelParametric.
*/
public TermStructCovarianceModelFromLIBORCovarianceModelParametric(final TermStructureTenorTimeScaling tenorTimeScalingModel, final AbstractLIBORCovarianceModelParametric covarianceModel) {
this.tenorTimeScalingModel = tenorTimeScalingModel;
this.covarianceModel = covarianceModel;
}
@Override
public double getScaledTenorTime(final double periodStart, final double periodEnd) {
if(tenorTimeScalingModel == null) {
return periodEnd-periodStart;
}
return tenorTimeScalingModel.getScaledTenorTime(periodStart, periodEnd);
}
@Override
public RandomVariable[] getFactorLoading(final double time, final double periodStart, final double periodEnd, final TimeDiscretization periodDiscretization, final RandomVariable[] realizationAtTimeIndex, final TermStructureModel model) {
final TimeDiscretization liborPeriodDiscretization = covarianceModel.getLiborPeriodDiscretization();
final int periodStartIndex = liborPeriodDiscretization.getTimeIndex(periodStart);
final int periodEndIndex = liborPeriodDiscretization.getTimeIndex(periodEnd);
final RandomVariable[] factorLoadings = covarianceModel.getFactorLoading(time, periodStartIndex, null);
if(periodEndIndex > periodStartIndex+1) {
// Need to sum factor loadings
for(int factorIndex = 0; factorIndex