pub struct FuturePosition {
pub symbol: String,
pub quantity: Positive,
pub entry_price: Positive,
pub side: Side,
pub expiration_date: ExpirationDate,
pub contract_size: Positive,
pub initial_margin_req: Positive,
pub maintenance_margin_req: Positive,
pub date: DateTime<Utc>,
pub fees: Positive,
}Expand description
Represents a futures contract position.
Futures are standardized contracts traded on exchanges that obligate the buyer to purchase (or seller to sell) an asset at a predetermined price on a specific future date.
§Fields
symbol- Contract symbol (e.g., “ES”, “CL”, “BTC-QUARTERLY”)quantity- Number of contractsentry_price- Average entry priceside- Long or Short positionexpiration_date- Contract expiry datecontract_size- Multiplier (e.g., 50 for ES, 1000 for CL)initial_margin- Initial margin requirementmaintenance_margin- Maintenance margin leveldate- Position open timestampfees- Commission and exchange fees
Fields§
§symbol: StringContract symbol (e.g., “ES”, “CL”, “GC”).
quantity: PositiveNumber of contracts held.
entry_price: PositiveAverage entry price per contract.
side: SidePosition direction (Long or Short).
expiration_date: ExpirationDateContract expiration date.
contract_size: PositiveContract size multiplier (notional per point).
initial_margin_req: PositiveInitial margin requirement per contract.
maintenance_margin_req: PositiveMaintenance margin requirement per contract.
date: DateTime<Utc>Timestamp when the position was opened.
fees: PositiveTotal trading fees paid.
Implementations§
Source§impl FuturePosition
impl FuturePosition
Sourcepub fn new(
symbol: String,
quantity: Positive,
entry_price: Positive,
side: Side,
expiration_date: ExpirationDate,
contract_size: Positive,
initial_margin_req: Positive,
maintenance_margin_req: Positive,
date: DateTime<Utc>,
fees: Positive,
) -> Self
pub fn new( symbol: String, quantity: Positive, entry_price: Positive, side: Side, expiration_date: ExpirationDate, contract_size: Positive, initial_margin_req: Positive, maintenance_margin_req: Positive, date: DateTime<Utc>, fees: Positive, ) -> Self
Creates a new futures position.
§Arguments
symbol- Contract symbolquantity- Number of contractsentry_price- Average entry priceside- Long or Shortexpiration_date- Contract expirycontract_size- Contract multiplierinitial_margin_req- Initial margin per contractmaintenance_margin_req- Maintenance margin per contractdate- Position open timestampfees- Trading fees
Sourcepub fn long(
symbol: String,
quantity: Positive,
entry_price: Positive,
expiration_date: ExpirationDate,
contract_size: Positive,
margin: Positive,
) -> Self
pub fn long( symbol: String, quantity: Positive, entry_price: Positive, expiration_date: ExpirationDate, contract_size: Positive, margin: Positive, ) -> Self
Creates a long futures position with default settings.
§Arguments
symbol- Contract symbolquantity- Number of contractsentry_price- Entry priceexpiration_date- Contract expirycontract_size- Contract multipliermargin- Margin requirement
Sourcepub fn short(
symbol: String,
quantity: Positive,
entry_price: Positive,
expiration_date: ExpirationDate,
contract_size: Positive,
margin: Positive,
) -> Self
pub fn short( symbol: String, quantity: Positive, entry_price: Positive, expiration_date: ExpirationDate, contract_size: Positive, margin: Positive, ) -> Self
Creates a short futures position with default settings.
§Arguments
symbol- Contract symbolquantity- Number of contractsentry_price- Entry priceexpiration_date- Contract expirycontract_size- Contract multipliermargin- Margin requirement
Sourcepub fn notional_value_at_entry(&self) -> Result<Positive, PositionError>
pub fn notional_value_at_entry(&self) -> Result<Positive, PositionError>
Returns the notional value of the position at entry.
Notional = quantity × entry_price × contract_size
§Errors
Returns PositionError::PositiveError when the product leaves the
Positive range. The three factors are pub fields, so nothing
bounds it; Positive * Positive aborted on it (#788).
Sourcepub fn notional_value_at_price(
&self,
current_price: Positive,
) -> Result<Positive, PositionError>
pub fn notional_value_at_price( &self, current_price: Positive, ) -> Result<Positive, PositionError>
Returns the notional value at a given price.
§Arguments
current_price- Current market price
§Errors
Returns PositionError::PositiveError when the product leaves the
Positive range (#788).
Sourcepub fn unrealized_pnl(
&self,
current_price: Positive,
) -> Result<Decimal, PositionError>
pub fn unrealized_pnl( &self, current_price: Positive, ) -> Result<Decimal, PositionError>
Calculates the unrealized P&L at a given price.
§Arguments
current_price- Current market price
§Decision (issue #471): fallible because pnl_at_price is
This is the whole body of LegAble::pnl_at_price for a future, so
leaving it infallible would have moved that method’s abort one frame
down rather than removing it. entry_price, quantity and
contract_size are pub, so no constructor guard bounds the product.
§Errors
Returns PositionError::DecimalError when the price difference, the
quantity scaling or the contract-size scaling leaves the representable
Decimal range.
Sourcepub fn tick_value(&self, tick_size: Positive) -> Result<Positive, PositionError>
pub fn tick_value(&self, tick_size: Positive) -> Result<Positive, PositionError>
Calculates the tick value (value of one minimum price movement).
§Arguments
tick_size- Minimum price increment
§Errors
Returns PositionError::PositiveError when the product leaves the
Positive range (#788).
Sourcepub fn total_margin_required(&self) -> Result<Positive, PositionError>
pub fn total_margin_required(&self) -> Result<Positive, PositionError>
Returns the total margin required for this position.
§Errors
Returns PositionError::PositiveError when the product leaves the
Positive range (#788).
Sourcepub fn basis(&self, spot_price: Positive) -> Decimal
pub fn basis(&self, spot_price: Positive) -> Decimal
Calculates the basis (futures price - spot price).
§Arguments
spot_price- Current spot price of the underlying
Sourcepub fn implied_leverage(&self) -> Result<Decimal, PositionError>
pub fn implied_leverage(&self) -> Result<Decimal, PositionError>
Calculates the implied leverage of the position.
Leverage = Notional Value / Margin Required, and zero when no margin is required.
§Errors
Returns PositionError when the notional, the margin or their
ratio leaves the representable range (#788).
Trait Implementations§
Source§impl Clone for FuturePosition
impl Clone for FuturePosition
Source§impl ComposeSchema for FuturePosition
impl ComposeSchema for FuturePosition
Source§impl Debug for FuturePosition
impl Debug for FuturePosition
Source§impl Default for FuturePosition
impl Default for FuturePosition
Source§impl<'de> Deserialize<'de> for FuturePosition
impl<'de> Deserialize<'de> for FuturePosition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for FuturePosition
impl Display for FuturePosition
Source§impl Expirable for FuturePosition
impl Expirable for FuturePosition
Source§fn expiration_timestamp(&self) -> Result<i64, PositionError>
fn expiration_timestamp(&self) -> Result<i64, PositionError>
Source§fn days_to_expiration(&self) -> Result<Positive, PositionError>
fn days_to_expiration(&self) -> Result<Positive, PositionError>
Source§fn is_expired(&self) -> Result<bool, PositionError>
fn is_expired(&self) -> Result<bool, PositionError>
Source§fn time_to_expiration_years(&self) -> Result<Decimal, PositionError>
fn time_to_expiration_years(&self) -> Result<Decimal, PositionError>
Source§impl From<FuturePosition> for Leg
impl From<FuturePosition> for Leg
Source§fn from(position: FuturePosition) -> Self
fn from(position: FuturePosition) -> Self
Source§impl LegAble for FuturePosition
impl LegAble for FuturePosition
Source§fn get_symbol(&self) -> &str
fn get_symbol(&self) -> &str
Source§fn get_quantity(&self) -> Positive
fn get_quantity(&self) -> Positive
Source§fn pnl_at_price(&self, price: Positive) -> Result<Decimal, PositionError>
fn pnl_at_price(&self, price: Positive) -> Result<Decimal, PositionError>
Source§fn total_cost(&self) -> Result<Positive, PositionError>
fn total_cost(&self) -> Result<Positive, PositionError>
Source§fn fees(&self) -> Result<Positive, PositionError>
fn fees(&self) -> Result<Positive, PositionError>
Source§fn notional_value(&self, price: Positive) -> Result<Positive, PositionError>
fn notional_value(&self, price: Positive) -> Result<Positive, PositionError>
Source§impl Marginable for FuturePosition
impl Marginable for FuturePosition
Source§fn liquidation_price(
&self,
_current_price: Positive,
) -> Result<Option<Positive>, PositionError>
fn liquidation_price( &self, _current_price: Positive, ) -> Result<Option<Positive>, PositionError>
None for a long whose margin buffer per unit exceeds the entry
price: no non-negative price liquidates it. A short threshold below
zero is floored at zero, the documented domain floor of
Marginable::liquidation_price.
§Errors
Returns PositionError::DecimalError for a zero quantity or
contract size, where the buffer per unit is undefined (the division
aborted with Division by zero, #788), and when a margin, the buffer
or the shifted price leaves the representable range.