Package it.unimi.dsi.fastutil.doubles

Examples of it.unimi.dsi.fastutil.doubles.DoubleArrayList


        final String curveSpecificationName = curveName;
        final FuturePriceCurveDefinition<Object> priceCurveDefinition = getCurveDefinition(curveDefinitionSource, target, curveDefinitionName);
        final FuturePriceCurveSpecification priceCurveSpecification = getCurveSpecification(curveSpecificationSource, target, curveSpecificationName);
        final Clock snapshotClock = executionContext.getValuationClock();
        final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
        final DoubleArrayList xList = new DoubleArrayList();
        final DoubleArrayList prices = new DoubleArrayList();
        final FuturePriceCurveInstrumentProvider<Number> futurePriceCurveProvider = (FuturePriceCurveInstrumentProvider<Number>) priceCurveSpecification.getCurveInstrumentProvider();
        final ExchangeTradedInstrumentExpiryCalculator expiryCalc = futurePriceCurveProvider.getExpiryRuleCalculator();
        final LocalDate valDate = now.toLocalDate();
        if (inputs.getAllValues().isEmpty()) {
          throw new OpenGammaRuntimeException("Could not get any data for future price curve called " + curveSpecificationName);
        }
        for (final Object x : priceCurveDefinition.getXs()) {
          final Number xNum = (Number) x;
          final ExternalId identifier = futurePriceCurveProvider.getInstrument(xNum, valDate);
          final ValueRequirement requirement = new ValueRequirement(futurePriceCurveProvider.getDataFieldName(), ComputationTargetType.PRIMITIVE, identifier);
          Double futurePrice = null;
          if (inputs.getValue(requirement) != null) {
            futurePrice = (Double) inputs.getValue(requirement);
            if (futurePrice != null) {
              LocalDate expiry = expiryCalc.getExpiryDate(xNum.intValue(), valDate, calendar);
              final Double ttm = TimeCalculator.getTimeBetween(valDate, expiry);
              xList.add(ttm);
              prices.add(futurePrice);
            }
          }
        }
        final ValueSpecification futurePriceCurveResult = new ValueSpecification(ValueRequirementNames.FUTURE_PRICE_CURVE_DATA,
            target.toSpecification(),
            createValueProperties()
                .with(ValuePropertyNames.CURVE, curveName)
                .with(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE, getInstrumentType()).get());
        final NodalDoublesCurve curve = NodalDoublesCurve.from(xList.toDoubleArray(), prices.toDoubleArray());
        final ComputedValue futurePriceCurveResultValue = new ComputedValue(futurePriceCurveResult, curve);
        return Sets.newHashSet(futurePriceCurveResultValue);
      }

    };
View Full Code Here


    Surface<Double, Double, Double> inputSurface = value.getSurface();
    if (inputSurface instanceof DoublesSurface) {
     
      // Compute unique X data
      Double[] xData = inputSurface.getXData();
      DoubleArrayList uniqueXs = new DoubleArrayList();
      for (int i = 0; i < xData.length; i++) {
        if (!uniqueXs.contains(xData[i])) {
          uniqueXs.add(xData[i]);
        }
      }
     
      final int xCount = uniqueXs.size();
      result.put("xCount", xCount);
     

      // Compute unique Y data
      Double[] yData = inputSurface.getYData();
      DoubleArrayList uniqueYs = new DoubleArrayList();
      for (int j = 0; j < yData.length; j++) {
        if (!uniqueYs.contains(yData[j])) {
          uniqueYs.add(yData[j]);
        }
      }
      Collections.sort(uniqueYs);
      final int yCount = uniqueYs.size();
      result.put("yCount", yCount);
     
      // Convert for display
      if (mode == ConversionMode.FULL) {
        String[] xStrings = new String[xCount];
        for (int i = 0; i < xCount; i++) {
          xStrings[i] = uniqueXs.get(i).toString();
        }
        result.put("xs", xStrings);
       
        String[] ysStrings = new String[yCount];
        for (int i = 0; i < yCount; i++) {
          ysStrings[i] = uniqueYs.get(i).toString();
        }
        result.put("ys", ysStrings);
       
        double[][] outputSurface = new double[yCount][xCount];
        boolean[][] missingValues = new boolean[yCount][xCount];
        // Summary view includes only the actual points of the surface
        for (int y = 0; y < yCount; y++) {
          for (int x = 0; x < xCount; x++) {
            Double volatility = inputSurface.getZValue(uniqueXs.get(x), uniqueYs.get(y));
            if (volatility == null) {
              missingValues[y][x] = true;
              //Some 'obviously wrong' value in case client displays it.  Can't use NaN
              outputSurface[y][x] = Double.MAX_VALUE;
            } else {
View Full Code Here

  private Set<ComputedValue> getResultsForExternalRiskFactors(final SecuritySource secSource, final FunctionInputs inputs, final ComputationTarget target, final RawSecurity security) {
    final List<FactorExposureData> factors = decodeSensitivities(secSource, security);
    Collections.sort(factors, new FactorExposureDataComparator());
    final List<String> indices = Lists.newArrayList();
    final List<String> labels = Lists.newArrayList();
    final DoubleList values = new DoubleArrayList();
    for (final FactorExposureData factor : factors) {
      if (factor.getFactorType().equals(FactorType.CDS_SPREAD)) {
        final ComputedValue computedValue = inputs.getComputedValue(getSensitivityRequirement(factor.getExposureExternalId()));
        if (computedValue != null) {
          indices.add(factor.getFactorExternalId().getValue());
          labels.add(factor.getExposureExternalId().getValue());
          values.add((Double) computedValue.getValue());
        } else {
          s_logger.error("Value was null when getting required input data " + factor.getExposureExternalId());
        }
      }
    }
    final StringLabelledMatrix1D labelledMatrix = new StringLabelledMatrix1D(indices.toArray(new String[] {}), labels.toArray(), values.toDoubleArray());
    final ValueSpecification valueSpecification = new ValueSpecification(CREDIT_SENSITIVITIES_REQUIREMENT, target.toSpecification(), createCurrencyValueProperties(target).get());
    return Collections.singleton(new ComputedValue(valueSpecification, labelledMatrix));
  }
View Full Code Here

        leftExtrapolatorName = Interpolator1DFactory.LINEAR_EXTRAPOLATOR;
        rightExtrapolatorName = Interpolator1DFactory.LINEAR_EXTRAPOLATOR;
      }
      final CurveSpecification specification = (CurveSpecification) inputs.getValue(CURVE_SPECIFICATION);
      final SnapshotDataBundle data = (SnapshotDataBundle) inputs.getValue(CURVE_MARKET_DATA);
      final DoubleArrayList tList = new DoubleArrayList();
      final DoubleArrayList fxList = new DoubleArrayList();
      for (final CurveNodeWithIdentifier nodeWithId : specification.getNodes()) {
        final CurveNode node = nodeWithId.getCurveNode();
        if (!(node instanceof FXForwardNode)) {
          throw new OpenGammaRuntimeException("Unexpected node " + nodeWithId + " found");
        }
        final Double fxForward = data.getDataPoint(nodeWithId.getIdentifier());
        if (fxForward == null) {
          throw new OpenGammaRuntimeException("Could not get FX forward rate for " + node);
        }
        final Tenor tenor = node.getResolvedMaturity();
        tList.add(DateUtils.getDifferenceInYears(now, now.plus(tenor.getPeriod())));
        fxList.add(fxForward);
      }
      final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName,
          leftExtrapolatorName, rightExtrapolatorName);
      return InterpolatedDoublesCurve.from(tList.toDoubleArray(), fxList.toDoubleArray(), interpolator);
    }
View Full Code Here

        final HolidaySource holidaySource = OpenGammaExecutionContext.getHolidaySource(executionContext);
        final Clock snapshotClock = executionContext.getValuationClock();
        final ValueRequirement desiredValue = desiredValues.iterator().next();
        final String curveName = desiredValue.getConstraint(ValuePropertyNames.CURVE);
        final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
        final DoubleArrayList expiries = new DoubleArrayList();
        final DoubleArrayList forwards = new DoubleArrayList();
        final Currency currency = target.getValue(PrimitiveComputationTargetType.CURRENCY);
        final ForwardSwapCurveDefinition definition = curveDefinitionSource.getDefinition(curveName, currency.toString());
        if (definition == null) {
          throw new OpenGammaRuntimeException("Couldn't find a forward swap curve definition called " + curveName + " for target " + target);
        }
        final ForwardSwapCurveSpecification specification = curveSpecificationSource.getSpecification(curveName, currency.toString());
        if (specification == null) {
          throw new OpenGammaRuntimeException("Couldn't find a forward swap curve specification called " + curveName + " for target " + target);
        }
        final ForwardSwapCurveInstrumentProvider provider = (ForwardSwapCurveInstrumentProvider) specification.getCurveInstrumentProvider();
        final Object dataObject = inputs.getValue(ValueRequirementNames.FORWARD_SWAP_CURVE_MARKET_DATA);
        if (dataObject == null) {
          throw new OpenGammaRuntimeException("Could not get market data");
        }
        @SuppressWarnings("unchecked")
        final Map<ExternalId, Double> data = (Map<ExternalId, Double>) dataObject;
        final String interpolatorName = desiredValue.getConstraint(PROPERTY_FORWARD_CURVE_INTERPOLATOR);
        final String leftExtrapolatorName = desiredValue.getConstraint(PROPERTY_FORWARD_CURVE_LEFT_EXTRAPOLATOR);
        final String rightExtrapolatorName = desiredValue.getConstraint(PROPERTY_FORWARD_CURVE_RIGHT_EXTRAPOLATOR);
        final String forwardTenorName = desiredValue.getConstraint(ForwardSwapCurveMarketDataFunction.PROPERTY_FORWARD_TENOR);
        final String conventionName = currency.getCode() + "_SWAP";
        final ConventionBundle convention = conventionSource.getConventionBundle(ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, conventionName));
        if (convention == null) {
          throw new OpenGammaRuntimeException("Could not get convention named " + conventionName);
        }
        final DayCount dayCount = convention.getSwapFloatingLegDayCount();
        if (dayCount == null) {
          throw new OpenGammaRuntimeException("Could not get daycount");
        }
        final Integer settlementDays = convention.getSwapFloatingLegSettlementDays();
        if (settlementDays == null) {
          throw new OpenGammaRuntimeException("Could not get number of settlement days");
        }
        final Calendar calendar = new HolidaySourceCalendarAdapter(holidaySource, currency);
        final LocalDate localNow = now.toLocalDate();
        final Period forwardPeriod = Period.parse(forwardTenorName);
        final Tenor forwardTenor = Tenor.of(forwardPeriod);
        final LocalDate forwardStart = ScheduleCalculator.getAdjustedDate(localNow.plus(forwardPeriod), settlementDays, calendar); //TODO check adjustments
        for (final Tenor tenor : definition.getTenors()) {
          final ExternalId identifier = provider.getInstrument(localNow, tenor, forwardTenor);
          if (data.containsKey(identifier)) {
            final LocalDate expiry = ScheduleCalculator.getAdjustedDate(forwardStart.plus(tenor.getPeriod()), settlementDays, calendar);
            expiries.add(dayCount.getDayCountFraction(localNow, expiry));
            forwards.add(data.get(identifier));
          }
        }
        if (expiries.size() == 0) {
          throw new OpenGammaRuntimeException("Could not get any values for forward swaps");
        }
View Full Code Here

    final int nExpiries = expiries.length;
    final int nStrikes = strikes.length;
    final double[][] fullStrikes = new double[nExpiries][];
    final double[][] fullValues = new double[nExpiries][];
    for (int i = 0; i < nExpiries; i++) {
      final DoubleList availableStrikes = new DoubleArrayList();
      final DoubleList availableVols = new DoubleArrayList();
      for (int j = 0; j < nStrikes; j++) {
        final Double vol = volatilitySurface.getVolatility(expiries[i], strikes[j]);
        if (vol != null) {
          availableStrikes.add(strikes[j]);
          availableVols.add(vol);
        }
      }
      if (availableVols.size() == 0) {
        throw new OpenGammaRuntimeException("No volatility values found for expiry " + expiries[i]);
      }
      fullStrikes[i] = availableStrikes.toDoubleArray();
      fullValues[i] = availableVols.toDoubleArray();
    }
    return Pair.of(fullStrikes, fullValues);
  }
