Class SecurityPosition
- java.lang.Object
-
- com.opengamma.strata.product.SecurityPosition
-
- All Implemented Interfaces:
CalculationTarget,ResolvableCalculationTarget,PortfolioItem,Position,ResolvableSecurityPosition,SecurityQuantity,Serializable,org.joda.beans.Bean,org.joda.beans.ImmutableBean
public final class SecurityPosition extends Object implements ResolvableSecurityPosition, org.joda.beans.ImmutableBean, Serializable
A position in a security, where the security is referenced by identifier.This represents a position in a security, defined by long and short quantity. The security is referenced using
SecurityId. The identifier may be looked up inReferenceData.The net quantity of the position is stored using two fields -
longQuantityandshortQuantity. 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 classSecurityPosition.BuilderThe bean-builder forSecurityPosition.static classSecurityPosition.MetaThe meta-bean forSecurityPosition.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SecurityPosition.Builderbuilder()Returns a builder used to create an instance of the bean.booleanequals(Object obj)PositionInfogetInfo()Gets the additional position information, defaulted to an empty instance.doublegetLongQuantity()Gets the long quantity of the security.doublegetQuantity()Gets the net quantity of the security.SecurityIdgetSecurityId()Gets the identifier of the underlying security.doublegetShortQuantity()Gets the quantity that was traded.inthashCode()static SecurityPosition.Metameta()The meta-bean forSecurityPosition.SecurityPosition.MetametaBean()static SecurityPositionofLongShort(PositionInfo positionInfo, SecurityId securityId, double longQuantity, double shortQuantity)Obtains an instance from position information, security identifier, long quantity and short quantity.static SecurityPositionofLongShort(SecurityId securityId, double longQuantity, double shortQuantity)Obtains an instance from the security identifier, long quantity and short quantity.static SecurityPositionofNet(PositionInfo positionInfo, SecurityId securityId, double netQuantity)Obtains an instance from position information, security identifier and net quantity.static SecurityPositionofNet(SecurityId securityId, double netQuantity)Obtains an instance from the security identifier and net quantity.SecuritizedProductPosition<?>resolveTarget(ReferenceData refData)Resolves the security identifier using the specified reference data.SecurityPosition.BuildertoBuilder()Returns a builder that allows this bean to be mutated.StringtoString()SecurityPositionwithInfo(PortfolioItemInfo info)Returns an instance with the specified info.SecurityPositionwithQuantity(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 SecurityPosition ofNet(SecurityId securityId, double netQuantity)
Obtains an instance from the security identifier 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:
securityId- the identifier of the underlying securitynetQuantity- the net quantity of the underlying security- Returns:
- the position
-
ofNet
public static SecurityPosition ofNet(PositionInfo positionInfo, SecurityId securityId, double netQuantity)
Obtains an instance from position information, security identifier 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 informationsecurityId- the identifier of the underlying securitynetQuantity- the net quantity of the underlying security- Returns:
- the position
-
ofLongShort
public static SecurityPosition ofLongShort(SecurityId securityId, double longQuantity, double shortQuantity)
Obtains an instance from the security identifier, 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:
securityId- the identifier of the underlying securitylongQuantity- the long quantity of the underlying securityshortQuantity- the short quantity of the underlying security- Returns:
- the position
-
ofLongShort
public static SecurityPosition ofLongShort(PositionInfo positionInfo, SecurityId securityId, double longQuantity, double shortQuantity)
Obtains an instance from position information, security identifier, 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 informationsecurityId- the identifier of the underlying securitylongQuantity- the long quantity of the underlying securityshortQuantity- the short quantity of the underlying security- Returns:
- the position
-
getQuantity
public double getQuantity()
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.
This is calculated by subtracting the short quantity from the long quantity.
- Specified by:
getQuantityin interfacePosition- Specified by:
getQuantityin interfaceSecurityQuantity- Returns:
- the net quantity of the underlying security
-
withInfo
public SecurityPosition withInfo(PortfolioItemInfo info)
Description copied from interface:ResolvableSecurityPositionReturns an instance with the specified info.- Specified by:
withInfoin interfacePortfolioItem- Specified by:
withInfoin interfacePosition- Specified by:
withInfoin interfaceResolvableSecurityPosition- Parameters:
info- the new info- Returns:
- the instance with the specified info
-
withQuantity
public SecurityPosition withQuantity(double quantity)
Description copied from interface:ResolvableSecurityPositionReturns an instance with the specified quantity.- Specified by:
withQuantityin interfacePosition- Specified by:
withQuantityin interfaceResolvableSecurityPosition- Parameters:
quantity- the new quantity- Returns:
- the instance with the specified quantity
-
resolveTarget
public SecuritizedProductPosition<?> resolveTarget(ReferenceData refData)
Description copied from interface:ResolvableSecurityPositionResolves the security identifier using the specified reference data.This takes the security identifier of this position, looks it up in reference data, and returns the equivalent position with full security information. If the security has underlying securities, they will also have been resolved in the result.
The resulting position is bound to data from reference data. If the data changes, the resulting position form will not be updated. Care must be taken when placing the resolved form in a cache or persistence layer.
- Specified by:
resolveTargetin interfaceResolvableCalculationTarget- Specified by:
resolveTargetin interfaceResolvableSecurityPosition- Parameters:
refData- the reference data to use when resolving- Returns:
- the resolved position
-
meta
public static SecurityPosition.Meta meta()
The meta-bean forSecurityPosition.- Returns:
- the meta-bean, not null
-
builder
public static SecurityPosition.Builder builder()
Returns a builder used to create an instance of the bean.- Returns:
- the builder, not null
-
metaBean
public SecurityPosition.Meta metaBean()
- Specified by:
metaBeanin 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:
getInfoin interfacePortfolioItem- Specified by:
getInfoin interfacePosition- Returns:
- the value of the property, not null
-
getSecurityId
public SecurityId getSecurityId()
Gets the identifier of the underlying security.This identifier uniquely identifies the security within the system.
- Specified by:
getSecurityIdin interfacePosition- Specified by:
getSecurityIdin interfaceSecurityQuantity- 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 quantity that was traded.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 SecurityPosition.Builder toBuilder()
Returns a builder that allows this bean to be mutated.- Returns:
- the mutable builder, not null
-
-