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

cdm.product.asset.functions.ResolveEquityInitialPrice Maven / Gradle / Ivy

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

import cdm.base.math.ArithmeticOperationEnum;
import cdm.base.math.DatedValue;
import cdm.base.math.FinancialUnitEnum;
import cdm.base.math.UnitType;
import cdm.observable.asset.CashPrice;
import cdm.observable.asset.Price;
import cdm.observable.asset.PriceComposite;
import cdm.observable.asset.PriceExpressionEnum;
import cdm.observable.asset.PriceSchedule;
import cdm.observable.asset.PriceSchedule.PriceScheduleBuilder;
import cdm.observable.asset.PriceTypeEnum;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.expression.CardinalityOperator;
import com.rosetta.model.lib.functions.ModelObjectValidator;
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 java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;

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

@ImplementedBy(ResolveEquityInitialPrice.ResolveEquityInitialPriceDefault.class)
public abstract class ResolveEquityInitialPrice implements RosettaFunction {
	
	@Inject protected ModelObjectValidator objectValidator;

	/**
	* @param price 
	* @return initialPrice 
	*/
	public PriceSchedule evaluate(List price) {
		PriceSchedule.PriceScheduleBuilder initialPriceBuilder = doEvaluate(price);
		
		final PriceSchedule initialPrice;
		if (initialPriceBuilder == null) {
			initialPrice = null;
		} else {
			initialPrice = initialPriceBuilder.build();
			objectValidator.validate(PriceSchedule.class, initialPrice);
		}
		
		return initialPrice;
	}

	protected abstract PriceSchedule.PriceScheduleBuilder doEvaluate(List price);

	public static class ResolveEquityInitialPriceDefault extends ResolveEquityInitialPrice {
		@Override
		protected PriceSchedule.PriceScheduleBuilder doEvaluate(List price) {
			if (price == null) {
				price = Collections.emptyList();
			}
			PriceSchedule.PriceScheduleBuilder initialPrice = PriceSchedule.builder();
			return assignOutput(initialPrice, price);
		}
		
		protected PriceSchedule.PriceScheduleBuilder assignOutput(PriceSchedule.PriceScheduleBuilder initialPrice, List price) {
			final MapperC thenResult0 = MapperC.of(price)
				.filterItemNullSafe(item -> areEqual(item.map("getPerUnitOf", priceSchedule -> priceSchedule.getPerUnitOf()).map("getFinancialUnit", unitType -> unitType.getFinancialUnit()), MapperS.of(FinancialUnitEnum.SHARE), CardinalityOperator.All).get());
			final MapperC thenResult1 = thenResult0
				.mapItem(item -> MapperS.of(Price.builder()
					.setValue(item.map("getValue", priceSchedule -> priceSchedule.getValue()).get())
					.setUnit(item.map("getUnit", priceSchedule -> priceSchedule.getUnit()).get())
					.setPerUnitOf(item.map("getPerUnitOf", priceSchedule -> priceSchedule.getPerUnitOf()).get())
					.setPriceType(item.map("getPriceType", priceSchedule -> priceSchedule.getPriceType()).get())
					.setPriceExpression(item.map("getPriceExpression", priceSchedule -> priceSchedule.getPriceExpression()).get())
					.setComposite(item.map("getComposite", priceSchedule -> priceSchedule.getComposite()).get())
					.setArithmeticOperator(item.map("getArithmeticOperator", priceSchedule -> priceSchedule.getArithmeticOperator()).get())
					.setCashPrice(item.map("getCashPrice", priceSchedule -> priceSchedule.getCashPrice()).get())
					.setDatedValue(Collections.emptyList())
					.build()));
			initialPrice = toBuilder(MapperS.of(thenResult1.get()).get());
			
			return Optional.ofNullable(initialPrice)
				.map(o -> o.prune())
				.orElse(null);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy