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

cdm.event.common.functions.Qualify_Reprice 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.template.EconomicTerms;
import cdm.product.template.NonTransferableProduct;
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_Reprice.Qualify_RepriceDefault.class)
public abstract class Qualify_Reprice implements RosettaFunction,IQualifyFunctionExtension {
	
	// RosettaFunction dependencies
	//
	@Inject protected ExtractAfterTrade extractAfterTrade;
	@Inject protected ExtractBeforeEconomicTerms extractBeforeEconomicTerms;
	@Inject protected ExtractBeforeTrade extractBeforeTrade;
	@Inject protected ExtractOpenEconomicTerms extractOpenEconomicTerms;
	@Inject protected ExtractTradeCollateralPrice extractTradeCollateralPrice;
	@Inject protected ExtractTradeCollateralQuantity extractTradeCollateralQuantity;
	@Inject protected ExtractTradePurchasePrice extractTradePurchasePrice;
	@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 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 beforeTradePurchasePrice(BusinessEvent businessEvent);

	protected abstract MapperC afterTradePurchasePrice(BusinessEvent businessEvent);

	protected abstract MapperC beforeTradeCollateralQuantity(BusinessEvent businessEvent);

	protected abstract MapperC afterTradeCollateralQuantity(BusinessEvent businessEvent);

	protected abstract MapperC beforeTradeCollateralPrice(BusinessEvent businessEvent);

	protected abstract MapperC afterTradeCollateralPrice(BusinessEvent businessEvent);

	protected abstract MapperS beforeEconomicterms(BusinessEvent businessEvent);

	protected abstract MapperS openEconomicTerms(BusinessEvent businessEvent);

	public static class Qualify_RepriceDefault extends Qualify_Reprice {
		@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(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).map("getTrade", tradeState -> tradeState.getTrade()).map("getProduct", trade -> trade.getProduct()).map("getEconomicTerms", nonTransferableProduct -> nonTransferableProduct.getEconomicTerms()).mapC("getPayout", economicTerms -> economicTerms.getPayout()).map("getInterestRatePayout", payout -> payout.getInterestRatePayout())).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(exists(beforeTradePurchasePrice(businessEvent))).and(exists(afterTradePurchasePrice(businessEvent))).and(notEqual(afterTradePurchasePrice(businessEvent), beforeTradePurchasePrice(businessEvent), CardinalityOperator.Any)).and(areEqual(beforeTradeCollateralQuantity(businessEvent), afterTradeCollateralQuantity(businessEvent), CardinalityOperator.All)).and(notEqual(beforeTradeCollateralPrice(businessEvent), afterTradeCollateralPrice(businessEvent), CardinalityOperator.Any)).and(exists(beforeEconomicterms(businessEvent))).and(exists(openEconomicTerms(businessEvent))).and(areEqual(openEconomicTerms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()), beforeEconomicterms(businessEvent).map("getTerminationDate", economicTerms -> economicTerms.getTerminationDate()), CardinalityOperator.All)).get();
			
			return is_event;
		}
		
		@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 beforeTradePurchasePrice(BusinessEvent businessEvent) {
			return MapperC.of(extractTradePurchasePrice.evaluate(beforeTrade(businessEvent).get()));
		}
		
		@Override
		protected MapperC afterTradePurchasePrice(BusinessEvent businessEvent) {
			return MapperC.of(extractTradePurchasePrice.evaluate(afterTrade(businessEvent).get()));
		}
		
		@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
		protected MapperC beforeTradeCollateralPrice(BusinessEvent businessEvent) {
			return MapperC.of(extractTradeCollateralPrice.evaluate(beforeTrade(businessEvent).get()));
		}
		
		@Override
		protected MapperC afterTradeCollateralPrice(BusinessEvent businessEvent) {
			return MapperC.of(extractTradeCollateralPrice.evaluate(afterTrade(businessEvent).get()));
		}
		
		@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
		public String getNamePrefix() {
			return "Qualify";
		}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy