OpenPit C++ SDK
C++17 SDK for the OpenPit pre-trade risk engine
openpit::param::PositionSize Class Referencefinal

Signed position quantity: positive is long and negative is short. More...

Inheritance diagram for openpit::param::PositionSize:
Collaboration diagram for openpit::param::PositionSize:

Public Member Functions

PositionSize CheckedAddQuantity (const Quantity &quantity, Side side) const
 Applies a directed quantity and throws openpit::Error on failure. More...
 
PositionSize CheckedNeg () const
 Negates the position size and throws openpit::Error on overflow. More...
 
std::pair< Quantity, std::optional< Side > > CloseQuantity () const
 Returns the absolute closing quantity and optional direction. More...
 
std::pair< Quantity, SideOpenQuantity () const
 Returns the absolute opening quantity and its direction. More...
 
- Public Member Functions inherited from openpit::param::detail::ExactValue< PositionSize, detail::PositionSizeTraits >
PositionSize CheckedAdd (const PositionSize &other) const
 Adds another value and throws openpit::Error on overflow. More...
 
PositionSize CheckedDivFloat (double divisor) const
 Divides by an imprecise boundary double. More...
 
PositionSize CheckedDivInt (std::int64_t divisor) const
 Divides by a signed integer and throws openpit::Error on failure. More...
 
PositionSize CheckedDivUint (std::uint64_t divisor) const
 Divides by an unsigned integer and throws openpit::Error on failure. More...
 
PositionSize CheckedMulFloat (double scalar) const
 Multiplies by an imprecise boundary double. More...
 
PositionSize CheckedMulInt (std::int64_t scalar) const
 Multiplies by a signed integer and throws openpit::Error on failure. More...
 
PositionSize CheckedMulUint (std::uint64_t scalar) const
 Multiplies by an unsigned integer and throws openpit::Error on failure. More...
 
PositionSize CheckedRemFloat (double divisor) const
 Computes the remainder for an imprecise boundary double divisor. More...
 
PositionSize CheckedRemInt (std::int64_t divisor) const
 Computes the remainder for a signed integer divisor. More...
 
PositionSize CheckedRemUint (std::uint64_t divisor) const
 Computes the remainder for an unsigned integer divisor. More...
 
PositionSize CheckedSubtract (const PositionSize &other) const
 Subtracts another value and throws openpit::Error on failure. More...
 
int Compare (const PositionSize &other) const
 Compares this value with another value of the same domain type. More...
 
::openpit::param::Decimal Decimal () const noexcept
 Returns the lossless decimal representation. More...
 
bool IsZero () const
 Returns whether the value is exactly zero. More...
 
bool operator!= (const PositionSize &other) const
 
bool operator< (const PositionSize &other) const
 
bool operator<= (const PositionSize &other) const
 
bool operator== (const PositionSize &other) const
 
bool operator> (const PositionSize &other) const
 
bool operator>= (const PositionSize &other) const
 
double ToDouble () const
 Converts to an imprecise boundary double. More...
 
std::string ToString () const
 Formats the exact value as a decimal string. More...
 

Static Public Member Functions

static PositionSize FromFee (const Fee &fee)
 Converts a fee contribution to its position-size effect. More...
 
static PositionSize FromPnl (const Pnl &pnl)
 Converts a PnL contribution to an equivalent position size. More...
 
static PositionSize FromQuantityAndSide (const Quantity &quantity, Side side)
 Creates a signed position size from quantity and direction. More...
 
- Static Public Member Functions inherited from openpit::param::detail::ExactValue< PositionSize, detail::PositionSizeTraits >
static PositionSize FromDecimal (Decimal value)
 Validates an exact decimal representation. More...
 
static PositionSize FromDecimalRounded (Decimal value, std::uint32_t scale, RoundingStrategy rounding)
 Rounds an exact decimal representation to scale digits. More...
 
static PositionSize FromDouble (double value)
 Creates a value from an imprecise boundary double. More...
 
static PositionSize FromDoubleRounded (double value, std::uint32_t scale, RoundingStrategy rounding)
 Converts and rounds an imprecise boundary double. More...
 
static PositionSize FromInt64 (std::int64_t value)
 Creates a value from a signed integer. More...
 
static PositionSize FromString (std::string_view value)
 Parses an exact decimal string. More...
 
static PositionSize FromStringRounded (std::string_view value, std::uint32_t scale, RoundingStrategy rounding)
 Parses and rounds an exact decimal string to scale digits. More...
 
static PositionSize FromUint64 (std::uint64_t value)
 Creates a value from an unsigned integer. More...
 

Detailed Description

Signed position quantity: positive is long and negative is short.

Member Function Documentation

◆ CheckedAddQuantity()

PositionSize openpit::param::PositionSize::CheckedAddQuantity ( const Quantity quantity,
Side  side 
) const
inline

Applies a directed quantity and throws openpit::Error on failure.

◆ CheckedNeg()

PositionSize openpit::param::PositionSize::CheckedNeg ( ) const
inline

Negates the position size and throws openpit::Error on overflow.

◆ CloseQuantity()

std::pair< Quantity, std::optional< Side > > openpit::param::PositionSize::CloseQuantity ( ) const
inline

Returns the absolute closing quantity and optional direction.

◆ FromFee()

PositionSize openpit::param::PositionSize::FromFee ( const Fee fee)
inlinestatic

Converts a fee contribution to its position-size effect.

◆ FromPnl()

PositionSize openpit::param::PositionSize::FromPnl ( const Pnl pnl)
inlinestatic

Converts a PnL contribution to an equivalent position size.

◆ FromQuantityAndSide()

PositionSize openpit::param::PositionSize::FromQuantityAndSide ( const Quantity quantity,
Side  side 
)
inlinestatic

Creates a signed position size from quantity and direction.

◆ OpenQuantity()

std::pair< Quantity, Side > openpit::param::PositionSize::OpenQuantity ( ) const
inline

Returns the absolute opening quantity and its direction.