net.finmath.time.TenorFromArray Maven / Gradle / Ivy
/*
* (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
*
* Created on 03.09.2013
*/
package net.finmath.time;
import java.time.LocalDate;
/**
* Implements a time discretization based on dates using a reference
* date and an daycount convention / year fraction.
*
* The time as a double is represented as the year fraction from the reference date.
*
* @author Christian Fries
* @version 1.0
*/
public class TenorFromArray extends TimeDiscretizationFromArray implements Tenor {
private static final long serialVersionUID = 4027884423439197483L;
private LocalDate referenceDate;
private LocalDate[] dates;
/**
* @param dates A set of dates.
* @param referenceDate The reference date, which defines t=0 with respect to the internal double representation.
*/
public TenorFromArray(final LocalDate[] dates, final LocalDate referenceDate) {
super(createTimeDiscretizationFromDates(dates, referenceDate));
this.dates = dates;
this.referenceDate = referenceDate;
}
/**
* @param dates
* @param referenceDate
* @return A time discretization corresponding to the given dates, relative to the reference date, using the internal day count fraction.
*/
private static double[] createTimeDiscretizationFromDates(final LocalDate[] dates, final LocalDate referenceDate) {
final double[] timeDiscretization = new double[dates.length];
for(int timeIndex=0; timeIndex