Class Swap

  • All Implemented Interfaces:
    Resolvable<ResolvedSwap>, Product, java.io.Serializable, Bean, ImmutableBean

    public final class Swap
    extends java.lang.Object
    implements Product, Resolvable<ResolvedSwap>, ImmutableBean, java.io.Serializable
    A rate swap.

    A rate swap is a financial instrument that represents the exchange of streams of payments. The swap is formed of legs, where each leg typically represents the obligations of the seller or buyer of the swap. In the simplest vanilla interest rate swap, there are two legs, one with a fixed rate and the other a floating rate. Many other more complex swaps can also be represented.

    For example, a swap might involve an agreement to exchange the difference between the fixed rate of 1% and the 'GBP-LIBOR-3M' rate every 3 months for 2 years.

    See Also:
    Serialized Form
    • Method Detail

      • of

        public static Swap of​(SwapLeg... legs)
        Creates a swap from one or more swap legs.

        While most swaps have two legs, other combinations are possible.

        Parameters:
        legs - the array of legs
        Returns:
        the swap
      • of

        public static Swap of​(java.util.List<? extends SwapLeg> legs)
        Creates a swap from one or more swap legs.

        While most swaps have two legs, other combinations are possible.

        Parameters:
        legs - the list of legs
        Returns:
        the swap
      • getLegs

        public com.google.common.collect.ImmutableList<SwapLeg> getLegs​(SwapLegType type)
        Gets the legs of the swap with the specified type.

        This returns all the legs with the given type.

        Parameters:
        type - the type to find
        Returns:
        the matching legs of the swap
      • getLeg

        public java.util.Optional<SwapLeg> getLeg​(PayReceive payReceive)
        Gets the first pay or receive leg of the swap.

        This returns the first pay or receive leg of the swap, empty if no matching leg.

        Parameters:
        payReceive - the pay or receive flag
        Returns:
        the first matching leg of the swap
      • getPayLeg

        public java.util.Optional<SwapLeg> getPayLeg()
        Gets the first pay leg of the swap.

        This returns the first pay leg of the swap, empty if no pay leg.

        Returns:
        the first pay leg of the swap
      • getReceiveLeg

        public java.util.Optional<SwapLeg> getReceiveLeg()
        Gets the first receive leg of the swap.

        This returns the first receive leg of the swap, empty if no receive leg.

        Returns:
        the first receive leg of the swap
      • getStartDate

        public AdjustableDate getStartDate()
        Gets the accrual start date of the swap.

        This is the earliest accrual date of the legs, often known as the effective date. The latest date is chosen by examining the unadjusted end date.

        Returns:
        the start date of the swap
      • getEndDate

        public AdjustableDate getEndDate()
        Gets the accrual end date of the swap.

        This is the latest accrual date of the legs, often known as the termination date. The latest date is chosen by examining the unadjusted end date.

        Returns:
        the end date of the swap
      • allPaymentCurrencies

        public com.google.common.collect.ImmutableSet<Currency> allPaymentCurrencies()
        Returns the set of payment currencies referred to by the swap.

        This returns the complete set of payment currencies for the swap. This will typically return one or two currencies.

        If there is an FX reset, then this set contains the currency of the payment, not the currency of the notional. Note that in many cases, the currency of the FX reset notional will be the currency of the other leg.

        Specified by:
        allPaymentCurrencies in interface Product
        Returns:
        the set of payment currencies referred to by this swap
      • allCurrencies

        public com.google.common.collect.ImmutableSet<Currency> allCurrencies()
        Returns the set of currencies referred to by the swap.

        This returns the complete set of currencies for the swap, not just the payment currencies.

        Specified by:
        allCurrencies in interface Product
        Returns:
        the set of currencies referred to by this swap
      • allIndices

        public com.google.common.collect.ImmutableSet<Index> allIndices()
        Returns the set of indices referred to by the swap.

        A swap will typically refer to at least one index, such as 'GBP-LIBOR-3M'. Calling this method will return the complete list of indices, including any associated with FX reset.

        Returns:
        the set of indices referred to by this swap
      • summaryDescription

        public java.lang.String summaryDescription()
        Summarizes this swap into string form.
        Returns:
        the summary description
      • resolve

        public ResolvedSwap resolve​(ReferenceData refData)
        Description copied from interface: Resolvable
        Resolves this object using the specified reference data.

        This converts the object implementing this interface to the equivalent resolved form. All ReferenceDataId identifiers in this instance will be resolved. The resolved form will typically be a type that is optimized for pricing.

        Resolved objects may be bound to data that changes over time, such as holiday calendars. If the data changes, such as the addition of a new holiday, the resolved form will not be updated. Care must be taken when placing the resolved form in a cache or persistence layer.

        Specified by:
        resolve in interface Resolvable<ResolvedSwap>
        Parameters:
        refData - the reference data to use when resolving
        Returns:
        the resolved instance
      • meta

        public static Swap.Meta meta()
        The meta-bean for Swap.
        Returns:
        the meta-bean, not null
      • builder

        public static Swap.Builder builder()
        Returns a builder used to create an instance of the bean.
        Returns:
        the builder, not null
      • getLegs

        public com.google.common.collect.ImmutableList<SwapLeg> getLegs()
        Gets the legs of the swap.

        A swap consists of one or more legs. The legs of a swap are essentially unordered, however it is more efficient and closer to user expectation to treat them as being ordered.

        Returns:
        the value of the property, not empty
      • toBuilder

        public Swap.Builder toBuilder()
        Returns a builder that allows this bean to be mutated.
        Returns:
        the mutable builder, not null
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object