Package com.opengamma.financial.security.future

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


  }

  @Override
  public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    final Position position = target.getPosition();
    final FutureSecurity security = (FutureSecurity) position.getSecurity();
    final Currency currency = security.getCurrency();
    final Clock snapshotClock = executionContext.getValuationClock();
    final LocalDate now = ZonedDateTime.now(snapshotClock).toLocalDate();
    final ValueRequirement desiredValue = desiredValues.iterator().next();
    final Set<String> samplingPeriodName = desiredValue.getConstraints().getValues(ValuePropertyNames.SAMPLING_PERIOD);
    final Set<String> scheduleCalculatorName = desiredValue.getConstraints().getValues(ValuePropertyNames.SCHEDULE_CALCULATOR);
View Full Code Here


    final Set<String> curveName = constraints.getValues(ValuePropertyNames.CURVE);
    if (curveName == null || curveName.isEmpty() || curveName.size() != 1) {
      return null;
    }
    final Position position = target.getPosition();
    final FutureSecurity future = (FutureSecurity) position.getSecurity();
    final Set<ValueRequirement> requirements = new HashSet<ValueRequirement>();
    final ValueProperties pvProperties = ValueProperties.builder()
        .with(ValuePropertyNames.CURRENCY, future.getCurrency().getCode())
        .with(ValuePropertyNames.CURVE, curveName).get();
    requirements.add(new ValueRequirement(ValueRequirementNames.PRESENT_VALUE, ComputationTargetType.SECURITY, future.getUniqueId(), pvProperties));
    final HistoricalTimeSeriesResolutionResult timeSeries = OpenGammaCompilationContext.getHistoricalTimeSeriesResolver(context).resolve(
        getUnderlyingIdentifier(future), null, null, null, MarketDataRequirementNames.MARKET_VALUE, _resolutionKey);
    if (timeSeries == null) {
      return null;
    }
View Full Code Here

    tradeDate = checkAvailableData(tradeDate, htsMarkToMarket, security, _mark2MarketField, _resolutionKey);
    final ValueSpecification valueSpecification = new ValueSpecification(getResultValueRequirementName(), target.toSpecification(), desiredValue.getConstraints());
    final double costOfCarry = getCostOfCarry(security, tradeDate, htsCostOfCarry);
    Double markToMarket = htsMarkToMarket.getTimeSeries().getValue(tradeDate);
    if (security instanceof FutureSecurity) {
      final FutureSecurity futureSecurity = (FutureSecurity) security;
      markToMarket = markToMarket * futureSecurity.getUnitAmount();
    }
    final BigDecimal dailyPnL = tradeValue.subtract(trade.getQuantity().multiply(BigDecimal.valueOf(markToMarket + costOfCarry)));
    s_logger.debug("{}  security: {} quantity: {} fairValue: {} markToMarket: {} costOfCarry: {} dailyPnL: {}",
          new Object[] {trade.getUniqueId(), trade.getSecurity().getExternalIdBundle(), trade.getQuantity(), tradeValue, markToMarket, costOfCarry, dailyPnL });
    final ComputedValue result = new ComputedValue(valueSpecification, MoneyCalculationUtils.rounded(dailyPnL).doubleValue());
View Full Code Here

    FixedIncomeStripWithSecurity strip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.CASH, Tenor.ONE_MONTH, "DEFAULT"), Tenor.ONE_MONTH, maturity, dummyId, cash);
    assertEquals(strip, cycleObject(FixedIncomeStripWithSecurity.class, strip));

    dummyId = ExternalSchemes.bloombergTickerSecurityId("EDZ2 Comdty");
    bundle = ExternalIdBundle.of(dummyId);
    final FutureSecurity future = new InterestRateFutureSecurity(new Expiry(ZonedDateTime.now()), "XCSE", "XCSE", Currency.USD, 0, dummyId, "Interest Rate");
    future.setExternalIdBundle(bundle);
    strip = new FixedIncomeStripWithSecurity(new FixedIncomeStrip(StripInstrumentType.FUTURE, Tenor.THREE_MONTHS, 2, "DEFAULT"), Tenor.THREE_MONTHS, DateUtils.getUTCDate(2011, 12, 1), dummyId, future);
    assertEquals(strip, cycleObject(FixedIncomeStripWithSecurity.class, strip));
   
    dummyId = ExternalSchemes.bloombergTickerSecurityId("USFR0BE Curncy");
    bundle = ExternalIdBundle.of(dummyId);
