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.MapperListOfLists;
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) {
final MapperListOfLists thenResult0 = MapperS.of(MapperS.of(tradableProduct).mapC("getTradeLot", _tradableProduct -> _tradableProduct.getTradeLot()).get()).mapC("getPriceQuantity", tradeLot -> tradeLot.getPriceQuantity())
.mapItemToList(item -> item.mapC("getPrice", priceQuantity -> priceQuantity.getPrice()).map("getValue", _f->_f.getValue()));
final MapperC thenResult1 = thenResult0
.flattenList();
final MapperC thenResult2 = thenResult1
.filterItemNullSafe(item -> areEqual(item.map("getPriceType", priceSchedule -> priceSchedule.getPriceType()), MapperS.of(PriceTypeEnum.ASSET_PRICE), CardinalityOperator.All).get());
value = thenResult2
.mapItem(item -> item.map("getValue", priceSchedule -> priceSchedule.getValue())).getMulti();
return value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy