#[non_exhaustive]pub struct Trade {Show 18 fields
pub side: PositionSide,
pub entry_timestamp: i64,
pub exit_timestamp: i64,
pub entry_price: f64,
pub exit_price: f64,
pub quantity: f64,
pub entry_quantity: f64,
pub commission: f64,
pub transaction_tax: f64,
pub pnl: f64,
pub return_pct: f64,
pub dividend_income: f64,
pub unreinvested_dividends: f64,
pub entry_signal: Signal,
pub exit_signal: Signal,
pub tags: Vec<String>,
pub is_partial: bool,
pub scale_sequence: usize,
}Expand description
A completed trade (closed position)
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.side: PositionSideTrade direction
entry_timestamp: i64Entry timestamp
exit_timestamp: i64Exit timestamp
entry_price: f64Entry price
exit_price: f64Exit price
quantity: f64Number of shares/units at exit
entry_quantity: f64Number of shares/units at entry
commission: f64Total commission paid (entry + exit).
transaction_tax: f64Total transaction tax paid (entry + exit).
Non-zero only when BacktestConfig::transaction_tax_pct is set.
Deducted from P&L along with commission.
pnl: f64Realized P&L (after commission and transaction tax, including any unreinvested dividend income)
return_pct: f64Return as percentage
dividend_income: f64Dividend income received while this position was open
unreinvested_dividends: f64Dividend income that was NOT reinvested (i.e. remains as cash). Used internally for correct cash-accounting.
entry_signal: SignalSignal that triggered entry
exit_signal: SignalSignal that triggered exit
Tags inherited from the entry signal for subgroup analysis.
Populated automatically from Signal::tags when the position closes.
Query via BacktestResult::trades_by_tag and metrics_by_tag.
Placed last so that JSON field order is consistent with Signal::tags
(both appear after all other fields).
is_partial: booltrue when this trade represents a partial close of a position
(generated by Position::partial_close / a ScaleOut signal).
false for full position closes and for the final close of a scaled
position.
scale_sequence: usizeZero-based sequence number among the partial closes of this position.
For the first ScaleOut on a given position this is 0, the second is
1, etc. Always 0 for non-partial trades.
Implementations§
Source§impl Trade
impl Trade
Sourcepub fn is_profitable(&self) -> bool
pub fn is_profitable(&self) -> bool
Check if trade was profitable
Sourcepub fn duration_secs(&self) -> i64
pub fn duration_secs(&self) -> i64
Get trade duration in seconds
Sourcepub fn entry_value(&self) -> f64
pub fn entry_value(&self) -> f64
Get entry value (cost basis)
Sourcepub fn exit_value(&self) -> f64
pub fn exit_value(&self) -> f64
Get exit value
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Trade
impl<'de> Deserialize<'de> for Trade
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>,
Auto Trait Implementations§
impl Freeze for Trade
impl RefUnwindSafe for Trade
impl Send for Trade
impl Sync for Trade
impl Unpin for Trade
impl UnsafeUnpin for Trade
impl UnwindSafe for Trade
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more