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

cdm.event.qualification.functions.Qualify_IndexTransition Maven / Gradle / Ivy

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

import cdm.base.math.ArithmeticOperationEnum;
import cdm.event.common.BusinessEvent;
import cdm.event.common.EventIntentEnum;
import cdm.event.common.Instruction;
import cdm.event.common.Trade;
import cdm.event.common.TradeState;
import cdm.event.common.metafields.ReferenceWithMetaTradeState;
import cdm.observable.asset.FloatingRateIndex;
import cdm.observable.asset.Index;
import cdm.observable.asset.Observable;
import cdm.observable.asset.PriceQuantity;
import cdm.observable.asset.PriceSchedule;
import cdm.observable.asset.PriceTypeEnum;
import cdm.observable.asset.functions.FilterPrice;
import cdm.observable.asset.metafields.FieldWithMetaFloatingRateIndex;
import cdm.observable.asset.metafields.FieldWithMetaObservable;
import cdm.observable.asset.metafields.FieldWithMetaPriceSchedule;
import cdm.product.template.TradeLot;
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_IndexTransition.Qualify_IndexTransitionDefault.class)
public abstract class Qualify_IndexTransition implements RosettaFunction,IQualifyFunctionExtension {
	
	// RosettaFunction dependencies
	//
	@Inject protected FilterPrice filterPrice;

	/**
	* @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 after(BusinessEvent businessEvent);

	protected abstract MapperC before(BusinessEvent businessEvent);

	protected abstract MapperS floatingRateIndexChanged(BusinessEvent businessEvent);

	protected abstract MapperS spread(BusinessEvent businessEvent);

	protected abstract MapperS adjustmentSpreadAdded(BusinessEvent businessEvent);

	public static class Qualify_IndexTransitionDefault extends Qualify_IndexTransition {
		@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 = areEqual(MapperS.of(businessEvent).map("getIntent", _businessEvent -> _businessEvent.getIntent()), MapperS.of(EventIntentEnum.INDEX_TRANSITION), CardinalityOperator.All).and(areEqual(floatingRateIndexChanged(businessEvent), MapperS.of(true), CardinalityOperator.All)).and(areEqual(adjustmentSpreadAdded(businessEvent), MapperS.of(true), CardinalityOperator.All)).get();
			
			return is_event;
		}
		
		@Override
		protected MapperS after(BusinessEvent businessEvent) {
			return MapperS.of(MapperS.of(businessEvent).mapC("getAfter", _businessEvent -> _businessEvent.getAfter()).get()).map("getTrade", tradeState -> tradeState.getTrade());
		}
		
		@Override
		protected MapperC before(BusinessEvent businessEvent) {
			return MapperS.of(businessEvent).mapC("getInstruction", _businessEvent -> _businessEvent.getInstruction()).map("getBefore", instruction -> instruction.getBefore()).map("getValue", _f->_f.getValue()).map("getTrade", tradeState -> tradeState.getTrade());
		}
		
		@Override
		protected MapperS floatingRateIndexChanged(BusinessEvent businessEvent) {
			return exists(before(businessEvent).mapC("getTradeLot", trade -> trade.getTradeLot()).mapC("getPriceQuantity", tradeLot -> tradeLot.getPriceQuantity()).map("getObservable", priceQuantity -> priceQuantity.getObservable()).map("getValue", _f->_f.getValue()).map("getIndex", observable -> observable.getIndex()).map("getFloatingRateIndex", index -> index.getFloatingRateIndex()).map("getValue", _f->_f.getValue())).and(disjoint(before(businessEvent).mapC("getTradeLot", trade -> trade.getTradeLot()).mapC("getPriceQuantity", tradeLot -> tradeLot.getPriceQuantity()).map("getObservable", priceQuantity -> priceQuantity.getObservable()).map("getValue", _f->_f.getValue()).map("getIndex", observable -> observable.getIndex()).map("getFloatingRateIndex", index -> index.getFloatingRateIndex()).map("getValue", _f->_f.getValue()), after(businessEvent).mapC("getTradeLot", trade -> trade.getTradeLot()).mapC("getPriceQuantity", tradeLot -> tradeLot.getPriceQuantity()).map("getObservable", priceQuantity -> priceQuantity.getObservable()).map("getValue", _f->_f.getValue()).map("getIndex", observable -> observable.getIndex()).map("getFloatingRateIndex", index -> index.getFloatingRateIndex()).map("getValue", _f->_f.getValue()))).asMapper();
		}
		
		@Override
		protected MapperS spread(BusinessEvent businessEvent) {
			return MapperS.of(filterPrice.evaluate(after(businessEvent).mapC("getTradeLot", trade -> trade.getTradeLot()).mapC("getPriceQuantity", tradeLot -> tradeLot.getPriceQuantity()).mapC("getPrice", priceQuantity -> priceQuantity.getPrice()).map("getValue", _f->_f.getValue()).getMulti(), PriceTypeEnum.INTEREST_RATE, MapperC.of(MapperS.of(ArithmeticOperationEnum.ADD), MapperS.of(ArithmeticOperationEnum.SUBTRACT)).getMulti(), null));
		}
		
		@Override
		protected MapperS adjustmentSpreadAdded(BusinessEvent businessEvent) {
			if (exists(spread(businessEvent)).getOrDefault(false)) {
				return notEqual(spread(businessEvent).map("getValue", priceSchedule -> priceSchedule.getValue()), MapperS.of(BigDecimal.valueOf(0)), CardinalityOperator.Any).asMapper();
			}
			return MapperS.of(true);
		}
	}
		
		@Override
		public String getNamePrefix() {
			return "Qualify";
		}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy