Example usage for org.apache.commons.lang ArrayUtils EMPTY_DOUBLE_OBJECT_ARRAY

List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_DOUBLE_OBJECT_ARRAY

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils EMPTY_DOUBLE_OBJECT_ARRAY.

Prototype

Double[] EMPTY_DOUBLE_OBJECT_ARRAY

To view the source code for org.apache.commons.lang ArrayUtils EMPTY_DOUBLE_OBJECT_ARRAY.

Click Source Link

Document

An empty immutable Double array.

Usage

From source file:com.opengamma.analytics.math.interpolation.Interpolator1D.java

public Interpolator1DDataBundle getDataBundle(final Map<Double, Double> data) {
    Validate.notNull(data, "Backing data for interpolation must not be null.");
    Validate.notEmpty(data, "Backing data for interpolation must not be empty.");
    if (data instanceof SortedMap) {
        final double[] keys = ArrayUtils
                .toPrimitive(data.keySet().toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY));
        final double[] values = ArrayUtils
                .toPrimitive(data.values().toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY));
        return getDataBundleFromSortedArrays(keys, values);
    }//from  w  w  w.  j  av  a2s.  c  o m
    final double[] keys = new double[data.size()];
    final double[] values = new double[data.size()];
    int i = 0;
    for (final Map.Entry<Double, Double> entry : data.entrySet()) {
        keys[i] = entry.getKey();
        values[i] = entry.getValue();
        i++;
    }
    return getDataBundle(keys, values);
}

From source file:com.opengamma.financial.analytics.model.VegaMatrixHelper.java

public static DoubleLabelledMatrix3D getVegaSwaptionCubeQuoteMatrixInStandardForm(
        final Map<Pair<Tenor, Tenor>, Double[]> fittedPoints, final Map<Double, DoubleMatrix2D> matrices) {
    final List<Double> xKeysList = new ArrayList<Double>();
    final List<Double> xLabelsList = new ArrayList<Double>();
    final List<Double> yKeysList = new ArrayList<Double>();
    final List<Tenor> yLabelsList = new ArrayList<Tenor>();
    final List<Double> zKeysList = new ArrayList<Double>();
    final List<Tenor> zLabelsList = new ArrayList<Tenor>();
    for (final Entry<Pair<Tenor, Tenor>, Double[]> entry : fittedPoints.entrySet()) {
        final double swapMaturity = getTime(entry.getKey().getFirst());
        if (!zKeysList.contains(swapMaturity)) {
            zKeysList.add(swapMaturity);
            zLabelsList.add(entry.getKey().getFirst());
        }/*w  w w .  j  a  v a  2s. c  o  m*/
        final double swaptionExpiry = getTime(entry.getKey().getSecond());
        if (!yKeysList.contains(swaptionExpiry)) {
            yKeysList.add(swaptionExpiry);
            yLabelsList.add(entry.getKey().getSecond());
        }
        if (xKeysList.size() == 0) {
            final Double[] relativeStrikesArray = entry.getValue();
            for (final Double relativeStrike : relativeStrikesArray) {
                xKeysList.add(relativeStrike);
                xLabelsList.add(relativeStrike);
            }
        }
    }
    final Double[] xKeys = xKeysList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Double[] xLabels = xLabelsList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Double[] yKeys = yKeysList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Tenor[] yLabels = yLabelsList.toArray(EMPTY_TENOR_ARRAY);
    final Double[] zKeys = zKeysList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Tenor[] zLabels = zLabelsList.toArray(EMPTY_TENOR_ARRAY);
    final double[][][] values = new double[zKeys.length][xKeys.length][yKeys.length];
    for (int i = 0; i < zKeys.length; i++) {
        values[i] = matrices.get(zKeys[i]).toArray();
    }
    return new DoubleLabelledMatrix3D(xKeys, xLabels, yKeys, yLabels, zKeys, zLabels, values);
}

From source file:com.opengamma.financial.analytics.model.YieldCurveNodeSensitivitiesHelper.java

public static Set<ComputedValue> getTimeLabelledSensitivitiesForCurve(final List<DoublesPair> resultList,
        final ValueSpecification resultSpec) {
    final int n = resultList.size();
    final Double[] keys = new Double[n];
    final double[] values = new double[n];
    final Object[] labels = new Object[n];
    LabelledMatrix1D<Double, Double> labelledMatrix = new DoubleLabelledMatrix1D(
            ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, ArrayUtils.EMPTY_OBJECT_ARRAY, ArrayUtils.EMPTY_DOUBLE_ARRAY);
    for (int i = 0; i < n; i++) {
        final DoublesPair pair = resultList.get(i);
        keys[i] = pair.first;/*from w  w  w. j  a  v  a  2 s .c om*/
        values[i] = pair.second;
        labels[i] = s_formatter.format(pair.first);
        labelledMatrix = labelledMatrix.add(pair.first, s_formatter.format(pair.first), pair.second, 1e-16);
    }
    return Collections.singleton(new ComputedValue(resultSpec, labelledMatrix));
}

