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

cdm.product.asset.floatingrate.functions.DetermineFixingDate Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.product.asset.floatingrate.functions;

import cdm.base.datetime.BusinessCenterEnum;
import cdm.base.datetime.BusinessCenters;
import cdm.base.datetime.RelativeDateOffset;
import cdm.base.datetime.functions.AddBusinessDays;
import cdm.base.datetime.functions.GetAllBusinessCenters;
import cdm.product.common.schedule.ResetDates;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.MapperC;
import com.rosetta.model.lib.mapper.MapperS;
import com.rosetta.model.lib.records.Date;
import javax.inject.Inject;


@ImplementedBy(DetermineFixingDate.DetermineFixingDateDefault.class)
public abstract class DetermineFixingDate implements RosettaFunction {
	
	// RosettaFunction dependencies
	//
	@Inject protected AddBusinessDays addBusinessDays;
	@Inject protected GetAllBusinessCenters getAllBusinessCenters;

	/**
	* @param resetDates Reset date parameters for observing the rate.
	* @param resetDate The date that the rate is needed for.
	* @return fixingDate The date upon which the rate should be observed. .
	*/
	public Date evaluate(ResetDates resetDates, Date resetDate) {
		Date fixingDate = doEvaluate(resetDates, resetDate);
		
		return fixingDate;
	}

	protected abstract Date doEvaluate(ResetDates resetDates, Date resetDate);

	protected abstract MapperS fixingOffsetDays(ResetDates resetDates, Date resetDate);

	protected abstract MapperC businessCenters(ResetDates resetDates, Date resetDate);

	protected abstract MapperS fixDate(ResetDates resetDates, Date resetDate);

	public static class DetermineFixingDateDefault extends DetermineFixingDate {
		@Override
		protected Date doEvaluate(ResetDates resetDates, Date resetDate) {
			Date fixingDate = null;
			return assignOutput(fixingDate, resetDates, resetDate);
		}
		
		protected Date assignOutput(Date fixingDate, ResetDates resetDates, Date resetDate) {
			fixingDate = fixDate(resetDates, resetDate).get();
			
			return fixingDate;
		}
		
		@Override
		protected MapperS fixingOffsetDays(ResetDates resetDates, Date resetDate) {
			return MapperS.of(resetDates).map("getFixingDates", _resetDates -> _resetDates.getFixingDates()).map("getPeriodMultiplier", relativeDateOffset -> relativeDateOffset.getPeriodMultiplier());
		}
		
		@Override
		protected MapperC businessCenters(ResetDates resetDates, Date resetDate) {
			return MapperC.of(getAllBusinessCenters.evaluate(MapperS.of(resetDates).map("getFixingDates", _resetDates -> _resetDates.getFixingDates()).map("getBusinessCenters", relativeDateOffset -> relativeDateOffset.getBusinessCenters()).get()));
		}
		
		@Override
		protected MapperS fixDate(ResetDates resetDates, Date resetDate) {
			return MapperS.of(addBusinessDays.evaluate(resetDate, fixingOffsetDays(resetDates, resetDate).get(), businessCenters(resetDates, resetDate).getMulti()));
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy