Package com.opengamma.engine

Examples of com.opengamma.engine.ComputationTarget


    final ConfigSource configurationSource = OpenGammaCompilationContext.getConfigSource(context);
    final MultiCurveCalculationConfig impliedConfiguration = configurationSource.getLatestByName(MultiCurveCalculationConfig.class, _impliedCurveCalculationConfig);
    if (impliedConfiguration == null) {
      throw new OpenGammaRuntimeException("Multi-curve calculation called " + _impliedCurveCalculationConfig + " was null");
    }
    ComputationTarget target = context.getComputationTargetResolver().resolve(impliedConfiguration.getTarget());
    if (!(target.getValue() instanceof Currency)) {
      throw new OpenGammaRuntimeException("Target of curve calculation configuration was not a currency");
    }
    final Currency impliedCurrency = (Currency) target.getValue();
    if (!IMPLIED_DEPOSIT.equals(impliedConfiguration.getCalculationMethod())) {
      throw new OpenGammaRuntimeException("Curve calculation method was not " + IMPLIED_DEPOSIT + " for configuration called " + _impliedCurveCalculationConfig);
    }
    final String[] impliedCurveNames = impliedConfiguration.getYieldCurveNames();
    if (impliedCurveNames.length != 1) {
      throw new OpenGammaRuntimeException("Can only handle configurations with a single implied curve");
    }
    final LinkedHashMap<String, String[]> originalConfigurationName = impliedConfiguration.getExogenousConfigData();
    if (originalConfigurationName == null || originalConfigurationName.size() != 1) {
      throw new OpenGammaRuntimeException("Need a configuration with one exogenous configuration");
    }
    final Map.Entry<String, String[]> entry = Iterables.getOnlyElement(originalConfigurationName.entrySet());
    final String[] originalCurveNames = entry.getValue();
    if (originalCurveNames.length != 1) {
      s_logger.warn("Found more than one exogenous configuration name; using only the first");
    }
    final MultiCurveCalculationConfig originalConfiguration = configurationSource.getLatestByName(MultiCurveCalculationConfig.class, entry.getKey());
    if (originalConfiguration == null) {
      throw new OpenGammaRuntimeException("Multi-curve calculation called " + entry.getKey() + " was null");
    }
    target = context.getComputationTargetResolver().resolve(originalConfiguration.getTarget());
    if (!(target.getValue() instanceof Currency)) {
      throw new OpenGammaRuntimeException("Target of curve calculation configuration was not a currency");
    }
    final Currency originalCurrency = (Currency) target.getValue();
    if (!originalCurrency.equals(impliedCurrency)) {
      throw new OpenGammaRuntimeException("Currency targets for configurations " + _impliedCurveCalculationConfig + " and " + entry.getKey() + " did not match");
    }
    final YieldCurveDefinition impliedDefinition = configurationSource.getLatestByName(YieldCurveDefinition.class, impliedCurveNames[0] + "_" + impliedCurrency.getCode());
    if (impliedDefinition == null) {
View Full Code Here


    final CompiledFunctionDefinition payYieldCurveMarketDataFunction = createFunction(compContext, execContext, new YieldCurveMarketDataFunction(payCurrency, getCurrencyCurveName()));
    final CompiledFunctionDefinition receiveYieldCurveSpecificationFunction = createFunction(compContext, execContext, new YieldCurveSpecificationFunction(receiveCurrency, getCurrencyCurveName()));
    final CompiledFunctionDefinition receiveYieldCurveMarketDataFunction = createFunction(compContext, execContext, new YieldCurveMarketDataFunction(receiveCurrency, getCurrencyCurveName()));
    final CompiledFunctionDefinition yieldCurveFunction = createFunction(compContext, execContext, new MultiYieldCurvePresentValueMethodFunction());
    final CompiledFunctionDefinition fxForwardCurveFromYieldCurveFunction = createFunction(compContext, execContext, new FXForwardCurveFromYieldCurvesFunction());
    ComputationTarget target;
    // PAY
    target = new ComputationTarget(ComputationTargetType.CURRENCY, payCurrency);
    // PAY - YieldCurveMarketDataFunction
    final ComputedValue[] payCurveDataRequirements = findMarketData(compContext, payYieldCurveMarketDataFunction.getRequirements(compContext, target, null));
    if (payCurveDataRequirements == null) {
      s_logger.debug("Missing market data for curve on {}", payCurrency);
      return null;
    }
    final ComputedValue payCurveMarketData = execute(execContext, payYieldCurveMarketDataFunction, target,
        new ValueRequirement(ValueRequirementNames.YIELD_CURVE_MARKET_DATA, target.toSpecification()), payCurveDataRequirements);
    // PAY - YieldCurveSpecificationFunction
    final ComputedValue payCurveSpec = execute(execContext, payYieldCurveSpecificationFunction, target, new ValueRequirement(ValueRequirementNames.YIELD_CURVE_SPEC, target.toSpecification(),
        ValueProperties.none()), payCurveMarketData);
    // PAY - MultiYieldCurvePresentValueMethodFunction
    final ComputedValue payHtsConversion = new ComputedValue(new ValueSpecification(ValueRequirementNames.YIELD_CURVE_INSTRUMENT_CONVERSION_HISTORICAL_TIME_SERIES, target.toSpecification(),
        ValueProperties.with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, getCurveCalculationConfig(payCurrency)).with(ValuePropertyNames.FUNCTION, "").get()), new HistoricalTimeSeriesBundle());
    final ComputedValue payCurve = execute(execContext, yieldCurveFunction, target, new ValueRequirement(ValueRequirementNames.YIELD_CURVE, target.toSpecification(),
        ValueProperties
        .with(ValuePropertyNames.CURVE, getCurrencyCurveName())
        .with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, getCurveCalculationConfig(payCurrency))
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE, "0.0001")
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE, "0.0001")
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_MAX_ITERATIONS, "1000")
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_DECOMPOSITION, DecompositionFactory.SV_COLT_NAME)
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_USE_FINITE_DIFFERENCE, "false")
        .get()), payCurveSpec,
        payCurveMarketData, payHtsConversion);
    // RECEIVE
    target = new ComputationTarget(ComputationTargetType.CURRENCY, receiveCurrency);
    // RECEIVE - YieldCurveMarketDataFunction
    final ComputedValue[] receiveCurveDataRequirements = findMarketData(compContext, receiveYieldCurveMarketDataFunction.getRequirements(compContext, target, null));
    if (receiveCurveDataRequirements == null) {
      s_logger.debug("Missing market data for curve on {}", receiveCurrency);
      return null;
    }
    final ComputedValue receiveCurveMarketData = execute(execContext, receiveYieldCurveMarketDataFunction, target,
        new ValueRequirement(ValueRequirementNames.YIELD_CURVE_MARKET_DATA, target.toSpecification()), receiveCurveDataRequirements);
    // RECEIVE - YieldCurveSpecificationFunction
    final ComputedValue receiveCurveSpec = execute(execContext, receiveYieldCurveSpecificationFunction, target, new ValueRequirement(ValueRequirementNames.YIELD_CURVE_SPEC, target.toSpecification(),
        ValueProperties.none()), receiveCurveMarketData);
    // RECEIVE - MultiYieldCurvePresentValueMethodFunction
    final ComputedValue receiveHtsConversion = new ComputedValue(new ValueSpecification(ValueRequirementNames.YIELD_CURVE_INSTRUMENT_CONVERSION_HISTORICAL_TIME_SERIES, target.toSpecification(),
        ValueProperties.with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, getCurveCalculationConfig(receiveCurrency)).with(ValuePropertyNames.FUNCTION, "").get()), new HistoricalTimeSeriesBundle());
    final ComputedValue receiveCurve = execute(execContext, yieldCurveFunction, target, new ValueRequirement(ValueRequirementNames.YIELD_CURVE, target.toSpecification(),
        ValueProperties
        .with(ValuePropertyNames.CURVE, getCurrencyCurveName())
        .with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, getCurveCalculationConfig(receiveCurrency))
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_ABSOLUTE_TOLERANCE, "0.0001")
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_RELATIVE_TOLERANCE, "0.0001")
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_ROOT_FINDER_MAX_ITERATIONS, "1000")
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_DECOMPOSITION, DecompositionFactory.SV_COLT_NAME)
        .with(MultiYieldCurvePropertiesAndDefaults.PROPERTY_USE_FINITE_DIFFERENCE, "false")
        .get()), receiveCurveSpec,
        receiveCurveMarketData, receiveHtsConversion);
    // FXForwardCurveFromYieldCurveFunction
    target = new ComputationTarget(ComputationTargetType.UNORDERED_CURRENCY_PAIR, UnorderedCurrencyPair.of(payCurrency, receiveCurrency));
    final ForwardCurve fxForwardCurve = (ForwardCurve) execute(
        execContext,
        fxForwardCurveFromYieldCurveFunction,
        target,
        new ValueRequirement(ValueRequirementNames.FORWARD_CURVE, target.toSpecification(), ValueProperties.with(ValuePropertyNames.CURVE, getCurrencyCurveName()).get()),
        payCurve,
        receiveCurve,
        new ComputedValue(ValueSpecification.of(ValueRequirementNames.SPOT_RATE, ComputationTargetType.PRIMITIVE,
            UniqueId.of(spotRateIdentifier.getScheme().getName(), spotRateIdentifier.getValue()),
            ValueProperties.with(ValuePropertyNames.FUNCTION, "SPOT").get()), spotRate.getSecond())).getValue();