From source file:com.opengamma.financial.analytics.model.VegaMatrixUtils.java

/**
 * Returns a bucketed swaption vega cube with swaption expiry / swap maturity / distance from ATM axes.
 * @param fittedPoints The points in the swaption volatility cube, not null
 * @param matrices a map from swaption expiry to vega matrix, not null
 * @return A labelled vega cube/*from  w w w .j  av  a2  s  .c  o  m*/
 */
public static DoubleLabelledMatrix3D getVegaSwaptionCubeQuoteMatrix(
        final Map<Pair<Tenor, Tenor>, Double[]> fittedPoints, final Map<Double, DoubleMatrix2D> matrices) {
    ArgumentChecker.notNull(fittedPoints, "fitted points");
    ArgumentChecker.notNull(matrices, "matrices");
    final List<Double> xKeysList = new ArrayList<>();
    final List<Double> xLabelsList = new ArrayList<>();
    final List<Double> yKeysList = new ArrayList<>();
    final List<Tenor> yLabelsList = new ArrayList<>();
    final List<Double> zKeysList = new ArrayList<>();
    final List<Tenor> zLabelsList = new ArrayList<>();
    for (final Entry<Pair<Tenor, Tenor>, Double[]> entry : fittedPoints.entrySet()) {
        final double swapMaturity = getTime(entry.getKey().getFirst());
        if (!zKeysList.contains(swapMaturity)) {
            zKeysList.add(swapMaturity);
            zLabelsList.add(entry.getKey().getFirst());
        }
        final double swaptionExpiry = getTime(entry.getKey().getSecond());
        if (!yKeysList.contains(swaptionExpiry)) {
            yKeysList.add(swaptionExpiry);
            yLabelsList.add(entry.getKey().getSecond());
        }
        if (xKeysList.size() == 0) {
            final Double[] relativeStrikesArray = entry.getValue();
            for (final Double relativeStrike : relativeStrikesArray) {
                xKeysList.add(relativeStrike);
                xLabelsList.add(relativeStrike);
            }
        }
    }
    final Double[] xKeys = xKeysList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Double[] xLabels = xLabelsList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Double[] yKeys = yKeysList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Tenor[] yLabels = yLabelsList.toArray(new Tenor[yLabelsList.size()]);
    final Double[] zKeys = zKeysList.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY);
    final Tenor[] zLabels = zLabelsList.toArray(new Tenor[zLabelsList.size()]);
    final double[][][] values = new double[zKeys.length][xKeys.length][yKeys.length];
    for (int i = 0; i < zKeys.length; i++) {
        values[i] = matrices.get(zKeys[i]).toArray();
    }
    return new DoubleLabelledMatrix3D(xKeys, xLabels, yKeys, yLabels, zKeys, zLabels, values);
}

From source file:com.opengamma.financial.analytics.model.volatility.cube.SABRNonLinearSwaptionVolatilityCubeFittingFunctionNew.java

@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs,
        final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
    final ConfigSource configSource = OpenGammaExecutionContext.getConfigSource(executionContext);
    final VolatilityCubeDefinitionSource definitionSource = new SyntheticSwaptionVolatilityCubeDefinitionSource(
            configSource);//ww w. ja v a2 s  .  c o m
    final ConfigDBSwaptionVolatilityCubeSpecificationSource specificationSource = new ConfigDBSwaptionVolatilityCubeSpecificationSource(
            configSource);
    final ValueRequirement desiredSurface = getDesiredSurfaceRequirement(desiredValues);
    final String definitionName = desiredSurface
            .getConstraint(SurfaceAndCubePropertyNames.PROPERTY_CUBE_DEFINITION);
    final String specificationName = desiredSurface
            .getConstraint(SurfaceAndCubePropertyNames.PROPERTY_CUBE_SPECIFICATION);
    final String cubeName = desiredSurface.getConstraint(ValuePropertyNames.CUBE);
    final String curveName = desiredSurface.getConstraint(ValuePropertyNames.CURVE);
    final String curveCalculationMethod = desiredSurface
            .getConstraint(ValuePropertyNames.CURVE_CALCULATION_METHOD);
    final Object volatilityDataObject = inputs
            .getValue(getCubeDataRequirement(target, cubeName, definitionName, specificationName));
    if (volatilityDataObject == null) {
        throw new OpenGammaRuntimeException("Could not get swaption volatility cube data");
    }
    final String uniqueId = target.getUniqueId().getValue();
    final Currency currency = Currency.of(uniqueId);
    final String fullSpecificationName = specificationName + "_" + uniqueId;
    final String fullDefinitionName = definitionName + "_" + uniqueId;
    final SwaptionVolatilityCubeSpecification specification = specificationSource
            .getSpecification(fullSpecificationName);
    if (specification == null) {
        throw new OpenGammaRuntimeException(
                "Could not get swaption volatility cube specification name " + fullSpecificationName);
    }
    final VolatilityCubeDefinition definition = definitionSource.getDefinition(currency, fullDefinitionName);
    if (definition == null) {
        throw new OpenGammaRuntimeException(
                "Could not get swaption volatility cube definition name " + fullDefinitionName);
    }
    final DoubleMatrix1D initialValues = getInitialParameters(desiredSurface);
    final BitSet fixed = getFixedParameters(desiredSurface);
    final String epsValue = desiredSurface.getConstraint(PROPERTY_EPS);
    final double eps = Double.parseDouble(epsValue);
    final GridInterpolator2D interpolator = getInterpolator(desiredSurface);
    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<DoublesPair, DoubleMatrix2D>();
    final Map<Pair<Tenor, Tenor>, ExternalId[]> fittedSmileIds = new HashMap<Pair<Tenor, Tenor>, ExternalId[]>();
    final Map<Pair<Tenor, Tenor>, Double[]> fittedRelativeStrikes = new HashMap<Pair<Tenor, Tenor>, Double[]>();
    final List<Tenor> swapTenorData = definition.getSwapTenors();
    final List<Tenor> swaptionExpiryData = definition.getOptionExpiries();
    final List<Double> relativeStrikeData = definition.getRelativeStrikes();
    final VolatilityCubeData volatilityCubeData = (VolatilityCubeData) volatilityDataObject;
    final Map<VolatilityPoint, Double> dataPoint = volatilityCubeData.getDataPoints();
    final Map<VolatilityPoint, ExternalId> idPoint = volatilityCubeData.getDataIds();
    for (final Tenor swapTenor : swapTenorData) {
        final double maturity = getTime(swapTenor);
        for (final Tenor swaptionExpiry : swaptionExpiryData) {
            final Object forwardCurveObject = inputs.getValue(getForwardCurveRequirement(target, curveName,
                    curveCalculationMethod, swaptionExpiry.getPeriod().toString()));
            if (forwardCurveObject == null) {
                s_logger.error("Could not get forward curve for swap tenor " + swapTenor);
                continue;
            }
            final ForwardCurve forwardCurve = (ForwardCurve) forwardCurveObject;
            final double expiry = getTime(swaptionExpiry);
            final double forward = forwardCurve.getForward(maturity);
            final DoubleArrayList smileStrikes = new DoubleArrayList();
            final DoubleArrayList smileBlackVols = new DoubleArrayList();
            final DoubleArrayList errors = new DoubleArrayList();
            final ObjectArrayList<ExternalId> externalIds = new ObjectArrayList<ExternalId>();
            final ObjectArrayList<Double> smileDeltas = new ObjectArrayList<Double>();
            for (final double relativeStrike : relativeStrikeData) {
                final VolatilityPoint volatilityPoint = new VolatilityPoint(swapTenor, swaptionExpiry,
                        relativeStrike);
                final Double vol = dataPoint.get(volatilityPoint);
                if (vol != null) {
                    final double strike = forward + relativeStrike;
                    smileStrikes.add(strike);
                    smileBlackVols.add(vol);
                    errors.add(eps);
                    externalIds.add(idPoint.get(volatilityPoint));
                }
            }
            if (smileStrikes.size() > 4 && forward > 0) { //don't fit those smiles with insufficient data
                final LeastSquareResultsWithTransform fittedResult = new SABRModelFitter(forward,
                        smileStrikes.toDoubleArray(), expiry, smileBlackVols.toDoubleArray(),
                        errors.toDoubleArray(), SABR_FUNCTION).solve(initialValues, fixed);
                final DoubleMatrix1D parameters = fittedResult.getModelParameters();
                swapMaturitiesList.add(maturity);
                swaptionExpiriesList.add(expiry);
                alphaList.add(parameters.getEntry(0));
                betaList.add(parameters.getEntry(1));
                rhoList.add(parameters.getEntry(2));
                nuList.add(parameters.getEntry(3));
                final Pair<Tenor, Tenor> tenorPair = Pair.of(swapTenor, swaptionExpiry);
                final DoublesPair expiryMaturityPair = new DoublesPair(expiry, maturity);
                inverseJacobians.put(expiryMaturityPair, fittedResult.getModelParameterSensitivityToData());
                chiSqList.add(fittedResult.getChiSq());
                fittedSmileIds.put(tenorPair, externalIds.toArray(EMPTY_ARRAY));
                fittedRelativeStrikes.put(tenorPair, smileDeltas.toArray(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY));
            }
        }
    }
    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 ValueProperties properties = getResultProperties(target, desiredSurface);
    final ValueSpecification sabrSurfacesSpecification = new ValueSpecification(
            ValueRequirementNames.SABR_SURFACES, target.toSpecification(), properties);
    final ValueSpecification smileIdsSpecification = new ValueSpecification(
            ValueRequirementNames.VOLATILITY_CUBE_FITTED_POINTS, target.toSpecification(), properties);
    return Sets.newHashSet(new ComputedValue(sabrSurfacesSpecification, fittedSurfaces), new ComputedValue(
            smileIdsSpecification, new FittedSmileDataPoints(fittedSmileIds, fittedRelativeStrikes)));
}