Class BasisPoints


  • public final class BasisPoints
    extends Object
    A percentage amount, with a maximum of 8 decimal places.

    A number has three standard representations in finance:

    • decimal form - the form needed for mathematical calculations, as used by most parts of Strata
    • percentage - where 1.2% is the same as the decimal 0.012
    • basis points - where 120bps is the same as the decimal 0.012
    This class allows the use of basis points form to be explicit.
    • Field Detail

      • ZERO

        public static final BasisPoints ZERO
        A basis points of zero.
    • Method Detail

      • of

        public static BasisPoints of​(double basisPoints)
        Obtains an instance from a basis points value.
        Parameters:
        basisPoints - the basis points value
        Returns:
        the basis points object, rounded (HALF_UP) to 8 decimal places
      • of

        public static BasisPoints of​(Decimal basisPoints)
        Obtains an instance from a basis points value.
        Parameters:
        basisPoints - the basis points value
        Returns:
        the basis points object, rounded (HALF_UP) to 8 decimal places
      • fromDecimalForm

        public static BasisPoints fromDecimalForm​(double decimal)
        Obtains an instance from mathematical decimal form, where 0.007 will create an instance representing 70bps.
        Parameters:
        decimal - the mathematical decimal value
        Returns:
        the basis points object, rounded (HALF_UP) to 8 decimal places
      • fromDecimalForm

        public static BasisPoints fromDecimalForm​(Decimal decimal)
        Obtains an instance from mathematical decimal form, where 0.007 will create an instance representing 70bps.
        Parameters:
        decimal - the mathematical decimal value
        Returns:
        the basis points object, rounded (HALF_UP) to 8 decimal places
      • fromPercentage

        public static BasisPoints fromPercentage​(Percentage percentage)
        Obtains an instance from a percentage, where 0.7% will create an instance representing 70bps.
        Parameters:
        percentage - the percentage
        Returns:
        the basis points object
      • parse

        public static BasisPoints parse​(String str)
        Parses a percentage.

        The percentage may be suffixed by 'bps'.

        Parameters:
        str - the basis points string
        Returns:
        the basis points object, rounded to 8 decimal places
      • valueBasisPoints

        public Decimal valueBasisPoints()
        Gets the value in basis points form as a Decimal.

        A value of 150bps will return 150.

        Returns:
        the value in basis points form, with a maximum of 8 decimal places
      • toDecimalForm

        public Decimal toDecimalForm()
        Converts this basis points to mathematical decimal form.

        A value of 150bps will return 0.015.

        Returns:
        the amount in mathematical decimal form
      • toPercentage

        public Percentage toPercentage()
        Converts this basis points to the equivalent percentage.

        A value of 150bps will return 1.5%.

        Returns:
        the amount in percentage form
      • plus

        public BasisPoints plus​(BasisPoints other)
        Returns a basis points equal to the this basis points plus the other one.
        Parameters:
        other - the other basis points
        Returns:
        the resulting basis points
      • minus

        public BasisPoints minus​(BasisPoints other)
        Returns a basis points equal to the this basis points minus the other one.
        Parameters:
        other - the other basis points
        Returns:
        the resulting basis points
      • map

        public BasisPoints map​(UnaryOperator<Decimal> mapper)
        Applies an operation to the value.

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

           abs = base.map(value -> value.abs());
         
        Parameters:
        mapper - the operator to be applied to the amount
        Returns:
        a copy of this value with the mapping applied to the original amount
      • equals

        public boolean equals​(Object obj)
        Checks if this instance equals another.
        Overrides:
        equals in class Object
        Parameters:
        obj - the other instance
        Returns:
        true if equal
      • hashCode

        public int hashCode()
        Returns a suitable hash code.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • toString

        public String toString()
        Returns the formal string representation, '{value}bps'.
        Overrides:
        toString in class Object
        Returns:
        the formal string