View Full Code Here

    final ComputationTargetSpecification underlyingSpecification = context.getComputationTargetResolver().getSpecificationResolver().getTargetSpecification(underlyingTarget);
    if (underlyingSpecification == null) {
      s_logger.error("Loader error: " + security.getName() + " - cannot resolve underlying identifier " + identifier);
      return false;
    }
    final ComputationTarget underlying = context.getComputationTargetResolver().resolve(underlyingSpecification);
    if (underlying == null) {
      s_logger.error("Loader error: " + security.getName() + " - cannot resolve underlying " + underlyingSpecification);
      return false;
    }
    final Security underlyingSecurity = underlying.getSecurity();
    if (!(underlying.getValue() instanceof InterestRateFutureSecurity)) {
      s_logger.error("Loader error: " + security.getName() + " - IRateFutureOption has an underlying that is not an IRFuture: " + underlyingSecurity.getName());
      return false;
    }
    return true;
  }
View Full Code Here

    ComputationTargetSpecification specification = getCompilationContext().getComputationTargetResolver().getSpecificationResolver().getTargetSpecification(reference);
    if (specification == null) {
      s_logger.warn("Couldn't resolve {}", reference);
    }
    if (specification.getType().accept(s_isUnionType, null) == Boolean.TRUE) {
      final ComputationTarget target = getCompilationContext().getComputationTargetResolver().resolve(specification);
      if (target != null) {
        return target.toSpecification();
      } else {
        s_logger.warn("Resolved {} to {} but can't resolve target to eliminate union", reference, specification);
      }
    }
    return specification;
View Full Code Here

  public SecurityTypeTargetDigests() {
    addHandler(ComputationTargetType.POSITION, new TargetDigests() {
      @Override
      public Object getDigest(FunctionCompilationContext context, ComputationTargetSpecification targetSpec) {
        final ComputationTarget target = context.getComputationTargetResolver().resolve(targetSpec);
        if (target != null) {
          return getPositionDigest(target.getPosition());
        } else {
          return null;
        }
      }
    });
    addHandler(ComputationTargetType.TRADE, new TargetDigests() {
      @Override
      public Object getDigest(FunctionCompilationContext context, ComputationTargetSpecification targetSpec) {
        final ComputationTarget target = context.getComputationTargetResolver().resolve(targetSpec);
        if (target != null) {
          return getTradeDigest(target.getTrade());
        } else {
          return null;
        }
      }
    });
    addHandler(ComputationTargetType.SECURITY, new TargetDigests() {
      @Override
      public Object getDigest(FunctionCompilationContext context, ComputationTargetSpecification targetSpec) {
        final ComputationTarget target = context.getComputationTargetResolver().resolve(targetSpec);
        if (target != null) {
          return getSecurityDigest(target.getSecurity());
        } else {
          return null;
        }
      }
    });
View Full Code Here

public class LazyComputationTargetResolverTest {

  public void testPortfolioNode() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.PORTFOLIO_NODE, UniqueId.of("Node", "0")), VersionCorrection.LATEST);
    final PortfolioNode node = target.getPortfolioNode();
    assertEquals(node.getUniqueId(), UniqueId.of("Node", "0"));
    assertEquals(mock.getResolveCalls(), 0);
    assertEquals(node.getName(), "Node 0");
    assertEquals(mock.getResolveCalls(), 1);
    final List<PortfolioNode> childNodes = node.getChildNodes();
View Full Code Here

  }

  public void testPosition() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.POSITION, UniqueId.of("Position", "0")), VersionCorrection.LATEST);
    final Position position = target.getPosition();
    assertEquals(position.getUniqueId(), UniqueId.of("Position", "0"));
    assertEquals(mock.getResolveCalls(), 0);
    assertEquals(position.getAttributes(), Collections.emptyMap());
    assertEquals(position.getQuantity(), BigDecimal.ONE);
    assertEquals(mock.getResolveCalls(), 1);
View Full Code Here

  }

  public void testTrade() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.TRADE, UniqueId.of("Trade", "0")), VersionCorrection.LATEST);
    final Trade trade = target.getTrade();
    assertEquals(trade.getUniqueId(), UniqueId.of("Trade", "0"));
    assertEquals(mock.getResolveCalls(), 0);
    assertEquals(trade.getAttributes(), Collections.emptyMap());
    trade.setAttributes(ImmutableMap.of("K1", "V1"));
    assertEquals(trade.getAttributes(), ImmutableMap.of("K1", "V1"));
View Full Code Here

  }

  public void testSecurity() {
    final MockComputationTargetResolver mock = MockComputationTargetResolver.unresolved();
    final ComputationTargetResolver resolver = new LazyComputationTargetResolver(mock);
    final ComputationTarget target = resolver.resolve(new ComputationTargetSpecification(ComputationTargetType.SECURITY, UniqueId.of("Security", "0")), VersionCorrection.LATEST);
    final Security security = target.getSecurity();
    assertEquals(mock.getResolveCalls(), 1);
    assertEquals(security.getSecurityType(), "MOCK");
    assertEquals(mock.getResolveCalls(), 1);
  }
View Full Code Here

      final ComputationTargetSpecification specification = versioned.getSpecificationResolver()
          .getTargetSpecification(new ComputationTargetSpecification(ComputationTargetType.PORTFOLIO, portfolioId));
      if (specification == null) {
        throw new OpenGammaRuntimeException("Unable to identify portfolio '" + portfolioId + "' for view '" + getContext().getViewDefinition().getName() + "'");
      }
      final ComputationTarget target = versioned.resolve(specification);
      if (target == null) {
        throw new OpenGammaRuntimeException("Unable to resolve portfolio ID " + specification.getUniqueId() +
            " for view '" + getContext().getViewDefinition().getName() + "'");
      }
      return target.getValue(ComputationTargetType.PORTFOLIO);
    }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.ComputationTarget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.