algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::strategy::SizeSpec Class Reference

How much an OrderIntent trades: a quantity, a notional amount, or a target weight. More...

#include <algotradelib/src/strategy/intent.hpp>

Public Member Functions

 SizeSpec ()=default
 Constructs a quantity of zero (reconciling it reports QUANTITY_ROUNDS_TO_ZERO).
SizeKind kind () const noexcept
 Returns how the size is expressed.
const Decimal64 & as_quantity () const
 Returns the quantity.
const Money & as_notional () const
 Returns the notional amount.
const Decimal64 & as_target_weight () const
 Returns the target weight.

Static Public Member Functions

static SizeSpec quantity (Decimal64 amount)
 Makes a size in shares or contracts.
static SizeSpec notional (Money amount)
 Makes a size as an amount of money.
static SizeSpec target_weight (Decimal64 fraction)
 Makes a size as a fraction of portfolio value to hold.

Detailed Description

How much an OrderIntent trades: a quantity, a notional amount, or a target weight.

The runner converts a notional or a weight into a quantity, using a price and the portfolio. Read the value with the accessor that matches kind(); the others throw.

Definition at line 137 of file intent.hpp.

Constructor & Destructor Documentation

◆ SizeSpec()

algotradelib::strategy::SizeSpec::SizeSpec ( )
default

Constructs a quantity of zero (reconciling it reports QUANTITY_ROUNDS_TO_ZERO).

Referenced by notional(), quantity(), and target_weight().

Member Function Documentation

◆ as_notional()

const Money & algotradelib::strategy::SizeSpec::as_notional ( ) const
inline

Returns the notional amount.

Returns
The amount of money.
Exceptions
std::logic_errorunless kind() is NOTIONAL.

Definition at line 215 of file intent.hpp.

Referenced by algotradelib::strategy::reconcile().

◆ as_quantity()

const Decimal64 & algotradelib::strategy::SizeSpec::as_quantity ( ) const
inline

Returns the quantity.

Returns
The number of shares or contracts.
Exceptions
std::logic_errorunless kind() is QUANTITY.

Definition at line 205 of file intent.hpp.

Referenced by algotradelib::strategy::reconcile().

◆ as_target_weight()

const Decimal64 & algotradelib::strategy::SizeSpec::as_target_weight ( ) const
inline

Returns the target weight.

Returns
The fraction of portfolio value.
Exceptions
std::logic_errorunless kind() is TARGET_WEIGHT.

Definition at line 225 of file intent.hpp.

Referenced by algotradelib::strategy::reconcile(), and algotradelib::strategy::weight_target().

◆ kind()

SizeKind algotradelib::strategy::SizeSpec::kind ( ) const
inlinenoexcept

Returns how the size is expressed.

Returns
The kind, which selects the accessor to read.

Definition at line 198 of file intent.hpp.

Referenced by algotradelib::strategy::reconcile().

◆ notional()

SizeSpec algotradelib::strategy::SizeSpec::notional ( Money amount)
inlinestatic

Makes a size as an amount of money.

Parameters
amountThe amount; the runner divides it by a price to get a quantity.
Returns
The size.

Definition at line 159 of file intent.hpp.

◆ quantity()

SizeSpec algotradelib::strategy::SizeSpec::quantity ( Decimal64 amount)
inlinestatic

Makes a size in shares or contracts.

Parameters
amountThe quantity.
Returns
The size.

Definition at line 147 of file intent.hpp.

◆ target_weight()

SizeSpec algotradelib::strategy::SizeSpec::target_weight ( Decimal64 fraction)
inlinestatic

Makes a size as a fraction of portfolio value to hold.

A weight states a holding, not a trade: the runner compares it with what is held and working and trades only the difference, so restating the same weight places nothing. Like a target position, it may withdraw working orders on the instrument (see strategy::weight_target). The target is rounded down to whole lots, so a weight worth less than one share sells the holding to zero; set a TradeTolerance to avoid trading one share each time the price ticks.

Only a buy intent with DAY validity, no trigger and no idempotency key can carry a weight; anything else is refused with RejectReason::UNSUPPORTED_WEIGHT. A weight needs the portfolio value: a backtest supplies it, but a live runner refuses the intent (no_portfolio_value) unless you call Runner::set_portfolio_value.

It is still an order intent, not a TargetPosition: one withheld for the account is dropped, not retained for later; one refused for the market phase is kept, as any intent is.

Parameters
fractionThe fraction of portfolio value, as an exact decimal (for example 0.25); for a computed weight, convert with analytics::to_decimal.
Returns
The size.

Definition at line 187 of file intent.hpp.

Referenced by algotradelib::strategy::vanilla::EqualWeightRebalance::on_phase().


The documentation for this class was generated from the following file: