quantsupport 0.1.7

Rust quantitative finance library for derivatives pricing, yield-curve bootstrapping, AAD risk, Monte Carlo exposure, and XVA.
Documentation
use crate::{core::instrument::Instrument, time::date::Date};

/// A [`Side`] representing the direction of the cashflows.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Side {
    /// Paying or shorting a position.
    PayShort,
    /// Receive or being long a position.
    LongReceive,
}

impl Side {
    /// Returns the sign associated with the side: `LongReceive` (incoming cashflows) is positive,
    /// `PayShort` (outgoing cashflows) is negative.
    #[must_use]
    pub const fn sign(&self) -> f64 {
        match self {
            Self::PayShort => -1.0,
            Self::LongReceive => 1.0,
        }
    }
}

/// A [`Trade<I>`] represent a position taken on a particular instrument.
pub trait Trade<I: Instrument>: Send + Sync {
    /// Returns the associated instrument of the trade.
    fn instrument(&self) -> &I;

    /// Date of execution of the trade.
    fn trade_date(&self) -> Date;

    /// Side associated with the trade.
    fn side(&self) -> Side;
}