cdm.event.common.functions.ExtractTradeCollateralPrice Maven / Gradle / Ivy
package cdm.event.common.functions;
import cdm.observable.asset.PriceSchedule;
import cdm.observable.asset.PriceTypeEnum;
import cdm.observable.asset.metafields.FieldWithMetaPriceSchedule;
import cdm.product.common.settlement.PriceQuantity;
import cdm.product.template.TradableProduct;
import cdm.product.template.TradeLot;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.expression.CardinalityOperator;
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.ArrayList;
import java.util.List;
import static com.rosetta.model.lib.expression.ExpressionOperators.*;
@ImplementedBy(ExtractTradeCollateralPrice.ExtractTradeCollateralPriceDefault.class)
public abstract class ExtractTradeCollateralPrice implements RosettaFunction {
/**
* @param tradableProduct
* @return value
*/
public List evaluate(TradableProduct tradableProduct) {
List value = doEvaluate(tradableProduct);
return value;
}
protected abstract List doEvaluate(TradableProduct tradableProduct);
public static class ExtractTradeCollateralPriceDefault extends ExtractTradeCollateralPrice {
@Override
protected List doEvaluate(TradableProduct tradableProduct) {
List value = new ArrayList<>();
return assignOutput(value, tradableProduct);
}
protected List assignOutput(List value, TradableProduct tradableProduct) {
value = MapperS.of(MapperS.of(tradableProduct).mapC("getTradeLot", _tradableProduct -> _tradableProduct.getTradeLot()).get()).mapC("getPriceQuantity", tradeLot -> tradeLot.getPriceQuantity())
.mapItemToList(item -> (MapperC)item.mapC("getPrice", priceQuantity -> priceQuantity.getPrice()).map("getValue", _f->_f.getValue()))
.apply(item -> item
.flattenList())
.apply(item -> item
.filterItemNullSafe(_item -> (Boolean)areEqual(_item.map("getPriceType", priceSchedule -> priceSchedule.getPriceType()), MapperS.of(PriceTypeEnum.ASSET_PRICE), CardinalityOperator.All).get()))
.apply(item -> item
.mapItem(_item -> (MapperS)_item.map("getValue", measureBase -> measureBase.getValue()))).getMulti();
return value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy