Package com.opengamma.analytics.financial.pnl

Examples of com.opengamma.analytics.financial.pnl.UnderlyingType


      final NthOrderUnderlying nthOrder = (NthOrderUnderlying) underlying;
      final int n = nthOrder.getOrder();
      if (n == 0) {
        return 1;
      }
      final UnderlyingType type = nthOrder.getUnderlying();
      Validate.isTrue(underlyingData.containsKey(type));
      final double value = Math.pow(underlyingData.get(type), n);
      return value * getMultiplier(underlying);
    } else if (underlying instanceof MixedOrderUnderlying) {
      final MixedOrderUnderlying mixedOrder = (MixedOrderUnderlying) underlying;
View Full Code Here


      final NthOrderUnderlying nthOrder = (NthOrderUnderlying) underlying;
      final int n = nthOrder.getOrder();
      if (n == 0) {
        throw new UnsupportedOperationException();
      }
      final UnderlyingType type = nthOrder.getUnderlying();
      Validate.isTrue(underlyingData.containsKey(type));
      DoubleTimeSeries<?> ts = underlyingData.get(type);
      ts = ts.power(n);
      return ts.multiply(getMultiplier(underlying));
    } else if (underlying instanceof MixedOrderUnderlying) {
View Full Code Here

      throw new IllegalArgumentException("Must have at least two underlying types to have mixed order");
    }
    _orders = new ArrayList<>();
    _underlyings = new ArrayList<>();
    int totalOrder = 0;
    UnderlyingType underlying;
    for (final Entry<Integer, UnderlyingType> entry : underlyings.entrySet()) {
      final int key = entry.getKey();
      if (key < 1) {
        throw new IllegalArgumentException("Order must be at least one to have mixed order");
      }
View Full Code Here

  @Test
  public void test() {
    final int order1 = 2;
    final int order2 = 3;
    final UnderlyingType type1 = UnderlyingType.SPOT_PRICE;
    final UnderlyingType type2 = UnderlyingType.SPOT_VOLATILITY;
    final TreeMap<Integer, UnderlyingType> map1 = new TreeMap<>();
    map1.put(order1, type1);
    map1.put(order2, type2);
    final List<NthOrderUnderlying> set = new ArrayList<>();
    set.add(new NthOrderUnderlying(order1, type1));
View Full Code Here

  }

  @Test
  public void test() {
    final int order = 3;
    final UnderlyingType type = UnderlyingType.SPOT_PRICE;
    final Underlying underlying = new NthOrderUnderlying(order, type);
    assertEquals(underlying.getOrder(), order);
    assertEquals(underlying.getUnderlyings(), Arrays.asList(type));
    final Underlying other = new NthOrderUnderlying(order, type);
    assertFalse(other.equals(type));
View Full Code Here

    List<String> secondOrderNames = null;
    for (final SensitivityAndReturnDataBundle dataForSensitivity : data) {
      final Sensitivity<?> sensitivity = dataForSensitivity.getSensitivity();
      final String identifier = sensitivity.getIdentifier();
      if (sensitivity.getOrder() == 1) {
        final UnderlyingType type = sensitivity.getUnderlyingTypes().get(0);
        final String name = identifier + "_" + type;
        if (firstOrderNames == null) {
          firstOrderNames = new ArrayList<>();
        }
        if (!firstOrderNames.contains(name)) {
          firstOrderNames.add(name);
          firstOrderSensitivity.add(dataForSensitivity.getValue());
          firstOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type));
        } else {
          final int index = firstOrderNames.indexOf(name);
          firstOrderSensitivity.set(index, firstOrderSensitivity.get(index) + dataForSensitivity.getValue());
        }
      } else if (sensitivity.getOrder() == 2) {
        if (secondOrderNames == null) {
          secondOrderNames = new ArrayList<>();
        }
        if (sensitivity.getUnderlying() instanceof NthOrderUnderlying) {
          final UnderlyingType type = sensitivity.getUnderlyingTypes().get(0);
          final String name = identifier + "_" + type;
          if (!secondOrderNames.contains(name)) {
            secondOrderNames.add(name);
            secondOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type));
          }
        } else if (sensitivity.getUnderlying() instanceof MixedOrderUnderlying) {
          final UnderlyingType type1 = sensitivity.getUnderlyingTypes().get(0);
          final UnderlyingType type2 = sensitivity.getUnderlyingTypes().get(1);
          final String name1 = identifier + "_" + type1;
          final String name2 = identifier + "_" + type2;
          if (!secondOrderNames.contains(name1)) {
            secondOrderNames.add(name1);
            secondOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type1));
          }
          if (!secondOrderNames.contains(name2)) {
            secondOrderNames.add(name2);
            secondOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type2));
          }
        }
      } else {
        throw new IllegalArgumentException("Can only handle first and second order sensitivities");
      }
    }
    final Map<Integer, ParametricVaRDataBundle> result = new HashMap<>();
    DoubleMatrix2D firstOrderCovarianceMatrix = null;
    DoubleMatrix1D firstOrderSensitivityMatrix = null;
    DoubleMatrix2D secondOrderCovarianceMatrix = null;
    DoubleMatrix2D secondOrderSensitivityMatrix = null;
    if (firstOrderNames != null) {
      firstOrderCovarianceMatrix = _calculator.evaluate(firstOrderTimeSeries.toArray(EMPTY));
      firstOrderSensitivityMatrix = new DoubleMatrix1D(firstOrderSensitivity.toArray(new Double[firstOrderSensitivity.size()]));
      result.put(1, new ParametricVaRDataBundle(firstOrderNames, firstOrderSensitivityMatrix, firstOrderCovarianceMatrix, 1));
    }
    if (secondOrderNames != null) {
      final int n = secondOrderNames.size();
      final double[][] secondOrderSensitivities = new double[n][n];
      for (final SensitivityAndReturnDataBundle bundle : data) {
        final Sensitivity<?> sensitivity = bundle.getSensitivity();
        final String identifier = sensitivity.getIdentifier();
        if (sensitivity.getOrder() == 2) {
          if (sensitivity.getUnderlying() instanceof NthOrderUnderlying) {
            final UnderlyingType type = sensitivity.getUnderlyingTypes().get(0);
            final String name = identifier + "_" + type;
            final int index = secondOrderNames.indexOf(name);
            secondOrderSensitivities[index][index] += bundle.getValue();
          } else if (sensitivity.getUnderlying() instanceof MixedOrderUnderlying) {
            final UnderlyingType type1 = sensitivity.getUnderlyingTypes().get(0);
            final UnderlyingType type2 = sensitivity.getUnderlyingTypes().get(1);
            final String name1 = identifier + "_" + type1;
            final String name2 = identifier + "_" + type2;
            final int index1 = secondOrderNames.indexOf(name1);
            final int index2 = secondOrderNames.indexOf(name2);
            secondOrderSensitivities[index1][index2] += bundle.getValue();
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.pnl.UnderlyingType

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.