Here you can find the source of rebucketingArray(List
Parameter | Description |
---|---|
targetDates | the list of dates for the re-bucketing |
rebucketedSensitivityAmounts | the array of sensitivities; the array is modified by the method |
sensitivityAmount | the value of the sensitivity at the given data |
sensitivityDate | the date associated to the amount to re-bucket |
private static void rebucketingArray(List<LocalDate> targetDates, double[] rebucketedSensitivityAmounts, double sensitivityAmount, LocalDate sensitivityDate)
//package com.java2s; /**/*w w w .j a va 2s .c om*/ * Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ import java.time.LocalDate; import java.util.List; public class Main { /** * Re-bucket one sensitivity at a specific date and add it to an existing array. * * @param targetDates the list of dates for the re-bucketing * @param rebucketedSensitivityAmounts the array of sensitivities; the array is modified by the method * @param sensitivityAmount the value of the sensitivity at the given data * @param sensitivityDate the date associated to the amount to re-bucket */ private static void rebucketingArray(List<LocalDate> targetDates, double[] rebucketedSensitivityAmounts, double sensitivityAmount, LocalDate sensitivityDate) { int nbBuckets = targetDates.size(); if (!sensitivityDate.isAfter(targetDates.get(0))) { rebucketedSensitivityAmounts[0] += sensitivityAmount; } else if (!sensitivityDate.isBefore(targetDates.get(nbBuckets - 1))) { rebucketedSensitivityAmounts[nbBuckets - 1] += sensitivityAmount; } else { int indexSensitivityDate = 0; while (sensitivityDate.isAfter(targetDates.get(indexSensitivityDate))) { indexSensitivityDate++; } // 'indexSensitivityDate' contains the index of the node after the sensitivity date long intervalLength = targetDates.get(indexSensitivityDate).toEpochDay() - targetDates.get(indexSensitivityDate - 1).toEpochDay(); double weight = ((double) (targetDates.get(indexSensitivityDate).toEpochDay() - sensitivityDate.toEpochDay())) / intervalLength; rebucketedSensitivityAmounts[indexSensitivityDate - 1] += weight * sensitivityAmount; rebucketedSensitivityAmounts[indexSensitivityDate] += (1.0d - weight) * sensitivityAmount; } } }