当前位置: 首页>>代码示例>>Java>>正文


Java DoubleArrayList.toDoubleArray方法代码示例

本文整理汇总了Java中it.unimi.dsi.fastutil.doubles.DoubleArrayList.toDoubleArray方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleArrayList.toDoubleArray方法的具体用法?Java DoubleArrayList.toDoubleArray怎么用?Java DoubleArrayList.toDoubleArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在it.unimi.dsi.fastutil.doubles.DoubleArrayList的用法示例。


在下文中一共展示了DoubleArrayList.toDoubleArray方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGenerator

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
protected GeneratorYDCurve getGenerator(final CurveDefinition definition, final LocalDate valuationDate) {
  if (definition instanceof InterpolatedCurveDefinition) {
    final InterpolatedCurveDefinition interpolatedDefinition = (InterpolatedCurveDefinition) definition;
    final String interpolatorName = interpolatedDefinition.getInterpolatorName();
    final String leftExtrapolatorName = interpolatedDefinition.getLeftExtrapolatorName();
    final String rightExtrapolatorName = interpolatedDefinition.getRightExtrapolatorName();
    final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName, leftExtrapolatorName, rightExtrapolatorName);
    if (definition instanceof FixedDateInterpolatedCurveDefinition) {
      final FixedDateInterpolatedCurveDefinition fixedDateDefinition = (FixedDateInterpolatedCurveDefinition) definition;
      final List<LocalDate> fixedDates = fixedDateDefinition.getFixedDates();
      final DoubleArrayList nodePoints = new DoubleArrayList(fixedDates.size()); //TODO what about equal node points?
      for (final LocalDate fixedDate : fixedDates) {
        nodePoints.add(TimeCalculator.getTimeBetween(valuationDate, fixedDate)); //TODO what to do if the fixed date is before the valuation date?
      }
      final double anchor = nodePoints.get(0); //TODO should the anchor go into the definition?
      return new GeneratorCurveYieldInterpolatedAnchorNode(nodePoints.toDoubleArray(), anchor, interpolator);
    }
    return new GeneratorCurveYieldInterpolated(getMaturityCalculator(), interpolator);
  }
  throw new OpenGammaRuntimeException("Cannot handle curves of type " + definition.getClass());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:23,代码来源:MultiCurveDiscountingFunction.java

示例2: getGenerator

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private GeneratorYDCurve getGenerator(final AbstractCurveDefinition definition, LocalDate valuationDate) {

    if (definition instanceof InterpolatedCurveDefinition) {
      final InterpolatedCurveDefinition interpolatedDefinition = (InterpolatedCurveDefinition) definition;
      final String interpolatorName = interpolatedDefinition.getInterpolatorName();
      final String leftExtrapolatorName = interpolatedDefinition.getLeftExtrapolatorName();
      final String rightExtrapolatorName = interpolatedDefinition.getRightExtrapolatorName();
      final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName,
                                                                                                  leftExtrapolatorName,
                                                                                                  rightExtrapolatorName);
      if (definition instanceof FixedDateInterpolatedCurveDefinition) {
        final FixedDateInterpolatedCurveDefinition fixedDateDefinition = (FixedDateInterpolatedCurveDefinition) definition;
        final List<LocalDate> fixedDates = fixedDateDefinition.getFixedDates();
        final DoubleArrayList nodePoints = new DoubleArrayList(fixedDates.size()); //TODO what about equal node points?
        for (final LocalDate fixedDate : fixedDates) {
          nodePoints.add(TimeCalculator.getTimeBetween(valuationDate, fixedDate)); //TODO what to do if the fixed date is before the valuation date?
        }
        final double anchor = nodePoints.get(0); //TODO should the anchor go into the definition?
        return new GeneratorCurveYieldInterpolatedAnchorNode(nodePoints.toDoubleArray(), anchor, interpolator);
      }
      return new GeneratorCurveYieldInterpolated(LastTimeCalculator.getInstance(), interpolator);
    }

    throw new OpenGammaRuntimeException("Cannot handle curves of type " + definition.getClass());
  }
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:DefaultDiscountingMulticurveBundleFn.java

