本文整理汇总了Java中it.unimi.dsi.fastutil.doubles.DoubleArrayList.add方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleArrayList.add方法的具体用法?Java DoubleArrayList.add怎么用?Java DoubleArrayList.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.doubles.DoubleArrayList
的用法示例。
在下文中一共展示了DoubleArrayList.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: getSurfaceFromVolatilityQuote
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private static VolatilitySurfaceData<Double, Double> getSurfaceFromVolatilityQuote(final LocalDate valDate, final VolatilitySurfaceData<Pair<Integer, Tenor>, Double> rawSurface) {
// Remove empties, convert expiries from number to years, and scale vols
final Map<Pair<Double, Double>, Double> volValues = new HashMap<>();
final DoubleArrayList tList = new DoubleArrayList();
final DoubleArrayList kList = new DoubleArrayList();
for (final Pair<Integer, Tenor> nthExpiry : rawSurface.getXs()) {
final double t = FutureOptionExpiries.EQUITY_FUTURE.getFutureOptionTtm(nthExpiry.getFirst(), valDate, nthExpiry.getSecond()); //TODO need information about expiry calculator
if (t > 5. / 365.) { // Bootstrapping vol surface to this data causes far more trouble than any gain. The data simply isn't reliable.
for (final Double strike : rawSurface.getYs()) {
final Double vol = rawSurface.getVolatility(nthExpiry, strike);
if (vol != null) {
tList.add(t);
kList.add(strike);
volValues.put(Pairs.of(t, strike), vol / 100.);
}
}
}
}
final VolatilitySurfaceData<Double, Double> stdVolSurface = new VolatilitySurfaceData<>(rawSurface.getDefinitionName(), rawSurface.getSpecificationName(), rawSurface.getTarget(),
tList.toArray(new Double[0]), kList.toArray(new Double[0]), volValues);
return stdVolSurface;
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:23,代码来源:EquityFutureOptionVolatilitySurfaceDataFunction.java
示例3: 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());
}
示例4: reduceCurveNodes
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
* Matrix reducing the nodes, to which portfolio has sensitivities, to new nodes (objNodes), for which sensitivity is accounted for, when relevant curves are already known
* @param curves The relevant curves
* @param objNodes The objective nodes on which sensitivity is to be accounted for
* @return The matrix
*/
public DoubleMatrix2D reduceCurveNodes(final YieldAndDiscountCurve[] curves, final double[] objNodes) {
ArgumentChecker.notNull(curves, "curves");
ArgumentChecker.notNull(objNodes, "objNodes");
int nCurves = curves.length;
DoubleArrayList result = new DoubleArrayList();
for (int i = 0; i < nCurves; ++i) {
Double[] nodes = getNodes(curves[i]);
for (final double element : nodes) {
result.add(element);
}
}
int totalNum = result.size();
int[] tmp = toPositions(objNodes, result.toDoubleArray());
int objNum = tmp.length;
double[][] res = new double[objNum][totalNum];
for (int i = 0; i < objNum; ++i) {
Arrays.fill(res[i], 0.0);
res[i][tmp[i]] = 1.0;
}
return new DoubleMatrix2D(res);
}
示例5: 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());
}
示例6: getResult
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
public Interpolator1DDataBundle getResult(final LocalVolatilitySurfaceMoneyness localVolatility, final ForwardCurve forwardCurve, final EuropeanVanillaOption option,
final YieldAndDiscountCurve discountingCurve) {
final PDETerminalResults1D pdeGrid = _pdeCalculator.runPDESolver(localVolatility, option);
final PDEGrid1D grid = pdeGrid.getGrid();
final double expiry = option.getTimeToExpiry();
final boolean isCall = option.isCall();
final double strike = option.getStrike();
final double forward = forwardCurve.getForward(expiry);
final double[] moneynesses = grid.getSpaceNodes();
final double[] modifiedPrices = pdeGrid.getTerminalResults();
final int n = modifiedPrices.length;
final DoubleArrayList strikes = new DoubleArrayList();
final DoubleArrayList prices = new DoubleArrayList();
for (int i = 0; i < n; i++) {
try {
final double impliedVol = BlackFormulaRepository.impliedVolatility(modifiedPrices[i], 1, moneynesses[i], expiry, isCall);
prices.add(BlackFormulaRepository.price(forward, strike, expiry, impliedVol, isCall));
strikes.add(forward * moneynesses[i]);
} catch (final Exception e) {
}
}
return _interpolator.getDataBundleFromSortedArrays(strikes.toDoubleArray(), prices.toDoubleArray());
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:25,代码来源:LocalVolatilityForwardPDEPriceGridCalculator.java
示例7: testDoubleArrayList
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
* Test for ser/de of {@link DoubleArrayList}.
*/
@Test
public void testDoubleArrayList()
throws IOException {
for (int i = 0; i < NUM_ITERATIONS; i++) {
int size = RANDOM.nextInt(100);
DoubleArrayList expected = new DoubleArrayList(size);
for (int j = 0; j < size; j++) {
expected.add(RANDOM.nextDouble());
}
byte[] bytes = ObjectCustomSerDe.serialize(expected);
DoubleArrayList actual = ObjectCustomSerDe.deserialize(bytes, ObjectType.DoubleArrayList);
Assert.assertEquals(actual, expected, ERROR_MESSAGE);
}
}
示例8: getResult
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
public Interpolator1DDataBundle getResult(final LocalVolatilitySurfaceMoneyness localVolatility, final ForwardCurve forwardCurve, final EuropeanVanillaOption option,
final YieldAndDiscountCurve discountingCurve) {
final PDETerminalResults1D pdeGrid = _pdeCalculator.runPDESolver(localVolatility, option);
final PDEGrid1D grid = pdeGrid.getGrid();
final double expiry = option.getTimeToExpiry();
final boolean isCall = option.isCall();
final double strike = option.getStrike();
final double forward = forwardCurve.getForward(expiry);
final double[] moneynesses = grid.getSpaceNodes();
final double[] modifiedPrices = pdeGrid.getFinalTimePrices();
final int n = modifiedPrices.length;
final DoubleArrayList strikes = new DoubleArrayList();
final DoubleArrayList prices = new DoubleArrayList();
for (int i = 0; i < n; i++) {
try {
final double impliedVol = BlackFormulaRepository.impliedVolatility(modifiedPrices[i], 1, moneynesses[i], expiry, isCall);
prices.add(BlackFormulaRepository.price(forward, strike, expiry, impliedVol, isCall));
strikes.add(forward * moneynesses[i]);
} catch (final Exception e) {
}
}
return _interpolator.getDataBundleFromSortedArrays(strikes.toDoubleArray(), prices.toDoubleArray());
}
示例9: evaluate
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
public VaRCalculationResult evaluate(final EmpiricalDistributionVaRParameters parameters, final DoubleTimeSeries<?>... data) {
ArgumentChecker.notNull(parameters, "parameters");
ArgumentChecker.notNull(data, "data");
final double var = _varCalculator.evaluate(parameters, data).getVaRValue();
final DoubleArrayList excesses = new DoubleArrayList();
for (final double portfolioReturn : data[0].valuesArrayFast()) {
if (portfolioReturn < -var) {
excesses.add(portfolioReturn);
}
}
if (excesses.isEmpty()) {
return new VaRCalculationResult(var, null);
}
return new VaRCalculationResult(-_meanCalculator.evaluate(excesses.toDoubleArray()), null);
}
示例10: 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());
}
示例11: 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());
}
示例12: 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());
}
示例13: buildFeatures
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private void buildFeatures(Language lang, String prefix,
DoubleArrayList featureValues, String _label1, String _label2,
String[] l1, String[] l2,
boolean charLevel) {
final String label1 = _label1 == null ? "" : _label1;
final String label2 = _label2 == null ? "" : _label2;
featureValues.add(longestCommonSubsequence(l1, l2));
for(int i = (charLevel ? 2 : 1); i <= (charLevel ? 5 : 4); i++) {
featureValues.add(ngramOverlap(l1, l2, i, charLevel ? ngramWeighting : wordWeighting));
}
final JaccardDice jd = jaccardDice(l1, l2);
featureValues.add(jd.jaccard);
featureValues.add(jd.dice);
featureValues.add(jd.containment);
if(!charLevel) {
featureValues.add(sentenceLengthRatio(label1, label2));
featureValues.add(aveWordLenRatio(l1, l2));
featureValues.add(shareNegation(lang, l1, l2) ? 1.0 : 0.0);
featureValues.add(numberAgree(l1, l2));
}
// featureNames.add(prefix + "gst");
// if(charLevel) {
// String cl1 = label1.replaceAll("", " ").trim();
// String cl2 = label2.replaceAll("", " ").trim();
// featureValues.add(GreedyStringTiling.similarity(cl1, cl2));
// } else {
// featureValues.add(GreedyStringTiling.similarity(label1, label2));
// }
}
示例14: 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();
}
示例15: 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 Clock snapshotClock = executionContext.getValuationClock();
final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
final Object volatilitySurfaceDataObject = inputs.getValue(_requirement);
if (volatilitySurfaceDataObject == null) {
throw new OpenGammaRuntimeException("Could not get " + _requirement);
}
@SuppressWarnings("unchecked")
final VolatilitySurfaceData<LocalDate, Double> volatilitySurfaceData = (VolatilitySurfaceData<LocalDate, Double>) volatilitySurfaceDataObject;
final int n = volatilitySurfaceData.getXs().length;
final int m = volatilitySurfaceData.getYs().length;
final DoubleArrayList t = new DoubleArrayList();
final DoubleArrayList k = new DoubleArrayList();
final DoubleArrayList sigma = new DoubleArrayList();
final LocalDate[] xDates = volatilitySurfaceData.getXs();
final Double[] y = volatilitySurfaceData.getYs();
for (int i = 0; i < n; i++) {
final Double time = DateUtils.getDifferenceInYears(now.toLocalDate(), xDates[i]);
for (int j = 0; j < m; j++) {
final Double strike = y[j];
final Double vol = volatilitySurfaceData.getVolatility(xDates[i], y[j]);
if (time != null && strike != null && vol != null) {
t.add(time);
k.add(strike);
sigma.add(vol);
}
}
}
final Surface<Double, Double, Double> surface = InterpolatedDoublesSurface.from(t.toDoubleArray(), k.toDoubleArray(), sigma.toDoubleArray(), _interpolator);
final VolatilitySurface volatilitySurface = new VolatilitySurface(surface);
return Collections.singleton(new ComputedValue(_result, volatilitySurface));
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:34,代码来源:Grid2DInterpolatedVolatilitySurfaceFunctionDeprecated.java