View Full Code Here

      final int n = 1 + RANDOM.nextInt(20);
      final Expiry expiry = new Expiry(tradeDate.plusMonths(3 * n).with(THIRD_WED_ADJUSTER));
      final String letter = MONTHS.get(expiry.getExpiry().getMonth());
      final String year = Integer.toString(expiry.getExpiry().getYear() - 2000);
      final String code = "ER" + letter + year;
      final FutureSecurity security = new InterestRateFutureSecurity(expiry, "EUREX", "EUREX", CURRENCY, 2500, EURIBOR_3M, "Interest rate");
      security.setName(code);
      security.setExternalIdBundle(ExternalIdBundle.of(ExternalSchemes.syntheticSecurityId(code)));
      securities[i] = security;
      amounts[i] = RANDOM.nextInt(100) - 50;
      prices[i] = 1 - (1e-5 + RANDOM.nextDouble() / 100.);
    }
    return new FutureSecurityGenerator<>(securities, amounts, prices, tradeDate, "Euribor futures");
View Full Code Here

    for (int i = 0; i < 40; i++) {
      final Expiry expiry = new Expiry(startDate.plusMonths(3 * i).with(THIRD_WED_ADJUSTER));
      final String letter = MONTHS.get(expiry.getExpiry().getMonth());
      final String year = Integer.toString(expiry.getExpiry().getYear() - 2000);
      final String code = "ER" + letter + year;
      final FutureSecurity security = new InterestRateFutureSecurity(expiry, "EUREX", "EUREX", CURRENCY, 2500, EURIBOR_3M, "Interest rate");
      security.setName(code);
      security.setExternalIdBundle(ExternalIdBundle.of(ExternalSchemes.syntheticSecurityId(code)));
      securities[i] = security;
      amounts[i] = 1;
      prices[i] = 1 - ((i + 1) * 0.001);     
    }
    return new FutureSecurityGenerator<>(securities, amounts, prices, tradeDate, "Euribor futures");
View Full Code Here

  @Override
  public Set<ComputedValue> execute(FunctionExecutionContext executionContext, FunctionInputs inputs, ComputationTarget target, Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
   
    // Get security price (market value)
    final Trade trade = target.getTrade();
    final FutureSecurity security = (FutureSecurity) trade.getSecurity();
    final double price = (Double) inputs.getValue(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.SECURITY, security.getUniqueId()));
   
    // Get shift to price, if provided, and hence PNL
    final double pnl;
   
    ValueProperties constraints = desiredValues.iterator().next().getConstraints();
    String priceConstraint = constraints.getValues(s_priceShift).iterator().next();
    String priceShiftTypeConstraint = constraints.getValues(s_priceShiftType).iterator().next();
   
    if (priceConstraint.equals("")) {
      pnl = 0.0;
    } else {
     
      final Double priceShift = Double.valueOf(priceConstraint);
     
      if (priceShiftTypeConstraint.equals("Additive")) {
        // The shift is itself the pnl
        pnl = priceShift;
      } else if (priceShiftTypeConstraint.equals("Multiplicative")) {
        // The market value under shift, d = (1 + d ) * market_value, hence pnl = scenario_value - market_value = d * market_value
        pnl = priceShift * price;
      } else {
        s_logger.debug("Valid PriceShiftType's: Additive and Multiplicative. Found: " + priceShiftTypeConstraint + " Defaulting to Multiplicative.");
        pnl = priceShift * price;
      }
    }
    // Scale by unit notional of contract and trade size
    final Double scaledPnl = pnl * security.getUnitAmount() * trade.getQuantity().floatValue();
    // Return PNL with specification
    final ValueRequirement desiredValue = desiredValues.iterator().next();
    final ValueSpecification valueSpec = new ValueSpecification(getValueRequirementName(), target.toSpecification(), desiredValue.getConstraints());
    return Collections.singleton(new ComputedValue(valueSpec, scaledPnl));

View Full Code Here

           security instanceof IndexFutureSecurity;
  }

  @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

    if (requirements == null) {
      return null;
    }
    // Get Funding Curve Name and Configuration
    final String fundingCurveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
    final FutureSecurity security = (FutureSecuritytarget.getTrade().getSecurity();
    // Add Funding Curve Spec, to get labels correct in result
    requirements.add(getCurveSpecRequirement(FinancialSecurityUtils.getCurrency(security), fundingCurveName));
    return requirements;
  }
View Full Code Here

  @Override
  public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    // 1. Build the analytic derivative to be priced
    final Trade trade = target.getTrade();
    final FutureSecurity security = (FutureSecurity) trade.getSecurity();

    final HistoricalTimeSeriesBundle timeSeriesBundle = HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
    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");
    }
    final ZonedDateTime valuationTime = ZonedDateTime.now(executionContext.getValuationClock());
    final InstrumentDefinitionWithData<?, Double> definition = security.accept(_converter);
    final InstrumentDerivative derivative = definition.toDerivative(valuationTime, lastMarginPrice);

    // 2. Build up the market data bundle
    final SimpleFutureDataBundle market = getFutureDataBundle(security, inputs, timeSeriesBundle, desiredValues.iterator().next());
    final ValueRequirement desiredValue = desiredValues.iterator().next();
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.