示例3: getGenerator

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private GeneratorYDCurve getGenerator(final AbstractCurveDefinition definition, LocalDate valuationDate) {

    if (definition instanceof InterpolatedCurveDefinition) {
      InterpolatedCurveDefinition interpolatedDefinition = (InterpolatedCurveDefinition) definition;
      String interpolatorName = interpolatedDefinition.getInterpolatorName();
      String leftExtrapolatorName = interpolatedDefinition.getLeftExtrapolatorName();
      String rightExtrapolatorName = interpolatedDefinition.getRightExtrapolatorName();
      Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName,
                                                                                                  leftExtrapolatorName,
                                                                                                  rightExtrapolatorName);
      if (definition instanceof FixedDateInterpolatedCurveDefinition) {
        FixedDateInterpolatedCurveDefinition fixedDateDefinition = (FixedDateInterpolatedCurveDefinition) definition;
        List<LocalDate> fixedDates = fixedDateDefinition.getFixedDates();
        DoubleArrayList nodePoints = new DoubleArrayList(fixedDates.size()); //TODO what about equal node points?
        for (final LocalDate fixedDate : fixedDates) {
          //TODO what to do if the fixed date is before the valuation date?
          nodePoints.add(TimeCalculator.getTimeBetween(valuationDate, fixedDate));
        }
        final double anchor = nodePoints.get(0); //TODO should the anchor go into the definition?
        return new GeneratorCurveYieldInterpolatedAnchorNode(nodePoints.toDoubleArray(), anchor, interpolator);
      }
      return new GeneratorCurveYieldInterpolated(LastTimeCalculator.getInstance(), interpolator);
    }

    throw new OpenGammaRuntimeException("Cannot handle curves of type " + definition.getClass());
  }
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:27,代码来源:CurveBundleProviderFn.java

示例4: createCurveGenerator

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
 * Creates a curve generator for a curve definition and valuation date.
 *
 * @param definition the curve definition
 * @param valuationDate the valuation date
 * @return a generator capable of generating the curve
 */
private GeneratorYDCurve createCurveGenerator(AbstractCurveDefinition definition, LocalDate valuationDate) {
  if (definition instanceof InterpolatedCurveDefinition) {
    InterpolatedCurveDefinition interpolatedDefinition = (InterpolatedCurveDefinition) definition;
    Interpolator1D interpolator =
        CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatedDefinition.getInterpolatorName(),
                                                                interpolatedDefinition.getLeftExtrapolatorName(),
                                                                interpolatedDefinition.getRightExtrapolatorName());
    if (definition instanceof FixedDateInterpolatedCurveDefinition) {
      FixedDateInterpolatedCurveDefinition fixedDateDefinition = (FixedDateInterpolatedCurveDefinition) definition;
      List<LocalDate> fixedDates = fixedDateDefinition.getFixedDates();
      DoubleArrayList nodePoints = new DoubleArrayList(fixedDates.size()); //TODO what about equal node points?

      for (LocalDate fixedDate : fixedDates) {
        nodePoints.add(TimeCalculator.getTimeBetween(valuationDate, fixedDate)); //TODO what to do if the fixed date is before the valuation date?
      }
      double anchor = nodePoints.get(0); //TODO should the anchor go into the definition?
      return new GeneratorCurveYieldInterpolatedAnchorNode(nodePoints.toDoubleArray(), anchor, interpolator);
    }
    return new GeneratorCurveYieldInterpolated(LastTimeCalculator.getInstance(), interpolator);
  }
  throw new OpenGammaRuntimeException("Cannot handle curves of type " + definition.getClass());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:30,代码来源:AbstractMulticurveMarketDataBuilder.java

示例5: calculateFromPresentValue

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
 * Calculate the instrument sensitivity from the yield sensitivity, the jacobian matrix and the coupon sensitivity.
 * @param curveSensitivities The sensitivity to points of the yield curve.
 * @param curves The curve bundle.
 * @param couponSensitivity The sensitivity
 * @param jacobian The present value coupon sensitivity.
 * @return The instrument quote/rate sensitivity.
 */
public DoubleMatrix1D calculateFromPresentValue(final Map<String, List<DoublesPair>> curveSensitivities, final YieldCurveBundle curves, final DoubleMatrix1D couponSensitivity,
    final DoubleMatrix2D jacobian) {
  final DoubleArrayList resultList = new DoubleArrayList();
  for (final String curveName : curves.getAllNames()) {
    final DoubleMatrix1D nodeSensitivity = new DoubleMatrix1D(
        (_parameterSensitivityCalculator.pointToParameterSensitivity(curveSensitivities.get(curveName), curves.getCurve(curveName))).toArray(new Double[0]));
    final int n = nodeSensitivity.getNumberOfElements();
    final DoubleMatrix2D inverseJacobian = MATRIX_ALGEBRA.getInverse(jacobian);
    for (int i = 0; i < n; i++) {
      double sum = 0;
      for (int j = 0; j < n; j++) {
        sum += -couponSensitivity.getEntry(i) * inverseJacobian.getEntry(j, i) * nodeSensitivity.getEntry(j);
      }
      resultList.add(sum);
    }
  }
  return new DoubleMatrix1D(resultList.toDoubleArray());
}
 
开发者ID:charles-cooper,项目名称:idylfin,代码行数:27,代码来源:MarketQuoteSensitivityCalculator.java

示例6: calculateFromParRate

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
public DoubleMatrix1D calculateFromParRate(final Map<String, List<DoublesPair>> curveSensitivities, final YieldCurveBundle interpolatedCurves, final DoubleMatrix2D jacobian) {
  final DoubleArrayList resultList = new DoubleArrayList();
  for (final String curveName : interpolatedCurves.getAllNames()) {
    final DoubleMatrix1D nodeSensitivity = new DoubleMatrix1D(
        (_parameterSensitivityCalculator.pointToParameterSensitivity(curveSensitivities.get(curveName), interpolatedCurves.getCurve(curveName))).toArray(new Double[0]));
    final int n = nodeSensitivity.getNumberOfElements();
    final DoubleMatrix2D inverseJacobian = MATRIX_ALGEBRA.getInverse(jacobian);
    for (int i = 0; i < n; i++) {
      double sum = 0;
      for (int j = 0; j < n; j++) {
        sum += inverseJacobian.getEntry(j, i) * nodeSensitivity.getEntry(j);
      }
      resultList.add(sum);
    }
  }
  return new DoubleMatrix1D(resultList.toDoubleArray());
}
 
开发者ID:charles-cooper,项目名称:idylfin,代码行数:18,代码来源:MarketQuoteSensitivityCalculator.java

示例7: calculateFromSimpleInterpolatedCurve

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
public DoubleMatrix1D calculateFromSimpleInterpolatedCurve(final Map<String, List<DoublesPair>> curveSensitivities, final YieldCurveBundle interpolatedCurves) {
  final DoubleArrayList resultList = new DoubleArrayList();
  for (final String curveName : interpolatedCurves.getAllNames()) {
    final DoubleMatrix1D nodeSensitivity = new DoubleMatrix1D(
        (_parameterSensitivityCalculator.pointToParameterSensitivity(curveSensitivities.get(curveName), interpolatedCurves.getCurve(curveName))).toArray(new Double[0]));
    final int n = nodeSensitivity.getNumberOfElements();
    for (int i = 0; i < n; i++) {
      double sum = 0;
      for (int j = 0; j < n; j++) {
        sum += nodeSensitivity.getEntry(j);
      }
      resultList.add(sum);
    }
  }
  return new DoubleMatrix1D(resultList.toDoubleArray());
}
 
开发者ID:charles-cooper,项目名称:idylfin,代码行数:17,代码来源:MarketQuoteSensitivityCalculator.java

示例8: extractFeatures

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
    public double[] extractFeatures(Object _sp, String entity1id, String entity2id) {
        LangStringPair sp = (LangStringPair)_sp;
        DoubleArrayList featureValues = new DoubleArrayList();
//        System.err.printf("%s <-> %s\n", sp._1, sp._2);
        final String[] l1tok = PrettyGoodTokenizer.tokenize(sp._1), 
            l2tok = PrettyGoodTokenizer.tokenize(sp._2);

        buildFeatures(sp.lang1, "", featureValues, sp._1, sp._2, l1tok, l2tok, false);
        if(labelCharFeatures) {
            buildFeatures(sp.lang2, "char-", featureValues, sp._1, sp._2, sp._1.split(""), sp._2.split(""), true);
        }

        return featureValues.toDoubleArray();
    }
 
开发者ID:jmccrae,项目名称:naisc,代码行数:16,代码来源:ClassifierFeatures.java

示例9: visitAnnuityDefinition

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
public double[] visitAnnuityDefinition(final AnnuityDefinition<? extends PaymentDefinition> annuity, final ZonedDateTime date) {
  final int n = annuity.getNumberOfPayments();
  final DoubleArrayList fractions = new DoubleArrayList();
  for (int i = 0; i < n; i++) {
    final PaymentDefinition payment = annuity.getNthPayment(i);
    if (!date.isAfter(payment.getPaymentDate())) {
      fractions.add(payment.accept(COUPON_VISITOR));
    }
  }
  return fractions.toDoubleArray();
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:13,代码来源:AnnuitySpreadsVisitor.java

示例10: getData

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
protected SmileSurfaceDataBundle getData(final FunctionInputs inputs, final ValueRequirement volDataRequirement, final ValueRequirement forwardCurveRequirement) {
  final Object volatilitySurfaceObject = inputs.getValue(volDataRequirement);
  if (volatilitySurfaceObject == null) {
    throw new OpenGammaRuntimeException("Could not get " + volDataRequirement);
  }
  final Object forwardCurveObject = inputs.getValue(forwardCurveRequirement);
  if (forwardCurveObject == null) {
    throw new OpenGammaRuntimeException("Could not get " + forwardCurveRequirement);
  }
  final ForwardCurve forwardCurve = (ForwardCurve) forwardCurveObject;
  @SuppressWarnings("unchecked")
  final VolatilitySurfaceData<Tenor, Pair<Number, FXVolQuoteType>> fxVolatilitySurface = (VolatilitySurfaceData<Tenor, Pair<Number, FXVolQuoteType>>) volatilitySurfaceObject;
  final Tenor[] tenors = fxVolatilitySurface.getXs();
  Arrays.sort(tenors);
  final Pair<Number, FXVolQuoteType>[] quotes = fxVolatilitySurface.getYs();
  final Number[] deltaValues = getDeltaValues(quotes);
  final int nExpiries = tenors.length;
  final int nDeltas = deltaValues.length - 1;
  final double[] expiries = new double[nExpiries];
  final double[] deltas = new double[nDeltas];
  final double[] atms = new double[nExpiries];
  final double[][] riskReversals = new double[nDeltas][nExpiries];
  final double[][] strangle = new double[nDeltas][nExpiries];
  for (int i = 0; i < nExpiries; i++) {
    final Tenor tenor = tenors[i];
    final double t = getTime(tenor);
    final Double atm = fxVolatilitySurface.getVolatility(tenor, ObjectsPair.of(deltaValues[0], FXVolQuoteType.ATM));
    if (atm == null) {
      throw new OpenGammaRuntimeException("Could not get ATM volatility data for surface");
    }
    expiries[i] = t;
    atms[i] = atm;
  }
  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(tenors[j], ObjectsPair.of(delta, FXVolQuoteType.RISK_REVERSAL));
        final Double s = fxVolatilitySurface.getVolatility(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);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:58,代码来源:ForexPiecewiseSABRSurfaceFunction.java

示例11: getDataFromStrangleRiskReversalQuote

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
public static ForexSmileDeltaSurfaceDataBundle getDataFromStrangleRiskReversalQuote(final ForwardCurve forwardCurve,
    final VolatilitySurfaceData<Tenor, Pair<Number, FXVolQuoteType>> fxVolatilitySurface) {
  final Object[] tenors = fxVolatilitySurface.getXs();
  Arrays.sort(tenors);
  final Object[] quotes = fxVolatilitySurface.getYs();
  final Number[] deltaValues = getDeltaValues(quotes);
  final int nExpiries = tenors.length;
  final int nDeltas = deltaValues.length - 1;
  final double[] expiries = new double[nExpiries];
  final double[] deltas = new double[nDeltas];
  final double[] atms = new double[nExpiries];
  final double[][] riskReversals = new double[nDeltas][nExpiries];
  final double[][] strangle = new double[nDeltas][nExpiries];
  for (int i = 0; i < nExpiries; i++) {
    final Tenor tenor = (Tenor) tenors[i];
    final double t = getTime(tenor);
    final Double atm = fxVolatilitySurface.getVolatility(tenor, ObjectsPair.of(deltaValues[0], FXVolQuoteType.ATM));
    if (atm == null) {
      throw new OpenGammaRuntimeException("Could not get ATM volatility data for surface");
    }
    expiries[i] = t;
    atms[i] = atm;
  }
  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);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:47,代码来源:BlackVolatilitySurfaceUtils.java

示例12: execute

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
  final ValueRequirement desiredValue = desiredValues.iterator().next();
  final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
  final String interpolatorName = desiredValue.getConstraint(InterpolatedDataProperties.X_INTERPOLATOR_NAME);
  final String leftExtrapolatorName = desiredValue.getConstraint(InterpolatedDataProperties.LEFT_X_EXTRAPOLATOR_NAME);
  final String rightExtrapolatorName = desiredValue.getConstraint(InterpolatedDataProperties.RIGHT_X_EXTRAPOLATOR_NAME);
  final ValueRequirement surfaceRequirement = getDataRequirement(surfaceName, target);
  final Object volatilitySurfaceObject = inputs.getValue(surfaceRequirement);
  if (volatilitySurfaceObject == null) {
    throw new OpenGammaRuntimeException("Could not get " + surfaceRequirement);
  }
  // In some circumstances, we will get Object arrays for xs and ys, so need to cope with that.
  @SuppressWarnings("unchecked")
  final VolatilitySurfaceData<Object, Object> fxVolatilitySurface = (VolatilitySurfaceData<Object, Object>) volatilitySurfaceObject;
  final Object[] tenorsObjs = fxVolatilitySurface.getXs();
  final Tenor[] tenors = new Tenor[tenorsObjs.length];
  System.arraycopy(tenorsObjs, 0, tenors, 0, tenors.length);
  final Object[] deltaValueObjs = fxVolatilitySurface.getYs();
  final Double[] deltaValues = new Double[deltaValueObjs.length];
  System.arraycopy(deltaValueObjs, 0, deltaValues, 0, deltaValueObjs.length);
  Arrays.sort(tenors);
  Arrays.sort(deltaValues);
  final int nPoints = tenors.length;
  final SmileDeltaParameters[] smile = new SmileDeltaParameters[nPoints];
  final int nSmileValues = deltaValues.length;
  final Set<String> shifts = desiredValues.iterator().next().getConstraints().getValues(VolatilitySurfaceShiftFunction.SHIFT);
  final double shiftMultiplier;
  if ((shifts != null) && (shifts.size() == 1)) {
    final String shift = shifts.iterator().next();
    shiftMultiplier = 1 + Double.parseDouble(shift);
  } else {
    shiftMultiplier = 1;
  }
  for (int i = 0; i < tenors.length; i++) {
    final Tenor tenor = tenors[i];
    final double t = getTime(tenor);
    final DoubleArrayList deltas = new DoubleArrayList();
    final DoubleArrayList volatilities = new DoubleArrayList();
    for (int j = 0; j < nSmileValues; j++) {
      final Double delta = deltaValues[j];
      if (delta != null) {
        Double volatility = fxVolatilitySurface.getVolatility((Object) tenor, (Object) delta);
        if (volatility != null) {
          volatility *= shiftMultiplier;
          if (delta < 50) {
            deltas.add(getTransformedDelta(delta));
          }
          volatilities.add(volatility);
        }
      } else {
        s_logger.info("Had a null value for tenor number " + j);
      }
    }
    smile[i] = new SmileDeltaParameters(t, deltas.toDoubleArray(), volatilities.toDoubleArray());
  }
  final Interpolator1D interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(interpolatorName, leftExtrapolatorName, rightExtrapolatorName);
  final SmileDeltaTermStructureParametersStrikeInterpolation smiles = new SmileDeltaTermStructureParametersStrikeInterpolation(smile, interpolator);
  final ValueProperties.Builder resultProperties = createValueProperties()
      .with(ValuePropertyNames.SURFACE, surfaceName)
      .with(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE, InstrumentTypeProperties.FOREX)
      .with(InterpolatedDataProperties.X_INTERPOLATOR_NAME, interpolatorName)
      .with(InterpolatedDataProperties.LEFT_X_EXTRAPOLATOR_NAME, leftExtrapolatorName)
      .with(InterpolatedDataProperties.RIGHT_X_EXTRAPOLATOR_NAME, rightExtrapolatorName);
  if (shifts != null) {
    resultProperties.with(VolatilitySurfaceShiftFunction.SHIFT, shifts);
  }
  return Collections.singleton(new ComputedValue(new ValueSpecification(ValueRequirementNames.STANDARD_VOLATILITY_SURFACE_DATA, target.toSpecification(),
      resultProperties.get()), smiles));
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:71,代码来源:ForexPutCallDeltaVolatilitySurfaceFunction.java

示例13: execute

import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
    final Set<ValueRequirement> desiredValues) {
  final ValueProperties properties = desiredValues.iterator().next().getConstraints().copy().get();
  final VolatilityCubeData<Tenor, Tenor, Double> volatilityCubeData = (VolatilityCubeData<Tenor, Tenor, Double>) inputs.getValue(STANDARD_VOLATILITY_CUBE_DATA);
  final SurfaceData<Tenor, Tenor> forwardSwapSurface = (SurfaceData<Tenor, Tenor>) inputs.getValue(SURFACE_DATA);
  final DoubleArrayList swapMaturitiesList = new DoubleArrayList();
  final DoubleArrayList swaptionExpiriesList = new DoubleArrayList();
  final DoubleArrayList alphaList = new DoubleArrayList();
  final DoubleArrayList betaList = new DoubleArrayList();
  final DoubleArrayList nuList = new DoubleArrayList();
  final DoubleArrayList rhoList = new DoubleArrayList();
  final DoubleArrayList chiSqList = new DoubleArrayList();
  final Map<DoublesPair, DoubleMatrix2D> inverseJacobians = new HashMap<>();
  final Map<Pair<Tenor, Tenor>, Double[]> fittedRelativeStrikes = new HashMap<>();
  for (final Tenor expiry : volatilityCubeData.getUniqueXValues()) {
    final double swaptionExpiry = getTime(expiry);
    for (final Tenor maturity : volatilityCubeData.getUniqueYValues()) {
      final double swapMaturity = getTime(maturity);
      final double forward = forwardSwapSurface.getValue(expiry, maturity);
      if (volatilityCubeData.asMap().containsKey(Triple.of(expiry, maturity, forward))) {
        final List<ObjectsPair<Double, Double>> strikeVol = volatilityCubeData.getZValuesForXandY(expiry, maturity);
        final int nVols = strikeVol.size();
        if (nVols < 4) {
          s_logger.info("Smile had less than 4 points for expiry = {} and maturity = {}", expiry, maturity);
          continue;
        }
        final double[] strikes = new double[nVols];
        final Double[] strikeCopy = new Double[nVols]; //TODO
        final double[] blackVols = new double[nVols];
        final double[] errors = new double[nVols];
        int i = 0;
        for (final ObjectsPair<Double, Double> sv : strikeVol) {
          strikes[i] = sv.getFirst();
          strikeCopy[i] = sv.getFirst();
          blackVols[i] = sv.getSecond();
          errors[i++] = ERROR;
        }
        final LeastSquareResultsWithTransform fittedResult = new SABRModelFitter(forward, strikes, swaptionExpiry, blackVols, errors, SABR_FUNCTION).solve(SABR_INITIAL_VALUES, FIXED);
        final DoubleMatrix1D parameters = fittedResult.getModelParameters();
        swapMaturitiesList.add(swapMaturity);
        swaptionExpiriesList.add(swaptionExpiry);
        alphaList.add(parameters.getEntry(0));
        betaList.add(parameters.getEntry(1));
        rhoList.add(parameters.getEntry(2));
        nuList.add(parameters.getEntry(3));
        final DoublesPair expiryMaturityPair = DoublesPair.of(swaptionExpiry, swapMaturity);
        inverseJacobians.put(expiryMaturityPair, fittedResult.getModelParameterSensitivityToData());
        chiSqList.add(fittedResult.getChiSq());
        fittedRelativeStrikes.put(Pairs.of(expiry, maturity), strikeCopy);
      }
    }
  }
  if (swapMaturitiesList.size() < 5) { //don't have sufficient fits to construct a surface
    throw new OpenGammaRuntimeException("Could not construct SABR parameter surfaces; have under 5 surface points");
  }
  final double[] swapMaturities = swapMaturitiesList.toDoubleArray();
  final double[] swaptionExpiries = swaptionExpiriesList.toDoubleArray();
  final double[] alpha = alphaList.toDoubleArray();
  final double[] beta = betaList.toDoubleArray();
  final double[] nu = nuList.toDoubleArray();
  final double[] rho = rhoList.toDoubleArray();
  final InterpolatedDoublesSurface alphaSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, alpha, INTERPOLATOR, "SABR alpha surface");
  final InterpolatedDoublesSurface betaSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, beta, INTERPOLATOR, "SABR beta surface");
  final InterpolatedDoublesSurface nuSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, nu, INTERPOLATOR, "SABR nu surface");
  final InterpolatedDoublesSurface rhoSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, rho, INTERPOLATOR, "SABR rho surface");
  final SABRFittedSurfaces fittedSurfaces = new SABRFittedSurfaces(alphaSurface, betaSurface, nuSurface, rhoSurface, inverseJacobians);
  final ValueSpecification sabrSurfacesSpecification = new ValueSpecification(SABR_SURFACES, target.toSpecification(), properties);
  final ValueSpecification smileIdsSpecification = new ValueSpecification(VOLATILITY_CUBE_FITTED_POINTS, target.toSpecification(), properties);
  return Sets.newHashSet(new ComputedValue(sabrSurfacesSpecification, fittedSurfaces), new ComputedValue(smileIdsSpecification, new FittedSmileDataPoints(fittedRelativeStrikes)));
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:72,代码来源:SABRNonLinearLeastSquaresSwaptionCubeFittingFunction.java


注:本文中的it.unimi.dsi.fastutil.doubles.DoubleArrayList.toDoubleArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。