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 functionalityposition- Management of financial positions and their propertiestypes- Essential type definitions and enumsutils- Utility functions for model operations and calculationsformat- 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:
Positivefor non-negative numbersExpirationDatehandling- 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§
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::PayoffInfoand the implementation for everyOptionTypevariant. 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.
- Display
Money - A monetary amount as shown to a user:
$followed by the amount, or theunlimited_labelwhen the amount is an “unlimited” sentinel. - Margin
Info - 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 theis_positive::<T>()type check. Defined by the standalonepositivecrate and re-exported unchanged: a value obtained through this path is apositive::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§
- Basic
Axis Types - Represents the basic axis types used in financial option analysis and visualization.
- Expiration
Date - Represents the expiration of a financial instrument.
- Expiration
Date Error - Error types for expiration date operations.
- Option
Style - Re-export of core financial types from the standalone
financial_typescrate. - Option
Type - Represents the type of option in a financial context.
- Positive
Error Positive, the non-negative decimal newtype, its error and theis_positive::<T>()type check. Defined by the standalonepositivecrate and re-exported unchanged: a value obtained through this path is apositive::Positive(see the crate-level “Foundational types” table). Represents errors that can occur during positive decimal operations.- Rainbow
Type - Describes the type of rainbow option based on how multiple assets are combined.
- Side
- Re-export of core financial types from the standalone
financial_typescrate. - Trade
Status - Transaction Status
Constants§
- UNLIMITED
- The label shown in place of an amount that stands for “unlimited”.
Traits§
- Trade
Able - A trait that provides functionality for accessing and modifying trade-related data.
- Trade
Status Able - A trait representing the status management of a trade.
Functions§
- is_
positive Positive, the non-negative decimal newtype, its error and theis_positive::<T>()type check. Defined by the standalonepositivecrate and re-exported unchanged: a value obtained through this path is apositive::Positive(see the crate-level “Foundational types” table). Determines if the given type parameterTis thePositivetype.- 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
valueis one of the sentinels the library uses for it.