Class Swap
- java.lang.Object
-
- com.opengamma.strata.product.swap.Swap
-
- All Implemented Interfaces:
Resolvable<ResolvedSwap>
,Product
,Serializable
,org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class Swap extends Object implements Product, Resolvable<ResolvedSwap>, org.joda.beans.ImmutableBean, 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Swap.Builder
The bean-builder forSwap
.static class
Swap.Meta
The meta-bean forSwap
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableSet<Currency>
allCurrencies()
Returns the set of currencies referred to by the swap.ImmutableSet<Index>
allIndices()
Returns the set of indices referred to by the swap.ImmutableSet<Currency>
allPaymentCurrencies()
Returns the set of payment currencies referred to by the swap.static Swap.Builder
builder()
Returns a builder used to create an instance of the bean.boolean
equals(Object obj)
AdjustableDate
getEndDate()
Gets the accrual end date of the swap.Optional<SwapLeg>
getLeg(PayReceive payReceive)
Gets the first pay or receive leg of the swap.ImmutableList<SwapLeg>
getLegs()
Gets the legs of the swap.ImmutableList<SwapLeg>
getLegs(SwapLegType type)
Gets the legs of the swap with the specified type.Optional<SwapLeg>
getPayLeg()
Gets the first pay leg of the swap.Optional<SwapLeg>
getReceiveLeg()
Gets the first receive leg of the swap.AdjustableDate
getStartDate()
Gets the accrual start date of the swap.int
hashCode()
static Swap.Meta
meta()
The meta-bean forSwap
.Swap.Meta
metaBean()
static Swap
of(SwapLeg... legs)
Creates a swap from one or more swap legs.static Swap
of(List<? extends SwapLeg> legs)
Creates a swap from one or more swap legs.Swap
replaceStartDate(LocalDate adjustedStartDate)
Returns an instance based on this swap with the start date replaced.ResolvedSwap
resolve(ReferenceData refData)
Resolves this object using the specified reference data.String
summaryDescription()
Summarizes this swap into string form.Swap.Builder
toBuilder()
Returns a builder that allows this bean to be mutated.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.opengamma.strata.product.Product
isCrossCurrency
-
-
-
-
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(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 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 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 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 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 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 interfaceProduct
- Returns:
- the set of payment currencies referred to by this swap
-
allCurrencies
public 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 interfaceProduct
- Returns:
- the set of currencies referred to by this swap
-
allIndices
public 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 String summaryDescription()
Summarizes this swap into string form.- Returns:
- the summary description
-
replaceStartDate
public Swap replaceStartDate(LocalDate adjustedStartDate)
Returns an instance based on this swap with the start date replaced.This is used to change the start date of the swap, and is currently used by
Swaption
.- Parameters:
adjustedStartDate
- the new adjusted start date- Returns:
- the updated swap
- Throws:
IllegalArgumentException
- if the start date cannot be replaced with the proposed start dateUnsupportedOperationException
- if changing the start date is not supported
-
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 interfaceResolvable<ResolvedSwap>
- Parameters:
refData
- the reference data to use when resolving- Returns:
- the resolved instance
-
meta
public static Swap.Meta meta()
The meta-bean forSwap
.- 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
-
metaBean
public Swap.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getLegs
public 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
-
-