Class MutablePointSensitivities

  • All Implemented Interfaces:
    PointSensitivityBuilder

    public final class MutablePointSensitivities
    extends Object
    implements PointSensitivityBuilder
    Mutable builder for sensitivity to a group of curves.

    Contains a mutable list of point sensitivity objects, each referring to a specific point on a curve that was queried. The order of the list has no specific meaning, but does allow duplicates.

    This is a mutable builder that is not intended for use in multiple threads. It is intended to be used to create an immutable PointSensitivities instance. Note that each individual point sensitivity implementation is immutable.

    • Constructor Detail

      • MutablePointSensitivities

        public MutablePointSensitivities()
        Creates an empty instance.
      • MutablePointSensitivities

        public MutablePointSensitivities​(PointSensitivity sensitivity)
        Creates an instance with the specified sensitivity.
        Parameters:
        sensitivity - the sensitivity to add
      • MutablePointSensitivities

        public MutablePointSensitivities​(List<? extends PointSensitivity> sensitivities)
        Creates an instance with the specified sensitivities.
        Parameters:
        sensitivities - the list of sensitivities, which is copied
    • Method Detail

      • size

        public int size()
        Gets the number of sensitivity entries.
        Returns:
        the size of the internal list of point sensitivities
      • getSensitivities

        public ImmutableList<PointSensitivity> getSensitivities()
        Gets the immutable list of point sensitivities.

        Each entry includes details of the curve it relates to.

        Returns:
        the immutable list of sensitivities
      • add

        public MutablePointSensitivities add​(PointSensitivity sensitivity)
        Adds a point sensitivity, mutating the internal list.

        This instance will be mutated, with the new sensitivity added at the end of the list.

        Parameters:
        sensitivity - the sensitivity to add
        Returns:
        this, for method chaining
      • addAll

        public MutablePointSensitivities addAll​(List<PointSensitivity> sensitivities)
        Adds a list of point sensitivities, mutating the internal list.

        This instance will be mutated, with the new sensitivities added at the end of the list.

        Parameters:
        sensitivities - the sensitivities to add
        Returns:
        this, for method chaining
      • addAll

        public MutablePointSensitivities addAll​(MutablePointSensitivities other)
        Merges the list of point sensitivities from another instance, mutating the internal list.

        This instance will be mutated, with the new sensitivities added at the end of the list.

        Parameters:
        other - the other sensitivity to add
        Returns:
        this, for method chaining
      • withCurrency

        public MutablePointSensitivities withCurrency​(Currency currency)
        Description copied from interface: PointSensitivityBuilder
        Returns an instance with the specified currency applied to the sensitivities in this builder.

        The result will consists of the same points, but with the sensitivity currency assigned.

        Builders may be mutable. Once this method is called, this instance must not be used. Instead, the result of the method must be used.

        Specified by:
        withCurrency in interface PointSensitivityBuilder
        Parameters:
        currency - the currency to be applied to the sensitivities
        Returns:
        the resulting builder, replacing this builder
      • multipliedBy

        public MutablePointSensitivities multipliedBy​(double factor)
        Description copied from interface: PointSensitivityBuilder
        Multiplies the sensitivities in this builder by the specified factor.

        The result will consist of the same points, but with each sensitivity multiplied.

        Builders may be mutable. Once this method is called, this instance must not be used. Instead, the result of the method must be used.

        Specified by:
        multipliedBy in interface PointSensitivityBuilder
        Parameters:
        factor - the multiplicative factor
        Returns:
        the resulting builder, replacing this builder
      • mapSensitivity

        public MutablePointSensitivities mapSensitivity​(DoubleUnaryOperator operator)
        Description copied from interface: PointSensitivityBuilder
        Returns an instance with the specified operation applied to the sensitivities in this builder.

        The result will consist of the same points, but with the operator applied to each sensitivity.

        This is used to apply a mathematical operation to the sensitivities. For example, the operator could multiply the sensitivities by a constant, or take the inverse.

           inverse = base.mapSensitivities(value -> 1 / value);
         

        Builders may be mutable. Once this method is called, this instance must not be used. Instead, the result of the method must be used.

        Specified by:
        mapSensitivity in interface PointSensitivityBuilder
        Parameters:
        operator - the operator to be applied to the sensitivities
        Returns:
        the resulting builder, replacing this builder
      • combinedWith

        public MutablePointSensitivities combinedWith​(PointSensitivityBuilder other)
        Description copied from interface: PointSensitivityBuilder
        Combines this sensitivity with another instance.

        This returns an instance with a combined list of point sensitivities.

        Builders may be mutable. Once this method is called, this instance must not be used. Instead, the result of the method must be used.

        Specified by:
        combinedWith in interface PointSensitivityBuilder
        Parameters:
        other - the other sensitivity builder
        Returns:
        the combined builder, replacing this builder and the specified builder
      • cloned

        public MutablePointSensitivities cloned()
        Description copied from interface: PointSensitivityBuilder
        Clones the point sensitivity builder.

        This returns a PointSensitivityBuilder instance that is independent from the original. Immutable implementations may return themselves.

        Builders may be mutable. Using this method allows a copy of the original to be obtained, so both the original and the clone can be used.

        Specified by:
        cloned in interface PointSensitivityBuilder
        Returns:
        the built combined sensitivity
      • sort

        public MutablePointSensitivities sort()
        Sorts the mutable list of point sensitivities.

        Sorts the point sensitivities in this instance.

        Returns:
        this, for method chaining
      • normalize

        public MutablePointSensitivities normalize()
        Normalizes the point sensitivities by sorting and merging, mutating the internal list.

        The list of sensitivities is sorted and then merged. Any two entries that represent the same curve query are merged. For example, if there are two point sensitivities that were created based on the same curve, currency and fixing date, then the entries are combined, summing the sensitivity value.

        The intention is that normalization occurs after gathering all the point sensitivities.

        Specified by:
        normalize in interface PointSensitivityBuilder
        Returns:
        this, for method chaining
      • toImmutable

        public PointSensitivities toImmutable()
        Returns an immutable version of this object.

        The result is an instance of the immutable PointSensitivities. It will contain the same individual point sensitivities.

        Returns:
        the immutable sensitivity instance, not null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object