Java tutorial
/** * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.financial.analytics.model.bond; import java.util.Collections; import java.util.Map; import java.util.Set; import org.apache.commons.lang.Validate; import com.google.common.collect.Sets; import com.opengamma.engine.ComputationTarget; import com.opengamma.engine.ComputationTargetType; import com.opengamma.engine.function.FunctionCompilationContext; import com.opengamma.engine.value.ValueProperties; import com.opengamma.engine.value.ValuePropertyNames; import com.opengamma.engine.value.ValueRequirement; import com.opengamma.engine.value.ValueRequirementNames; import com.opengamma.engine.value.ValueSpecification; import com.opengamma.financial.analytics.ircurve.YieldCurveFunction; /** * */ public class BondPresentValueCountryCurveFunction extends BondPresentValueFunction { @Override public String getShortName() { return "BondPresentValueCountryCurveFunction"; } @Override public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) { final String curveName = YieldCurveFunction.getCurveName(context, desiredValue); return Sets.newHashSet(new ValueRequirement(ValueRequirementNames.YIELD_CURVE, ComputationTargetType.PRIMITIVE, BondFunctionUtils.getCountryID(target), ValueProperties.with(ValuePropertyNames.CURVE, curveName).get())); } @Override public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target) { return Collections .singleton(new ValueSpecification(ValueRequirementNames.PRESENT_VALUE, target.toSpecification(), createValueProperties() .with(ValuePropertyNames.COUNTRY, BondFunctionUtils.getCountryName(target)) .withAny(ValuePropertyNames.CURVE).get())); } @Override public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target, final Map<ValueSpecification, ValueRequirement> inputs) { String curveName = null; for (ValueSpecification input : inputs.keySet()) { if (ValueRequirementNames.YIELD_CURVE.equals(input.getValueName())) { curveName = input.getProperty(ValuePropertyNames.CURVE); break; } } Validate.notNull(curveName, "curveName"); return Collections .singleton(new ValueSpecification(ValueRequirementNames.PRESENT_VALUE, target.toSpecification(), createValueProperties() .with(ValuePropertyNames.COUNTRY, BondFunctionUtils.getCountryName(target)) .with(ValuePropertyNames.CURVE, curveName).get())); } }