Class AMaturityConverter
- java.lang.Object
-
- com.activeviam.risk.core.dates.impl.AMaturityConverter
-
- All Implemented Interfaces:
IMaturityConverter
- Direct Known Subclasses:
SimpleMaturityConverter
public abstract class AMaturityConverter extends Object implements IMaturityConverter
-
-
Field Summary
Fields Modifier and Type Field Description protected Pattern
NOT_DOUBLE
Want to interpret "2D" as two days and not 2.0
-
Constructor Summary
Constructors Constructor Description AMaturityConverter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected LocalDate
convert(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate asOfDate, BucketType bucketType, String tenorSet, String tenor, List<Object> leafCoordinates)
Convert tenor to a LocalDate; with business day convention applied.protected long
dayCount(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate start, LocalDate end, List<Object> leafCoordinates)
Given start and end dates, calculate the number of days between them.protected abstract IBusinessDayCalendar
getBusinessDayCalendar(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates)
protected abstract IBusinessDayConvention
getBusinessDayConvention(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates)
protected abstract IDayCountConvention
getDayCountConvention(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates)
protected com.quartetfs.biz.pivot.query.IQueryCache
getQueryCache(com.quartetfs.biz.pivot.IActivePivot pivot)
Return the query cache bound to the current query.protected abstract ITenorConverter
getTenorConverter(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates, BucketType bucketType)
LocalDate
toDate(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate asOfDate, BucketType bucketType, String tenorSet, String tenorOrDate, List<Object> leafCoordinates)
Convert tenorOrDate to a LocalDate.double
toFraction(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate asOfDate, BucketType bucketType, String tenorSet, String tenorOrDate, List<Object> leafCoordinates)
Calculate a fraction between the asOfDate and the tenorOrDate.protected LocalDate
tryParseAsDate(String tenorOrDate)
Try converting tenorOrDate directly to a date by parsing it as a date.protected Double
tryParseAsDaysBetween(String tenorOrDate)
try converting tenorOrDate directly to the number of days by parsing it as a double.
-
-
-
Field Detail
-
NOT_DOUBLE
protected Pattern NOT_DOUBLE
Want to interpret "2D" as two days and not 2.0
-
-
Method Detail
-
getQueryCache
protected com.quartetfs.biz.pivot.query.IQueryCache getQueryCache(com.quartetfs.biz.pivot.IActivePivot pivot)
Return the query cache bound to the current query. This cache contains values that can be shared among post processors involved in a query. The values in this cache are never shared with other queries.The query cache itself is thread-safe, actually implementing the concurrent map interface.
- Parameters:
pivot
- pivot- Returns:
- current query cache, it is never null
-
toFraction
public double toFraction(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate asOfDate, BucketType bucketType, String tenorSet, String tenorOrDate, List<Object> leafCoordinates)
Description copied from interface:IMaturityConverter
Calculate a fraction between the asOfDate and the tenorOrDate. That fraction is an implementation detail and can be: a number of days, a year fraction, a fraction between two double values (e.g. between two strike values) etc. Extra parameters are required for query-time conversion.- Specified by:
toFraction
in interfaceIMaturityConverter
- Parameters:
pivot
- The ActivePivot instance.asOfDate
- The initial as-of-date.bucketType
- The tenor store.tenorSet
- The tenor set.tenorOrDate
- The String representation of a tenor or date or number of days.leafCoordinates
- Leaf coordinates required for query-time conversion.- Returns:
- a long representing a number of days
-
tryParseAsDaysBetween
protected Double tryParseAsDaysBetween(String tenorOrDate)
try converting tenorOrDate directly to the number of days by parsing it as a double.- Parameters:
tenorOrDate
- the String representation of a tenor or date or number of days.- Returns:
- the number of days if applicable, or null if tenorOrDate could not be parsed as a number of days.
-
dayCount
protected long dayCount(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate start, LocalDate end, List<Object> leafCoordinates)
Given start and end dates, calculate the number of days between them.This method uses the
IDayCountConvention
returned bygetDayCountConvention(IActivePivot, List)
- Parameters:
pivot
- The ActivePivot instance.start
- The start date.end
- The end date.leafCoordinates
- Leaf coordinates required for query-time conversion.- Returns:
- a long representing a number of days.
-
toDate
public LocalDate toDate(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate asOfDate, BucketType bucketType, String tenorSet, String tenorOrDate, List<Object> leafCoordinates)
Description copied from interface:IMaturityConverter
Convert tenorOrDate to a LocalDate. Extra parameters are required for query-time conversion.- Specified by:
toDate
in interfaceIMaturityConverter
- Parameters:
pivot
- The ActivePivot instance.asOfDate
- The initial as-of-date, for use with tenors.bucketType
- The tenor store.tenorSet
- The tenor set.tenorOrDate
- The String representation of a tenor or date.leafCoordinates
- Leaf coordinates required for query-time conversion.- Returns:
- The LocalDate represented by tenorOrDate.
-
tryParseAsDate
protected LocalDate tryParseAsDate(String tenorOrDate)
Try converting tenorOrDate directly to a date by parsing it as a date.- Parameters:
tenorOrDate
- the String representation of a tenor or date.- Returns:
- the date if applicable, or null if tenorOrDate could not be parsed as a date.
-
convert
protected LocalDate convert(com.quartetfs.biz.pivot.IActivePivot pivot, LocalDate asOfDate, BucketType bucketType, String tenorSet, String tenor, List<Object> leafCoordinates) throws ParseException
Convert tenor to a LocalDate; with business day convention applied.This method uses the implementations returned by
getBusinessDayConvention(IActivePivot, List)
, andgetBusinessDayCalendar(IActivePivot, List)
- Parameters:
pivot
- The ActivePivot instance.asOfDate
- The initial as-of-date.bucketType
- The tenor store.tenorSet
- The tenor set.tenor
- The String representation of the tenor.leafCoordinates
- Leaf coordinates required for query-time conversion.- Returns:
- The LocalDate representing tenor added to asOfDate.
- Throws:
ParseException
- the tenor is not recognized
-
getDayCountConvention
protected abstract IDayCountConvention getDayCountConvention(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates)
-
getTenorConverter
protected abstract ITenorConverter getTenorConverter(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates, BucketType bucketType)
-
getBusinessDayConvention
protected abstract IBusinessDayConvention getBusinessDayConvention(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates)
-
getBusinessDayCalendar
protected abstract IBusinessDayCalendar getBusinessDayCalendar(com.quartetfs.biz.pivot.IActivePivot pivot, List<Object> leafCoordinates)
-
-