net.finmath.marketdata2.model.curves.AbstractForwardCurve 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 04.10.2013
*/
package net.finmath.marketdata2.model.curves;
import java.time.LocalDate;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import net.finmath.marketdata2.model.AnalyticModel;
import net.finmath.stochastic.RandomVariable;
import net.finmath.time.FloatingpointDate;
import net.finmath.time.businessdaycalendar.BusinessdayCalendar;
/**
* Abstract base class for a forward curve, extending a curve object
*
* It stores the maturity of the underlying index (paymentOffset) and the associated discount curve.
*
* @author Christian Fries
* @version 1.0
*/
public abstract class AbstractForwardCurve extends CurveFromInterpolationPoints implements ForwardCurveInterface {
private static final long serialVersionUID = 3735595267579329042L;
protected final String discountCurveName; // The name of the discount curve associated with this forward curve (e.g. OIS for collateralized forwards)
private final Map paymentOffsets = new ConcurrentHashMap<>();
protected final String paymentOffsetCode;
protected final BusinessdayCalendar paymentBusinessdayCalendar;
protected final BusinessdayCalendar.DateRollConvention paymentDateRollConvention;
private final double paymentOffset;
/**
* Construct a base forward curve with a reference date and a payment offset.
*
* @param name The name of this curve.
* @param referenceDate The reference date for this curve, i.e., the date which defined t=0.
* @param paymentOffsetCode The maturity of the index modeled by this curve.
* @param paymentBusinessdayCalendar The business day calendar used for adjusting the payment date.
* @param paymentDateRollConvention The date roll convention used for adjusting the payment date.
* @param interpolationMethod The interpolation method used for the curve.
* @param extrapolationMethod The extrapolation method used for the curve.
* @param interpolationEntity The entity interpolated/extrapolated.
* @param discountCurveName The name of the discount curve associated with this forward curve (e.g. OIS for collateralized forwards).
*/
public AbstractForwardCurve(String name,
LocalDate referenceDate,
String paymentOffsetCode,
BusinessdayCalendar paymentBusinessdayCalendar,
BusinessdayCalendar.DateRollConvention paymentDateRollConvention,
InterpolationMethod interpolationMethod,
ExtrapolationMethod extrapolationMethod,
InterpolationEntity interpolationEntity,
String discountCurveName) {
super(name, referenceDate, interpolationMethod, extrapolationMethod, interpolationEntity);
this.paymentOffsetCode = paymentOffsetCode;
this.paymentBusinessdayCalendar = paymentBusinessdayCalendar;
this.paymentDateRollConvention = paymentDateRollConvention;
this.paymentOffset = Double.NaN;
this.discountCurveName = discountCurveName;
}
/**
* Construct a base forward curve with a reference date and a payment offset.
*
* @param name The name of this curve.
* @param referenceDate The reference date for this curve, i.e., the date which defined t=0.
* @param paymentOffsetCode The maturity of the index modeled by this curve.
* @param paymentBusinessdayCalendar The business day calendar used for adjusting the payment date.
* @param paymentDateRollConvention The date roll convention used for adjusting the payment date.
* @param discountCurveName The name of the discount curve associated with this forward curve (e.g. OIS for collateralized forwards).
*/
public AbstractForwardCurve(String name,
LocalDate referenceDate,
String paymentOffsetCode,
BusinessdayCalendar paymentBusinessdayCalendar,
BusinessdayCalendar.DateRollConvention paymentDateRollConvention,
String discountCurveName) {
this(name, referenceDate, paymentOffsetCode, paymentBusinessdayCalendar, paymentDateRollConvention, InterpolationMethod.LINEAR, ExtrapolationMethod.CONSTANT, InterpolationEntity.VALUE, discountCurveName);
}
/**
* Construct a base forward curve with a reference date and a payment offset.
*
* @param name The name of this curve.
* @param referenceDate The reference date for this curve, i.e., the date which defined t=0.
* @param paymentOffset The maturity of the index modeled by this curve.
* @param discountCurveName The name of the discount curve associated with this forward curve (e.g. OIS for collateralized forwards).
*/
public AbstractForwardCurve(String name, LocalDate referenceDate, double paymentOffset, String discountCurveName) {
super(name, referenceDate, InterpolationMethod.LINEAR, ExtrapolationMethod.CONSTANT, InterpolationEntity.VALUE);
this.paymentOffset = paymentOffset;
this.discountCurveName = discountCurveName;
this.paymentOffsetCode = null;
this.paymentBusinessdayCalendar = null;
this.paymentDateRollConvention = null;
}
/* (non-Javadoc)
* @see net.finmath.marketdata.model.curves.ForwardCurveInterface#getDiscountCurveName()
*/
@Override
public String getDiscountCurveName() {
return discountCurveName;
}
/* (non-Javadoc)
* @see net.finmath.marketdata.model.curves.ForwardCurveInterface#getPaymentOffset(double)
*/
@Override
public double getPaymentOffset(double fixingTime) {
if(paymentOffsetCode == null) {
return paymentOffset;
}
if(paymentOffsets.containsKey(fixingTime)) {
return paymentOffsets.get(fixingTime);
}
else {
/**
* @TODO In case paymentDate is relevant for the index modeling, it should be checked
* if the following derivation of paymentDate is accurate (e.g. wo we have a fixingOffset).
* In such a case, this method may be overridden.
*/
LocalDate referenceDate = getReferenceDate();
LocalDate fixingDate = FloatingpointDate.getDateFromFloatingPointDate(referenceDate, fixingTime);
LocalDate paymentDate = paymentBusinessdayCalendar.getAdjustedDate(fixingDate, paymentOffsetCode, paymentDateRollConvention);
double paymentTime = FloatingpointDate.getFloatingPointDateFromDate(referenceDate, paymentDate);
paymentOffsets.put(fixingTime, paymentTime-fixingTime);
return paymentTime-fixingTime;
}
}
/**
* Returns the forwards for a given vector fixing times.
*
* @param model An analytic model providing a context. The discount curve (if needed) is obtained from this model.
* @param fixingTimes The given fixing times.
* @return The forward rates.
*/
public RandomVariable[] getForwards(AnalyticModel model, double[] fixingTimes)
{
RandomVariable[] values = new RandomVariable[fixingTimes.length];
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy