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

cdm.margin.schedule.functions.StandardizedScheduleOptionNotionalAmount Maven / Gradle / Ivy

package cdm.margin.schedule.functions;

import cdm.base.math.Measure;
import cdm.base.math.NonNegativeQuantitySchedule;
import cdm.base.math.metafields.ReferenceWithMetaNonNegativeQuantitySchedule;
import cdm.observable.asset.Price;
import cdm.product.common.settlement.ResolvablePriceQuantity;
import cdm.product.template.OptionPayout;
import cdm.product.template.OptionStrike;
import com.google.inject.ImplementedBy;
import com.rosetta.model.lib.expression.MapperMaths;
import com.rosetta.model.lib.functions.RosettaFunction;
import com.rosetta.model.lib.mapper.MapperS;
import java.math.BigDecimal;

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

@ImplementedBy(StandardizedScheduleOptionNotionalAmount.StandardizedScheduleOptionNotionalAmountDefault.class)
public abstract class StandardizedScheduleOptionNotionalAmount implements RosettaFunction {

	/**
	* @param optionPayout 
	* @return amount 
	*/
	public BigDecimal evaluate(OptionPayout optionPayout) {
		BigDecimal amount = doEvaluate(optionPayout);
		
		return amount;
	}

	protected abstract BigDecimal doEvaluate(OptionPayout optionPayout);

	protected abstract MapperS strikePrice(OptionPayout optionPayout);

	protected abstract MapperS notionalQuantity(OptionPayout optionPayout);

	public static class StandardizedScheduleOptionNotionalAmountDefault extends StandardizedScheduleOptionNotionalAmount {
		@Override
		protected BigDecimal doEvaluate(OptionPayout optionPayout) {
			BigDecimal amount = null;
			return assignOutput(amount, optionPayout);
		}
		
		protected BigDecimal assignOutput(BigDecimal amount, OptionPayout optionPayout) {
			amount = MapperMaths.multiply(strikePrice(optionPayout), notionalQuantity(optionPayout)).get();
			
			return amount;
		}
		
		@Override
		protected MapperS strikePrice(OptionPayout optionPayout) {
			return MapperS.of(optionPayout).map("getStrike", _optionPayout -> _optionPayout.getStrike()).map("getStrikePrice", optionStrike -> optionStrike.getStrikePrice()).map("getValue", price -> price.getValue());
		}
		
		@Override
		protected MapperS notionalQuantity(OptionPayout optionPayout) {
			final MapperS thenResult = MapperS.of(optionPayout).map("getPriceQuantity", _optionPayout -> _optionPayout.getPriceQuantity()).map("getQuantitySchedule", resolvablePriceQuantity -> resolvablePriceQuantity.getQuantitySchedule()).map("getValue", _f->_f.getValue());
			final MapperS ifThenElseResult;
			if (exists(thenResult.map("getMultiplier", nonNegativeQuantitySchedule -> nonNegativeQuantitySchedule.getMultiplier())).getOrDefault(false)) {
				ifThenElseResult = MapperMaths.multiply(thenResult.map("getValue", nonNegativeQuantitySchedule -> nonNegativeQuantitySchedule.getValue()), thenResult.map("getMultiplier", nonNegativeQuantitySchedule -> nonNegativeQuantitySchedule.getMultiplier()).map("getValue", measure -> measure.getValue()));
			} else {
				ifThenElseResult = thenResult.map("getValue", nonNegativeQuantitySchedule -> nonNegativeQuantitySchedule.getValue());
			}
			return ifThenElseResult;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy