Package com.opengamma.financial.security.future

Examples of com.opengamma.financial.security.future.FutureSecurity


  }

  @Override
  public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
    final Set<ValueRequirement> requirements = super.getRequirements(context, target, desiredValue);
    final FutureSecurity security = (FutureSecuritytarget.getTrade().getSecurity();
    final ValueRequirement spotAssetRequirement = getSpotAssetRequirement(security);
    if (spotAssetRequirement != null) {
      requirements.add(spotAssetRequirement);
    }
    return requirements;
View Full Code Here


  }

 
  @Override
  public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
    final FutureSecurity security = (FutureSecuritytarget.getTrade().getSecurity();
    final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>();
    // Spot
    final ValueRequirement refPriceReq = getReferencePriceRequirement(context, security);
    if (refPriceReq == null) {
      return null;
View Full Code Here

    super(valueRequirementName, calculator, closingPriceField, costOfCarryField, resolutionKey);
  }
 
  @Override
  public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
    final FutureSecurity security = (FutureSecuritytarget.getTrade().getSecurity();
    final Set<ValueRequirement> requirements = new HashSet<>();
    // Historical Price
    final ValueRequirement refPriceReq = getReferencePriceRequirement(context, security);
    if (refPriceReq == null) {
      return null;
View Full Code Here

  }

  @Override
  public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    final Trade trade = target.getTrade();
    final FutureSecurity security = (FutureSecurity) trade.getSecurity();
    // Get reference price
    final HistoricalTimeSeriesBundle timeSeriesBundle = HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
    if (timeSeriesBundle == null) {
      throw new OpenGammaRuntimeException("Could not get time series bundle for " + trade);
    }
    Double lastMarginPrice = null;
    try {
      lastMarginPrice = timeSeriesBundle.get(MarketDataRequirementNames.MARKET_VALUE, security.getExternalIdBundle()).getTimeSeries().getLatestValue();
    } catch (final NoSuchElementException e) {
      throw new OpenGammaRuntimeException("Time series for " + security.getExternalIdBundle() + " was empty");
    }
    // Build the analytic's version of the security - the derivative
    final ZonedDateTime valuationTime = ZonedDateTime.now(executionContext.getValuationClock());
    final InstrumentDefinitionWithData<?, Double> tradeDefinition = _tradeConverter.convert(trade);
    double referencePrice = lastMarginPrice; // TODO: Decide if this logic should be here or in toDerivative.
View Full Code Here

  public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
    final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {

    // 1. Build the analytic derivative to be priced
    final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
    final FutureSecurity security = (FutureSecurity) target.getTrade().getSecurity();

    // Get reference price
    final HistoricalTimeSeriesBundle timeSeriesBundle = HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
    final LocalDateDoubleTimeSeries timeSeries = timeSeriesBundle.get(MarketDataRequirementNames.MARKET_VALUE, security.getExternalIdBundle()).getTimeSeries();
    if (timeSeries == null || timeSeries.isEmpty()) {
      throw new OpenGammaRuntimeException("Time Series is null or empty for " + security.getExternalIdBundle());
    }
    final Double lastMarginPrice = timeSeries.getLatestValue();
    if (lastMarginPrice == null) {
      throw new OpenGammaRuntimeException("Could not find latest value in time series.");
    }

    final InstrumentDerivative derivative = security.accept(_converter).toDerivative(now, lastMarginPrice, new String[0]);

    // 2. Build up the (simple) market data bundle
    final SimpleFutureDataBundle market = new SimpleFutureDataBundle(null, getMarketPrice(security, inputs), null, null, null);

    // 3. The Calculation - what we came here to do
View Full Code Here

  }

  @Override
  public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
    final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>();
    final FutureSecurity security = (FutureSecurity) target.getTrade().getSecurity();
    // Live market price
    requirements.add(getMarketPriceRequirement(security));
    // Last day's closing price
    final ValueRequirement refPriceReq = getReferencePriceRequirement(context, security);
    if (refPriceReq == null) {
View Full Code Here

    _curveName = curveName;
  }

  @Override
  public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    final FutureSecurity security = (FutureSecurity) target.getSecurity();
    final Clock snapshotClock = executionContext.getValuationClock();
    final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
    final Currency currency = security.getCurrency();
    final Object curveObject = inputs.getValue(YieldCurveFunction.getCurveRequirement(currency, _curveName, null, null));
    if (curveObject == null) {
      throw new OpenGammaRuntimeException("Could not get " + _curveName + " curve");
    }
    final ExternalId underlyingIdentifier = getUnderlyingIdentifier(security);
    final Object spotObject = inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, underlyingIdentifier));
    if (spotObject == null) {
      throw new OpenGammaRuntimeException("Could not get market data for " + underlyingIdentifier);
    }
    final YieldAndDiscountCurve curve = (YieldAndDiscountCurve) curveObject;
    final double spot = (Double) spotObject;
    final SimpleFutureDataBundleDeprecated data = new SimpleFutureDataBundleDeprecated(curve, null, spot, 0., 0.);
    final SimpleInstrument instrument = security.accept(CONVERTER).toDerivative(now);
    final CurrencyAmount pv = instrument.accept(CALCULATOR, data);
    final ValueProperties properties = createValueProperties()
        .with(ValuePropertyNames.CURVE, _curveName)
        .with(ValuePropertyNames.CURRENCY, pv.getCurrency().getCode()).get();
    final ValueSpecification spec = new ValueSpecification(ValueRequirementNames.PRESENT_VALUE, target.toSpecification(), properties);
View Full Code Here

    return Collections.singleton(new ValueSpecification(ValueRequirementNames.PRESENT_VALUE, target.toSpecification(), properties));
  }

  @Override
  public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
    final FutureSecurity future = (FutureSecurity) target.getSecurity();
    final ExternalId underlyingIdentifier = getUnderlyingIdentifier(future);
    final ValueRequirement yieldCurve = YieldCurveFunction.getCurveRequirement(future.getCurrency(), _curveName, null, null);
    final ValueRequirement spot = new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.PRIMITIVE, underlyingIdentifier);
    return Sets.newHashSet(yieldCurve, spot);
  }
View Full Code Here

    return Collections.singleton(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, getTargetType(), target.getUniqueId()));
  }
 
  @Override
  public Set<ComputedValue> execute(FunctionExecutionContext executionContext, FunctionInputs inputs, ComputationTarget target, Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
    FutureSecurity security = (FutureSecurity) target.getSecurity();
    final ValueRequirement desiredValue = desiredValues.iterator().next();
    ValueProperties.Builder properties = desiredValue.getConstraints().copy()
        .with(ValuePropertyNames.CURRENCY, FinancialSecurityUtils.getCurrency(security).getCode());

    String scaleProperty = Double.toString(1);
    double scaleFactor = 1.0;
    if (target.getSecurity() instanceof InterestRateFutureSecurity) {
      // Add scaling and adjust properties to reflect
      final Set<String> scaleValue = desiredValue.getConstraints().getValues(ValuePropertyNames.SCALE);
      if (scaleValue != null && scaleValue.size() > 0) {
        scaleProperty = Iterables.getOnlyElement(scaleValue);
        scaleFactor = Double.parseDouble(scaleProperty);
      }
      properties = properties.withoutAny(ValuePropertyNames.SCALE).with(ValuePropertyNames.SCALE, scaleProperty);
    }
   
   
    final ValueSpecification valueSpecification = new ValueSpecification(ValueRequirementNames.VALUE_DELTA, target.toSpecification(), properties.get());
   
    // Get Market Value
    final Object marketValueObject = inputs.getValue(MarketDataRequirementNames.MARKET_VALUE);
    if (marketValueObject == null) {
      throw new OpenGammaRuntimeException("Could not get market value");
    }
    final Double marketValue = (Double) marketValueObject;
   
    final ComputedValue result = new ComputedValue(valueSpecification, scaleFactor * marketValue * security.getUnitAmount());
    return Collections.singleton(result);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.financial.security.future.FutureSecurity

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.