All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.finmath.time.daycount.DayCountConvention_30E_360 Maven / Gradle / Ivy

Go to download

finmath lib is a Mathematical Finance Library in Java. It provides algorithms and methodologies related to mathematical finance.

There is a newer version: 6.0.19
Show newest version
/*
 * (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
 *
 * Created on 07.09.2013
 */

package net.finmath.time.daycount;

import java.io.Serializable;
import java.time.LocalDate;

/**
 * Implementation of 30E/360 and 30E+/360.
 *
 * Calculates the day count of 30E/360 as
 * 
 *		(endDateYear - startDateYear) * 360.0 + (endDateMonth - startDateMonth) * 30.0 + (Math.min(endDateDay, 30.0) - Math.min(startDateDay, 30.0))
 * 
 *
 * This day count convention is sometime called Eurobond basis or 30/360 ISMA.
 *
 * For 30E/360 we have that:
 * 
    *
  • * The method {@link #getDaycount(LocalDate, LocalDate) getDaycount} corresponds to the implementation of the "European method" of Excel function DAYS360, i.e., DAYS360(startDate,endDate,TRUE). *
  • *
  • * The method {@link #getDaycountFraction(LocalDate, LocalDate) getDaycountFraction} corresponds to the implementation of the "30E/360 method" of Excel function YEARFRAC, i.e., YEARFRAC(startDate,endDate,4). *
  • *
* * The day count of 30E+/360 is that of 30E/360 whenever endDateDay is ≤ 30, otherwise it is that of 30E/360 plus one. * * @author Christian Fries * @version 1.0 */ public class DayCountConvention_30E_360 implements DayCountConvention, Serializable { private static final long serialVersionUID = 9198199320837217485L; private final boolean is30Eplus360; /** * Create a 30E/360 or 30E+/360 day count convention. * * @param is30Eplus360 If true, then 30E+/360 is constructed, otherwise 30E/360 is constructed. */ public DayCountConvention_30E_360(final boolean is30Eplus360) { this.is30Eplus360 = is30Eplus360; } /** * Create a 30E/360 daycount convention. */ public DayCountConvention_30E_360() { this(false); } /* (non-Javadoc) * @see net.finmath.time.daycount.DayCountConvention#getDaycount(java.time.LocalDate, java.time.LocalDate) */ @Override public double getDaycount(final LocalDate startDate, final LocalDate endDate) { if(startDate.isAfter(endDate)) { return -getDaycount(endDate,startDate); } final int startDateDay = startDate.getDayOfMonth(); final int startDateMonth = startDate.getMonthValue(); final int startDateYear = startDate.getYear(); final int endDateDay = endDate.getDayOfMonth(); final int endDateMonth = endDate.getMonthValue(); final int endDateYear = endDate.getYear(); double daycount = (endDateYear - startDateYear) * 360.0 + (endDateMonth - startDateMonth) * 30.0 + (Math.min(endDateDay, 30.0) - Math.min(startDateDay, 30.0)); if(is30Eplus360 && endDateDay == 31) { daycount +=1.0; } return daycount; } /* (non-Javadoc) * @see net.finmath.time.daycount.DayCountConvention#getDaycountFraction(java.time.LocalDate, java.time.LocalDate) */ @Override public double getDaycountFraction(final LocalDate startDate, final LocalDate endDate) { return getDaycount(startDate, endDate) / 360.0; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy