本文整理汇总了Java中it.unimi.dsi.fastutil.doubles.DoubleArrayList.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleArrayList.toArray方法的具体用法?Java DoubleArrayList.toArray怎么用?Java DoubleArrayList.toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.doubles.DoubleArrayList
的用法示例。
在下文中一共展示了DoubleArrayList.toArray方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSurfaceFromVolatilityQuote
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private static VolatilitySurfaceData<Double, Double> getSurfaceFromVolatilityQuote(final VolatilitySurfaceData<Number, Double> optionVolatilities, final ZonedDateTime now,
final Calendar calendar) {
final BondFutureOptionExpiryCalculator expiryCalculator = BondFutureOptionExpiryCalculator.getInstance();
final Map<Pair<Double, Double>, Double> volatilityValues = new HashMap<Pair<Double, Double>, Double>();
final DoubleArrayList tList = new DoubleArrayList();
final DoubleArrayList kList = new DoubleArrayList();
final LocalDate today = now.toLocalDate();
final Object[] xs = optionVolatilities.getXs();
for (final Object xObj : xs) {
Number x = (Number) xObj;
final Double t = TimeCalculator.getTimeBetween(today, expiryCalculator.getExpiryDate(x.intValue(), today, calendar));
final Object[] ys = optionVolatilities.getYs();
for (final Object yObj : ys) {
Double y = (Double) yObj;
final Double volatility = optionVolatilities.getVolatility(x, y);
if (volatility != null) {
tList.add(t);
kList.add(y / 100.);
volatilityValues.put(Pairs.of(t, y / 100.), volatility / 100); // TODO Normalisation, could this be done elsewhere?
}
}
}
return new VolatilitySurfaceData<Double, Double>(optionVolatilities.getDefinitionName(), optionVolatilities.getSpecificationName(), optionVolatilities.getTarget(),
tList.toArray(new Double[0]), kList.toArray(new Double[0]), volatilityValues);
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:BondFutureOptionVolatilitySurfaceDataFunction.java
示例2: getSurface
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private static VolatilitySurfaceData<Double, Double> getSurface(final VolatilitySurfaceData<Tenor, Tenor> volatilities) {
final Map<Pair<Double, Double>, Double> volatilityValues = new HashMap<Pair<Double, Double>, Double>();
final DoubleArrayList xList = new DoubleArrayList();
final DoubleArrayList yList = new DoubleArrayList();
for (final Tenor x : volatilities.getUniqueXValues()) {
final double xTime = getTime(x);
final List<ObjectsPair<Tenor, Double>> yValuesForX = volatilities.getYValuesForX(x);
for (final ObjectsPair<Tenor, Double> pair : yValuesForX) {
final double yTime = getTime(pair.getFirst());
final Double volatility = pair.getSecond();
if (volatility != null) {
xList.add(xTime);
yList.add(yTime);
volatilityValues.put(DoublesPair.of(xTime, yTime), volatility);
}
}
}
return new VolatilitySurfaceData<Double, Double>(volatilities.getDefinitionName(), volatilities.getSpecificationName(), volatilities.getTarget(), xList.toArray(new Double[0]),
yList.toArray(new Double[0]), volatilityValues);
}
示例3: getSurfaceFromVolatilityQuote
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/** Build a volatility surface based on Expiry, T, and Strike, K. T is in measured in our standard OG-Analytic years */
private static VolatilitySurfaceData<Double, Double> getSurfaceFromVolatilityQuote(final VolatilitySurfaceData<Object, Object> optionVolatilities, final ZonedDateTime now,
final Calendar calendar) {
final Map<Pair<Double, Double>, Double> volatilityValues = new HashMap<>();
final DoubleArrayList tList = new DoubleArrayList();
final DoubleArrayList kList = new DoubleArrayList();
final LocalDate today = now.toLocalDate();
final Object[] xs = optionVolatilities.getXs();
for (final Object xObj : optionVolatilities.getXs()) {
final Number x = (Number) xObj;
final Double t = FutureOptionUtils.getIRFutureOptionTtm(x.intValue(), today, calendar);
final Object[] ys = optionVolatilities.getYs();
for (final Object yObj : ys) {
final Double y = (Double) yObj;
final Double volatility = optionVolatilities.getVolatility(x, y);
if (volatility != null) {
tList.add(t);
kList.add(y / 100.);
volatilityValues.put(Pairs.of(t, y / 100.), volatility / 100); // TODO Normalisation, could this be done elsewhere?
}
}
}
return new VolatilitySurfaceData<>(optionVolatilities.getDefinitionName(), optionVolatilities.getSpecificationName(), optionVolatilities.getTarget(), tList.toArray(new Double[0]),
kList.toArray(new Double[0]), volatilityValues);
}
示例4: 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
示例5: getSurfaceFromVolatilityQuote
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private static VolatilitySurfaceData<Double, Double> getSurfaceFromVolatilityQuote(final LocalDate valDate, final VolatilitySurfaceData<Object, Object> 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();
final Object[] xs = rawSurface.getXs();
for (final Object x : xs) {
Double t;
if (x instanceof Number) {
t = FutureOptionExpiries.EQUITY.getFutureOptionTtm(((Number) x).intValue(), valDate);
} else if (x instanceof LocalDate) {
t = TimeCalculator.getTimeBetween((LocalDate) x, valDate);
} else {
throw new OpenGammaRuntimeException("Cannot not handle surfaces with x-axis type " + x.getClass());
}
if (t > 5. / 365.) { // Bootstrapping vol surface to this data causes far more trouble than any gain. The data simply isn't reliable.
final Double[] ysAsDoubles = getYs(rawSurface.getYs());
for (final Double strike : ysAsDoubles) {
final Double vol = rawSurface.getVolatility(x, 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;
}
示例6: join
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
* Joins arrays together, if only one array contains elements it will be returned without coping anything. <br>
* If given array or arrays is empty, new empty array will be returned.
*
* @param arrays arrays to join.
*
* @return new joined array, or one of given ones if other arrays were empty.
*/
public static double[] join(final double[]... arrays)
{
if (arrays.length == 0)
{
return EMPTY_DOUBLES;
}
if (arrays.length == 1)
{
return arrays[0];
}
if (arrays.length == 2)
{
return join(arrays[0], arrays[1]);
}
double[] notNull = null;
int finalSize = 0;
int nullArrays = 0;
final DoubleArrayList list = new DoubleArrayList(arrays.length * 10);
for (final double[] array : arrays)
{
if ((array == null) || (array.length == 0))
{
nullArrays++;
}
else
{
notNull = array;
finalSize += array.length;
list.addElements(list.size(), array);
}
}
if (nullArrays == arrays.length)
{
return EMPTY_DOUBLES;
}
if (nullArrays == (arrays.length - 1))
{
return notNull;
}
return list.toArray(new double[list.size()]);
}
示例7: getSurfaceFromPriceQuote
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private static VolatilitySurfaceData<Double, Double> getSurfaceFromPriceQuote(final LocalDate valDate, final VolatilitySurfaceData<Pair<Integer, Tenor>, Double> rawSurface,
final ForwardCurve forwardCurve, final VolatilitySurfaceSpecification specification) {
final String surfaceQuoteType = specification.getSurfaceQuoteType();
double callAboveStrike = 0;
if (specification.getSurfaceInstrumentProvider() instanceof CallPutSurfaceInstrumentProvider) {
callAboveStrike = ((CallPutSurfaceInstrumentProvider<?, ?>) specification.getSurfaceInstrumentProvider()).useCallAboveStrike();
}
// Remove empties, convert expiries from number to years, and imply 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
final double forward = forwardCurve.getForward(t);
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 price = rawSurface.getVolatility(nthExpiry, strike);
if (price != null) {
try {
final double vol;
if (surfaceQuoteType.equals(SurfaceAndCubeQuoteType.CALL_STRIKE)) {
vol = BlackFormulaRepository.impliedVolatility(price, forward, strike, t, true);
} else if (surfaceQuoteType.equals(SurfaceAndCubeQuoteType.PUT_STRIKE)) {
vol = BlackFormulaRepository.impliedVolatility(price, forward, strike, t, false);
} else if (surfaceQuoteType.equals(SurfaceAndCubeQuoteType.CALL_AND_PUT_STRIKE)) {
final boolean isCall = strike > callAboveStrike ? true : false;
vol = BlackFormulaRepository.impliedVolatility(price, forward, strike, t, isCall);
} else {
throw new OpenGammaRuntimeException("Cannot handle surface quote type " + surfaceQuoteType);
}
tList.add(t);
kList.add(strike);
volValues.put(Pairs.of(t, strike), vol);
} catch (final Exception e) {
}
}
}
}
}
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,代码行数:44,代码来源:EquityFutureOptionVolatilitySurfaceDataFunction.java
示例8: execute
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
/**
* {@inheritDoc} <p>
* INPUT: We are taking a VolatilitySurfaceData object, which contains all number of missing data, plus strikes and vols are in percentages <p>
* OUTPUT: and converting this into a StandardVolatilitySurfaceData object, which has no empty values, expiry is in years, and the strike and vol scale is without unit (35% -> 0.35)
*/
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
final ZonedDateTime valTime = ZonedDateTime.now(executionContext.getValuationClock());
final LocalDate valDate = valTime.toLocalDate();
final Currency currency = (Currency) target.getValue();
final Calendar calendar = new HolidaySourceCalendarAdapter(OpenGammaExecutionContext.getHolidaySource(executionContext), currency);
// 1. Build the surface name, in two parts: the given name and the target
final ValueRequirement desiredValue = desiredValues.iterator().next();
final String surfaceName = desiredValue.getConstraint(ValuePropertyNames.SURFACE);
// 2. Get the RawEquityVolatilitySurfaceData object
final Object rawSurfaceObject = inputs.getValue(ValueRequirementNames.VOLATILITY_SURFACE_DATA);
if (rawSurfaceObject == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface");
}
@SuppressWarnings("unchecked")
final VolatilitySurfaceData<Number, Double> rawSurface = (VolatilitySurfaceData<Number, Double>) rawSurfaceObject;
//2a Get forward curve
final Object forwardCurveObject = inputs.getValue(ValueRequirementNames.FORWARD_CURVE);
if (forwardCurveObject == null) {
throw new OpenGammaRuntimeException("Could not get forward curve");
}
final ForwardCurve forwardCurve = (ForwardCurve) forwardCurveObject;
// 3. Remove empties, convert expiries from number to years, and scale vols
final Map<Pair<Double, Double>, Double> volValues = new HashMap<Pair<Double, Double>, Double>();
final DoubleArrayList tList = new DoubleArrayList();
final DoubleArrayList kList = new DoubleArrayList();
// SurfaceInstrumentProvider just used to get expiry calculator - find a better way as this is quite ugly.
final String surfacePrefix = surfaceName.split("\\_")[1];
final ExchangeTradedInstrumentExpiryCalculator expiryCalculator = new BloombergCommodityFutureOptionVolatilitySurfaceInstrumentProvider(surfacePrefix, "Comdty", "", 0., "")
.getExpiryRuleCalculator();
for (final Number nthExpiry : rawSurface.getXs()) {
final double t = TimeCalculator.getTimeBetween(valDate, expiryCalculator.getExpiryDate(nthExpiry.intValue(), valDate, calendar));
if (!isValidStrike(forwardCurve, rawSurface, t, nthExpiry)) {
continue;
}
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<Double, Double>(rawSurface.getDefinitionName(), rawSurface.getSpecificationName(),
rawSurface.getTarget(), tList.toArray(new Double[0]), kList.toArray(new Double[0]), volValues);
// 4. Return
final ValueProperties stdVolProperties = createValueProperties().with(ValuePropertyNames.SURFACE, surfaceName)
.with(InstrumentTypeProperties.PROPERTY_SURFACE_INSTRUMENT_TYPE, InstrumentTypeProperties.COMMODITY_FUTURE_OPTION).get();
final ValueSpecification stdVolSpec = new ValueSpecification(ValueRequirementNames.STANDARD_VOLATILITY_SURFACE_DATA, target.toSpecification(), stdVolProperties);
return Collections.singleton(new ComputedValue(stdVolSpec, stdVolSurface));
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:69,代码来源:CommodityOptionVolatilitySurfaceDataFunction.java
示例9: calculateCorrelations
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private double[][] calculateCorrelations(double[][] results, String datasetNames[]) {
DatasetMetaDataMapping mapping = DatasetMetaDataMapping.getInstance();
DatasetMetaData metadata[] = new DatasetMetaData[datasetNames.length];
for (int i = 0; i < datasetNames.length; ++i) {
metadata[i] = mapping.getMetaData(datasetNames[i]);
}
double correlations[][] = new double[results.length][CORRELATION_TABLE_COLUMN_HEADINGS.length];
DoubleArrayList annotatorResults = new DoubleArrayList(datasetNames.length);
DoubleArrayList numberOfDocuments = new DoubleArrayList(datasetNames.length);
DoubleArrayList avgDocumentLength = new DoubleArrayList(datasetNames.length);
DoubleArrayList numberOfEntities = new DoubleArrayList(datasetNames.length);
DoubleArrayList entitiesPerDoc = new DoubleArrayList(datasetNames.length);
DoubleArrayList entitiesPerToken = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfPersons = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfOrganizations = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfLocations = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfOthers = new DoubleArrayList(datasetNames.length);
double annotatorResultsAsArray[];
int elementCount;
for (int i = 0; i < correlations.length; ++i) {
Arrays.fill(correlations[i], NOT_AVAILABLE_SENTINAL);
// load the values for this annotator
annotatorResults.clear();
numberOfDocuments.clear();
avgDocumentLength.clear();
numberOfEntities.clear();
entitiesPerDoc.clear();
entitiesPerToken.clear();
amountOfPersons.clear();
amountOfOrganizations.clear();
amountOfLocations.clear();
amountOfOthers.clear();
for (int j = 0; j < results[i].length; ++j) {
if ((metadata[j] != null) && (results[i][j] >= 0)) {
annotatorResults.add(results[i][j]);
numberOfDocuments.add(metadata[j].numberOfDocuments);
avgDocumentLength.add(metadata[j].avgDocumentLength);
numberOfEntities.add(metadata[j].numberOfEntities);
entitiesPerDoc.add(metadata[j].entitiesPerDoc);
entitiesPerToken.add(metadata[j].entitiesPerToken);
amountOfPersons.add(metadata[j].amountOfPersons);
amountOfOrganizations.add(metadata[j].amountOfOrganizations);
amountOfLocations.add(metadata[j].amountOfLocations);
amountOfOthers.add(metadata[j].amountOfOthers);
}
}
// If we have enough datasets with metadata and results of the
// current annotator for these datasets
elementCount = annotatorResults.size();
if (elementCount > MIN_NUMBER_OF_VALUES_FOR_CORR_CALC) {
annotatorResultsAsArray = annotatorResults.toArray(new double[elementCount]);
correlations[i][0] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, numberOfDocuments.toArray(new double[elementCount]));
correlations[i][1] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, avgDocumentLength.toArray(new double[elementCount]));
correlations[i][2] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, numberOfEntities.toArray(new double[elementCount]));
correlations[i][3] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, entitiesPerDoc.toArray(new double[elementCount]));
correlations[i][4] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, entitiesPerToken.toArray(new double[elementCount]));
correlations[i][5] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfPersons.toArray(new double[elementCount]));
correlations[i][6] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfOrganizations.toArray(new double[elementCount]));
correlations[i][7] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfLocations.toArray(new double[elementCount]));
correlations[i][8] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfOthers.toArray(new double[elementCount]));
// correlations[i][9] = annotatorResultsAsArray.length;
}
}
return correlations;
}