Class GenericSecurityPosition
- java.lang.Object
-
- com.opengamma.strata.product.GenericSecurityPosition
-
- All Implemented Interfaces:
CalculationTarget
,PortfolioItem
,Position
,SecuritizedProductPortfolioItem<GenericSecurity>
,SecuritizedProductPosition<GenericSecurity>
,SecurityQuantity
,Serializable
,org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class GenericSecurityPosition extends Object implements SecuritizedProductPosition<GenericSecurity>, org.joda.beans.ImmutableBean, Serializable
A position in a security, where the security is embedded ready for mark-to-market pricing.This represents a position in a security, defined by long and short quantity. The security is embedded directly, however the underlying product model is not available. The security may be of any kind, including equities, bonds and exchange traded derivatives (ETD).
The net quantity of the position is stored using two fields -
longQuantity
andshortQuantity
. These two fields must not be negative. In many cases, only a long quantity or short quantity will be present with the other set to zero. However it is also possible for both to be non-zero, allowing long and short positions to be treated separately. The net quantity is available viagetQuantity()
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GenericSecurityPosition.Builder
The bean-builder forGenericSecurityPosition
.static class
GenericSecurityPosition.Meta
The meta-bean forGenericSecurityPosition
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GenericSecurityPosition.Builder
builder()
Returns a builder used to create an instance of the bean.boolean
equals(Object obj)
Currency
getCurrency()
Gets the currency of the position.PositionInfo
getInfo()
Gets the additional position information, defaulted to an empty instance.double
getLongQuantity()
Gets the long quantity of the security.GenericSecurity
getProduct()
Gets the product of the security that was traded.double
getQuantity()
Gets the net quantity of the security.GenericSecurity
getSecurity()
Gets the underlying security.SecurityId
getSecurityId()
Gets the identifier of the underlying security.double
getShortQuantity()
Gets the short quantity of the security.int
hashCode()
static GenericSecurityPosition.Meta
meta()
The meta-bean forGenericSecurityPosition
.GenericSecurityPosition.Meta
metaBean()
static GenericSecurityPosition
ofLongShort(GenericSecurity security, double longQuantity, double shortQuantity)
Obtains an instance from the security, long quantity and short quantity.static GenericSecurityPosition
ofLongShort(PositionInfo positionInfo, GenericSecurity security, double longQuantity, double shortQuantity)
Obtains an instance from position information, security, long quantity and short quantity.static GenericSecurityPosition
ofNet(GenericSecurity security, double netQuantity)
Obtains an instance from the security and net quantity.static GenericSecurityPosition
ofNet(PositionInfo positionInfo, GenericSecurity security, double netQuantity)
Obtains an instance from position information, security and net quantity.PortfolioItemSummary
summarize()
Summarizes the portfolio item.GenericSecurityPosition.Builder
toBuilder()
Returns a builder that allows this bean to be mutated.String
toString()
GenericSecurityPosition
withInfo(PortfolioItemInfo info)
Returns an instance with the specified info.GenericSecurityPosition
withQuantity(double quantity)
Returns an instance with the specified quantity.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.opengamma.strata.product.PortfolioItem
getId
-
-
-
-
Method Detail
-
ofNet
public static GenericSecurityPosition ofNet(GenericSecurity security, double netQuantity)
Obtains an instance from the security and net quantity.The net quantity is the long quantity minus the short quantity, which may be negative. If the quantity is positive it is treated as a long quantity. Otherwise it is treated as a short quantity.
- Parameters:
security
- the underlying securitynetQuantity
- the net quantity of the underlying security- Returns:
- the position
-
ofNet
public static GenericSecurityPosition ofNet(PositionInfo positionInfo, GenericSecurity security, double netQuantity)
Obtains an instance from position information, security and net quantity.The net quantity is the long quantity minus the short quantity, which may be negative. If the quantity is positive it is treated as a long quantity. Otherwise it is treated as a short quantity.
- Parameters:
positionInfo
- the position informationsecurity
- the underlying securitynetQuantity
- the net quantity of the underlying security- Returns:
- the position
-
ofLongShort
public static GenericSecurityPosition ofLongShort(GenericSecurity security, double longQuantity, double shortQuantity)
Obtains an instance from the security, long quantity and short quantity.The long quantity and short quantity must be zero or positive, not negative. In many cases, only a long quantity or short quantity will be present with the other set to zero. However it is also possible for both to be non-zero, allowing long and short positions to be treated separately.
- Parameters:
security
- the underlying securitylongQuantity
- the long quantity of the underlying securityshortQuantity
- the short quantity of the underlying security- Returns:
- the position
-
ofLongShort
public static GenericSecurityPosition ofLongShort(PositionInfo positionInfo, GenericSecurity security, double longQuantity, double shortQuantity)
Obtains an instance from position information, security, long quantity and short quantity.The long quantity and short quantity must be zero or positive, not negative. In many cases, only a long quantity or short quantity will be present with the other set to zero. However it is also possible for both to be non-zero, allowing long and short positions to be treated separately.
- Parameters:
positionInfo
- the position informationsecurity
- the underlying securitylongQuantity
- the long quantity of the underlying securityshortQuantity
- the short quantity of the underlying security- Returns:
- the position
-
getSecurityId
public SecurityId getSecurityId()
Description copied from interface:Position
Gets the identifier of the underlying security.This identifier uniquely identifies the security within the system.
- Specified by:
getSecurityId
in interfacePosition
- Specified by:
getSecurityId
in interfaceSecuritizedProductPortfolioItem<GenericSecurity>
- Specified by:
getSecurityId
in interfaceSecuritizedProductPosition<GenericSecurity>
- Specified by:
getSecurityId
in interfaceSecurityQuantity
- Returns:
- the security identifier
-
getProduct
public GenericSecurity getProduct()
Description copied from interface:SecuritizedProductPortfolioItem
Gets the product of the security that was traded.- Specified by:
getProduct
in interfaceSecuritizedProductPortfolioItem<GenericSecurity>
- Returns:
- the product
-
getCurrency
public Currency getCurrency()
Description copied from interface:SecuritizedProductPortfolioItem
Gets the currency of the position.This is typically the same as the currency of the product.
- Specified by:
getCurrency
in interfaceSecuritizedProductPortfolioItem<GenericSecurity>
- Returns:
- the trading currency
-
getQuantity
public double getQuantity()
Description copied from interface:Position
Gets the net quantity of the security.This returns the net quantity of the underlying security. The result is positive if the net position is long and negative if the net position is short.
- Specified by:
getQuantity
in interfacePosition
- Specified by:
getQuantity
in interfaceSecurityQuantity
- Returns:
- the net quantity of the underlying security
-
withInfo
public GenericSecurityPosition withInfo(PortfolioItemInfo info)
Description copied from interface:SecuritizedProductPosition
Returns an instance with the specified info.- Specified by:
withInfo
in interfacePortfolioItem
- Specified by:
withInfo
in interfacePosition
- Specified by:
withInfo
in interfaceSecuritizedProductPosition<GenericSecurity>
- Parameters:
info
- the new info- Returns:
- the instance with the specified info
-
withQuantity
public GenericSecurityPosition withQuantity(double quantity)
Description copied from interface:SecuritizedProductPosition
Returns an instance with the specified quantity.- Specified by:
withQuantity
in interfacePosition
- Specified by:
withQuantity
in interfaceSecuritizedProductPortfolioItem<GenericSecurity>
- Specified by:
withQuantity
in interfaceSecuritizedProductPosition<GenericSecurity>
- Parameters:
quantity
- the new quantity- Returns:
- the instance with the specified quantity
-
summarize
public PortfolioItemSummary summarize()
Description copied from interface:PortfolioItem
Summarizes the portfolio item.This provides a summary, including a human readable description.
- Specified by:
summarize
in interfacePortfolioItem
- Specified by:
summarize
in interfacePosition
- Returns:
- the summary of the item
-
meta
public static GenericSecurityPosition.Meta meta()
The meta-bean forGenericSecurityPosition
.- Returns:
- the meta-bean, not null
-
builder
public static GenericSecurityPosition.Builder builder()
Returns a builder used to create an instance of the bean.- Returns:
- the builder, not null
-
metaBean
public GenericSecurityPosition.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getInfo
public PositionInfo getInfo()
Gets the additional position information, defaulted to an empty instance.This allows additional information to be attached to the position.
- Specified by:
getInfo
in interfacePortfolioItem
- Specified by:
getInfo
in interfacePosition
- Returns:
- the value of the property, not null
-
getSecurity
public GenericSecurity getSecurity()
Gets the underlying security.- Returns:
- the value of the property, not null
-
getLongQuantity
public double getLongQuantity()
Gets the long quantity of the security.This is the quantity of the underlying security that is held. The quantity cannot be negative, as that would imply short selling.
- Returns:
- the value of the property
-
getShortQuantity
public double getShortQuantity()
Gets the short quantity of the security.This is the quantity of the underlying security that has been short sold. The quantity cannot be negative, as that would imply the position is long.
- Returns:
- the value of the property
-
toBuilder
public GenericSecurityPosition.Builder toBuilder()
Returns a builder that allows this bean to be mutated.- Returns:
- the mutable builder, not null
-
-