Java LocalDate Calculate rebucketingArray(List targetDates, double[] rebucketedSensitivityAmounts, double sensitivityAmount, LocalDate sensitivityDate)

Here you can find the source of rebucketingArray(List targetDates, double[] rebucketedSensitivityAmounts, double sensitivityAmount, LocalDate sensitivityDate)

Description

Re-bucket one sensitivity at a specific date and add it to an existing array.

License

Open Source License

Parameter

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

Declaration

private static void rebucketingArray(List<LocalDate> targetDates, double[] rebucketedSensitivityAmounts,
        double sensitivityAmount, LocalDate sensitivityDate) 

Method Source Code

//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;
        }
    }
}

Related

  1. obtenirLocalDateAPartirDUneDate(Date date)
  2. oneDayAfterNotificationRequired(LocalDate requestDate, LocalDate vehicleDetailsMotExpiryDate)
  3. parseDate(LocalDate date)
  4. period(LocalDate startDate, LocalDate endDate)
  5. plusDays(LocalDate date, int daysToAdd)
  6. roundDown(final LocalDate dateTime, final TemporalUnit temporalUnit, final int size)
  7. stream(LocalDate startInclusive, LocalDate endExclusive)
  8. stringDateToLocalDate(String day, String month, String year)
  9. stringToLocalDate(String birthDate)