View Full Code Here

      final int minNumberOfStrikes) {
    final int nExpiries = expiries.length;
    final int nStrikes = strikes.length;
    final List<double[]> fullStrikes = new ArrayList<>();
    final List<double[]> fullValues = new ArrayList<>();
    final DoubleList availableExpiries = new DoubleArrayList();
    for (int i = 0; i < nExpiries; i++) {
      final DoubleList availableStrikes = new DoubleArrayList();
      final DoubleList availableVols = new DoubleArrayList();
      for (int j = 0; j < nStrikes; j++) {
        final Double vol = volatilitySurface.getVolatility(expiries[i], strikes[j]);
        if (vol != null) {
          availableStrikes.add(strikes[j]);
          availableVols.add(vol);
        }
      }
      if (availableVols.size() == 0) {
        throw new OpenGammaRuntimeException("No volatility values found for expiry " + expiries[i]);
      } else if (availableVols.size() >= minNumberOfStrikes) {
        availableExpiries.add(expiries[i]);
        fullStrikes.add(availableStrikes.toDoubleArray());
        fullValues.add(availableVols.toDoubleArray());
      }
    }
    return new Triple<>(availableExpiries.toDoubleArray(), fullStrikes.toArray(new double[0][]), fullValues.toArray(new double[0][]));
  }
View Full Code Here

    final int nExpiries = expiries.length;
    final int nStrikes = strikeValues.length;
    final double[][] strikes = new double[nExpiries][];
    final double[][] values = new double[nExpiries][];
    for (int i = 0; i < nExpiries; i++) {
      final DoubleList availableStrikes = new DoubleArrayList();
      final DoubleList availableVols = new DoubleArrayList();
      for (int j = 0; j < nStrikes; j++) {
        final Double vol = volatilitySurface.getVolatility(expiries[i], strikeValues[j]);
        if (vol != null) {
          availableStrikes.add((Double) strikeValues[j]);
          availableVols.add(vol);
        }
      }
      strikes[i] = availableStrikes.toDoubleArray();
      values[i] = availableVols.toDoubleArray();
    }
    return new Triple<>(getArrayOfDoubles(expiries), strikes, values);
  }
View Full Code Here

    }
    for (int i = 0; i < nDeltas; i++) {
      final Number delta = deltaValues[i + 1];
      if (delta != null) {
        deltas[i] = delta.doubleValue() / 100.;
        final DoubleArrayList riskReversalList = new DoubleArrayList();
        final DoubleArrayList strangleList = new DoubleArrayList();
        for (int j = 0; j < nExpiries; j++) {
          final Double rr = fxVolatilitySurface.getVolatility((Tenor) tenors[j], ObjectsPair.of(delta, FXVolQuoteType.RISK_REVERSAL));
          final Double s = fxVolatilitySurface.getVolatility((Tenor) tenors[j], ObjectsPair.of(delta, FXVolQuoteType.BUTTERFLY));
          if (rr != null && s != null) {
            riskReversalList.add(rr);
            strangleList.add(s);
          } else {
            s_logger.info("Had a null value for tenor number " + j);
          }
        }
        riskReversals[i] = riskReversalList.toDoubleArray();
        strangle[i] = strangleList.toDoubleArray();
      }
    }
    final boolean isCallData = true; //TODO this shouldn't be hard-coded
    return new ForexSmileDeltaSurfaceDataBundle(forwardCurve, expiries, deltas, atms, riskReversals, strangle, isCallData);
  }
View Full Code Here

  private Set<ComputedValue> getResultsForExternalRiskFactors(final SecuritySource secSource, final FunctionInputs inputs, final ComputationTarget target, final RawSecurity security) {
    final List<FactorExposureData> factors = decodeSensitivities(secSource, security);
    Collections.sort(factors, new FactorExposureDataComparator());
    final List<String> indices = Lists.newArrayList();
    final List<String> labels = Lists.newArrayList();
    final DoubleList values = new DoubleArrayList();
    for (final FactorExposureData factor : factors) {
      if (!(factor.getFactorType().equals(FactorType.YIELD) && factor.getFactorName().contains(SWAP_TEXT))) {
        final ComputedValue computedValue = inputs.getComputedValue(getSensitivityRequirement(factor.getExposureExternalId()));
        if (computedValue != null) {
          indices.add(factor.getFactorExternalId().getValue());
          labels.add(factor.getExposureExternalId().getValue());
          values.add((Double) computedValue.getValue());
        } else {
          s_logger.error("Value was null when getting required input data " + factor.getExposureExternalId());
        }
      }
    }
    final StringLabelledMatrix1D labelledMatrix = new StringLabelledMatrix1D(indices.toArray(new String[] {}), labels.toArray(), values.toDoubleArray());
    final ValueSpecification valueSpecification = new ValueSpecification(EXTERNAL_SENSITIVITIES_REQUIREMENT, target.toSpecification(), createCurrencyValueProperties(target).get());
    return Collections.singleton(new ComputedValue(valueSpecification, labelledMatrix));
  }
View Full Code Here

TOP

Related Classes of it.unimi.dsi.fastutil.doubles.DoubleArrayList

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.