optionstratlib-core 0.22.0

Core domain model of OptionStratLib: options, positions, legs, trades, checked Decimal helpers and their errors. Re-exported by the optionstratlib facade on every feature set.
Documentation
/******************************************************************************
   Author: Joaquín Béjar García
   Email: jb@taunais.com
   Date: 1/8/24
******************************************************************************/

//! # 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
//!
//! ```rust
//! 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);
//! ```

/// Core utilities for handling decimal numbers in financial calculations.
pub mod decimal;

/// Formatting utilities for displaying financial data and calculations.
mod format;

/// The option contract (`Options`): terms, validation, time to expiry and payoff.
pub mod option;

/// Trading positions (`Position`): an option with its premium, fees, quantity and open date.
pub mod position;

/// Payoff contracts at expiry: [`payoff::Payoff`], [`payoff::PayoffInfo`] and the
/// implementation for every [`OptionType`] variant.
pub mod payoff;

mod positive_ext;

/// Common type definitions used throughout the options strategy library.
pub mod types;

/// Utility functions supporting various operations across the library.
pub mod utils;

/// Components for defining and working with chart axes in strategy visualizations.
mod axis;

mod balance;
/// Components for defining and working with expiration dates.
mod expiration;
/// Components for different types of trading legs (spot, futures, perpetuals).
pub mod leg;
mod trade;

pub use axis::BasicAxisTypes;
pub use balance::*;
pub use expiration::ExpirationDate;
pub use expiration::ExpirationDateError;
pub use expiration::{reject_unrepresentable_expiration, resolve_expiration_date};
pub use format::{DisplayMoney, UNLIMITED, unlimited_label};
pub use option::Options;
pub use position::Position;
pub use trade::{Trade, TradeAble, TradeStatus, TradeStatusAble, save_trades};
pub use types::{OptionStyle, OptionType, RainbowType, Side};

/// `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).
pub use positive::{Positive, PositiveError, is_positive};