Skip to main content

Module model

Module model 

Source
Expand description

Domain types: options, positions, legs, trades, payoffs and checked Decimal helpers.

§Model Module

The core data structures of financial options modeling: option contracts, positions, legs, trades, payoffs at expiry and checked Decimal helpers. Pricing models, Greeks, probabilities and risk metrics are built on these types by the layers above; none of them lives here.

§Core Components

  • option - Implementation of the core Options structure and related functionality
  • position - Management of financial positions and their properties
  • types - Essential type definitions and enums
  • utils - Utility functions for model operations and calculations
  • format - Display and Debug implementations for model types

§Key Features

§Options

Comprehensive implementation of financial options including:

  • Multiple option types (European, American, Asian, etc.)
  • Contract validation, time to expiry and payoff at expiry
  • Intrinsic value and moneyness

§Position Management

Tools for managing financial positions:

  • Position tracking
  • Cost basis calculations
  • Profit/Loss analysis
  • Break-even calculations
  • Fee management

§Type System

Robust type definitions ensuring type safety:

  • Positive for non-negative numbers
  • ExpirationDate handling
  • Option styles and types
  • Side (Long/Short) definitions

§Formatting

Comprehensive formatting support:

  • Display trait implementations for readable output
  • Debug trait implementations for detailed inspection
  • Consistent formatting across all types
  • Custom format implementations for complex types

§Example Usage

use rust_decimal_macros::dec;
use tracing::info;
use optionstratlib_core::model::{ExpirationDate, Options};
use optionstratlib_core::model::types::{ OptionStyle, OptionType, Side};
use positive::pos_or_panic;
use positive::Positive;

let option = Options::new(
    OptionType::European,
    Side::Long,
    "AAPL".to_string(),
    Positive::HUNDRED,
    ExpirationDate::Days(pos_or_panic!(30.0)),
    pos_or_panic!(0.2),
    Positive::ONE,
    pos_or_panic!(105.0),
    dec!(0.05),
    OptionStyle::Call,
    pos_or_panic!(0.01),
    None,
);

info!("Option Details: {}", option);
info!("Debug View: {:?}", option);

Re-exports§

pub use option::Options;
pub use position::Position;

Modules§

decimal
Core utilities for handling decimal numbers in financial calculations.
leg
Components for different types of trading legs (spot, futures, perpetuals).
option
The option contract (Options): terms, validation, time to expiry and payoff.
payoff
Payoff contracts at expiry: payoff::Payoff, payoff::PayoffInfo and the implementation for every OptionType variant. Payoff contracts at expiry.
position
Trading positions (Position): an option with its premium, fees, quantity and open date.
types
Common type definitions used throughout the options strategy library.
utils
Utility functions supporting various operations across the library.

Structs§

Balance
Represents the balance of a specific option position in an exchange.
DisplayMoney
A monetary amount as shown to a user: $ followed by the amount, or the unlimited_label when the amount is an “unlimited” sentinel.
MarginInfo
Represents margin information for accounts that support leverage
Portfolio
Represents a portfolio containing multiple option balances.
Positive
Positive, the non-negative decimal newtype, its error and the is_positive::<T>() type check. Defined by the standalone positive crate and re-exported unchanged: a value obtained through this path is a positive::Positive (see the crate-level “Foundational types” table). A wrapper type that represents a guaranteed positive decimal value.
Trade
Represents a trade with detailed information such as action, side, option style, associated fees, and various metadata.

Enums§

BasicAxisTypes
Represents the basic axis types used in financial option analysis and visualization.
ExpirationDate
Represents the expiration of a financial instrument.
ExpirationDateError
Error types for expiration date operations.
OptionStyle
Re-export of core financial types from the standalone financial_types crate.
OptionType
Represents the type of option in a financial context.
PositiveError
Positive, the non-negative decimal newtype, its error and the is_positive::<T>() type check. Defined by the standalone positive crate and re-exported unchanged: a value obtained through this path is a positive::Positive (see the crate-level “Foundational types” table). Represents errors that can occur during positive decimal operations.
RainbowType
Describes the type of rainbow option based on how multiple assets are combined.
Side
Re-export of core financial types from the standalone financial_types crate.
TradeStatus
Transaction Status

Constants§

UNLIMITED
The label shown in place of an amount that stands for “unlimited”.

Traits§

TradeAble
A trait that provides functionality for accessing and modifying trade-related data.
TradeStatusAble
A trait representing the status management of a trade.

Functions§

is_positive
Positive, the non-negative decimal newtype, its error and the is_positive::<T>() type check. Defined by the standalone positive crate and re-exported unchanged: a value obtained through this path is a positive::Positive (see the crate-level “Foundational types” table). Determines if the given type parameter T is the Positive type.
reject_unrepresentable_expiration
Rejects a relative expiration that no calendar instant can represent.
resolve_expiration_date
Resolves an expiration into a calendar instant without aborting on overflow.
save_trades
Saves a list of trades to a file in JSON format.
unlimited_label
The label shown in place of an amount that stands for “unlimited”, if value is one of the sentinels the library uses for it.