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

cdm.event.common.functions.Qualify_PartialDelivery Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.event.common.functions;

import cdm.base.datetime.AdjustableOrRelativeDate;
import cdm.event.common.BusinessEvent;
import cdm.event.common.Trade;
import cdm.event.common.TradeState;
import cdm.product.asset.InterestRatePayout;
import cdm.product.collateral.Collateral;
import cdm.product.template.EconomicTerms;
import cdm.product.template.Payout;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.expression.CardinalityOperator;
import com.rosetta.model.lib.functions.IQualifyFunctionExtension;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.MapperC;
import com.rosetta.model.lib.mapper.MapperS;
import java.math.BigDecimal;
import javax.inject.Inject;

import static com.rosetta.model.lib.expression.ExpressionOperators.*;

@ImplementedBy(Qualify_PartialDelivery.Qualify_PartialDeliveryDefault.class)
public abstract class Qualify_PartialDelivery implements RosettaFunction,IQualifyFunctionExtension {
	
	// RosettaFunction dependencies
	//
	@Inject protected ExtractAfterTrade extractAfterTrade;
	@Inject protected ExtractBeforeEconomicTerms extractBeforeEconomicTerms;
	@Inject protected ExtractBeforeTrade extractBeforeTrade;
	@Inject protected ExtractOpenEconomicTerms extractOpenEconomicTerms;
	@Inject protected ExtractTradeCollateralQuantity extractTradeCollateralQuantity;
	@Inject protected FilterClosedTradeStates filterClosedTradeStates;
	@Inject protected FilterOpenTradeStates filterOpenTradeStates;

	/**
	* @param businessEvent 
	* @return is_event 
	*/
	@Override
	public Boolean evaluate(BusinessEvent businessEvent) {
		Boolean is_event = doEvaluate(businessEvent);
		
		return is_event;
	}

	protected abstract Boolean doEvaluate(BusinessEvent businessEvent);

	protected abstract MapperS beforeEconomicterms(BusinessEvent businessEvent);

	protected abstract MapperS openEconomicTerms(BusinessEvent businessEvent);

	protected abstract MapperC openTrades(BusinessEvent businessEvent);

	protected abstract MapperC closedTradeState(BusinessEvent businessEvent);

	protected abstract MapperS beforeTrade(BusinessEvent businessEvent);

	protected abstract MapperS afterTrade(BusinessEvent businessEvent);

	protected abstract MapperC beforeTradeCollateralQuantity(BusinessEvent businessEvent);

	protected abstract MapperC afterTradeCollateralQuantity(BusinessEvent businessEvent);

	public static class Qualify_PartialDeliveryDefault extends Qualify_PartialDelivery {
		@Override
		protected Boolean doEvaluate(BusinessEvent businessEvent) {
			Boolean is_event = null;
			return assignOutput(is_event, businessEvent);
		}
		
		protected Boolean assignOutput(Boolean is_event, BusinessEvent businessEvent) {
			is_event = exists(beforeEconomicterms(businessEvent)).and(exists(openEconomicTerms(businessEvent))).and(areEqual(MapperS.of(openTrades(businessEvent).resultCount()), MapperS.of(1), CardinalityOperator.All)).and(areEqual(MapperS.of(closedTradeState(businessEvent).resultCount()), MapperS.of(1), CardinalityOperator.All)).and(areEqual(openEconomicTerms(businessEvent).mapC("getPayout", economicTerms -> economicTerms.getPayout()).map("getInterestRatePayout", payout -> payout.getInterestRatePayout()), beforeEconomicterms(businessEvent).mapC("getPayout", economicTerms -> economicTerms.getPayout()).map("getInterestRatePayout", payout -> payout.getInterestRatePayout()), CardinalityOperator.All)).and(areEqual(openEconomicTerms(businessEvent).map("getCollateral", economicTerms -> economicTerms.getCollateral()), beforeEconomicterms(businessEvent).map("getCollateral", economicTerms -> economicTerms.getCollateral()), CardinalityOperator.All)).and(greaterThan(beforeTradeCollateralQuantity(businessEvent), afterTradeCollateralQuantity(businessEvent), CardinalityOperator.All)).and(areEqual(openEconomicTerms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()), beforeEconomicterms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()), CardinalityOperator.All)).and(areEqual(openEconomicTerms(businessEvent).map("getEffectiveDate", economicTerms -> economicTerms.getEffectiveDate()), beforeEconomicterms(businessEvent).map("getEffectiveDate", economicTerms -> economicTerms.getEffectiveDate()), CardinalityOperator.All)).get();
			
			return is_event;
		}
		
		@Override
		protected MapperS beforeEconomicterms(BusinessEvent businessEvent) {
			return MapperS.of(extractBeforeEconomicTerms.evaluate(businessEvent));
		}
		
		@Override
		protected MapperS openEconomicTerms(BusinessEvent businessEvent) {
			return MapperS.of(extractOpenEconomicTerms.evaluate(businessEvent));
		}
		
		@Override
		protected MapperC openTrades(BusinessEvent businessEvent) {
			return MapperC.of(filterOpenTradeStates.evaluate(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).getMulti())).map("getTrade", tradeState -> tradeState.getTrade());
		}
		
		@Override
		protected MapperC closedTradeState(BusinessEvent businessEvent) {
			return MapperC.of(filterClosedTradeStates.evaluate(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).getMulti()));
		}
		
		@Override
		protected MapperS beforeTrade(BusinessEvent businessEvent) {
			return MapperS.of(extractBeforeTrade.evaluate(businessEvent));
		}
		
		@Override
		protected MapperS afterTrade(BusinessEvent businessEvent) {
			return MapperS.of(extractAfterTrade.evaluate(businessEvent));
		}
		
		@Override
		protected MapperC beforeTradeCollateralQuantity(BusinessEvent businessEvent) {
			return MapperC.of(extractTradeCollateralQuantity.evaluate(beforeTrade(businessEvent).get()));
		}
		
		@Override
		protected MapperC afterTradeCollateralQuantity(BusinessEvent businessEvent) {
			return MapperC.of(extractTradeCollateralQuantity.evaluate(afterTrade(businessEvent).get()));
		}
	}
		
		@Override
		public String getNamePrefix() {
			return "Qualify";
		}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy