pub enum BalanceBasis {
Gross,
NetAsset,
}Expand description
Which figure of a Balance the asset statistics (drawdown, end-of-session balance) are
computed from.
The library deliberately does not hard-code one basis: gross is always safe, but net-asset
is only meaningful for margin accounts that stay solvent (see Self::NetAsset). Picking the
basis is therefore caller policy, selected once via
EngineStateBuilder::balance_basis
and defaulting to Self::Gross so existing/cash users see no change.
Variants§
Gross
Gross holdings (Balance::total) — always non-negative, the safe default.
NetAsset
Net asset value (Balance::net_asset, total - borrowed).
§Caller precondition — net must stay strictly positive
Drawdown is only well-defined while net asset stays strictly above zero. The underlying
DrawdownGenerator computes (peak - point) / peak, so under this basis:
- a zero peak (fully borrowed,
net == 0) makes the division returnNoneand the sample is silently dropped; - a negative peak (short held from session open) sign-flips the ratio, so a real loss yields a negative “drawdown” that never exceeds the running max and is silently never recorded.
Both failures are silent. A consumer selecting NetAsset is responsible for keeping net
asset strictly positive (or interpreting the drawdown metrics accordingly).
§Freshness
Balance::net_asset excludes accrued interest and reflects debt only as fresh as the last
BalanceSnapshot: WS partial
updates carry no debt, so between snapshots net_asset == total and the value steps at
snapshot boundaries.
Implementations§
Trait Implementations§
Source§impl Clone for BalanceBasis
impl Clone for BalanceBasis
Source§fn clone(&self) -> BalanceBasis
fn clone(&self) -> BalanceBasis
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for BalanceBasis
Source§impl Debug for BalanceBasis
impl Debug for BalanceBasis
Source§impl Default for BalanceBasis
impl Default for BalanceBasis
Source§fn default() -> BalanceBasis
fn default() -> BalanceBasis
Source§impl<'de> Deserialize<'de> for BalanceBasis
impl<'de> Deserialize<'de> for BalanceBasis
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>,
Source§impl Display for BalanceBasis
impl Display for BalanceBasis
impl Eq for BalanceBasis
Source§impl Hash for BalanceBasis
impl Hash for BalanceBasis
Source§impl Ord for BalanceBasis
impl Ord for BalanceBasis
Source§fn cmp(&self, other: &BalanceBasis) -> Ordering
fn cmp(&self, other: &BalanceBasis) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for BalanceBasis
impl PartialEq for BalanceBasis
Source§fn eq(&self, other: &BalanceBasis) -> bool
fn eq(&self, other: &BalanceBasis) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for BalanceBasis
impl PartialOrd for BalanceBasis
Source§impl Serialize for BalanceBasis
impl Serialize for BalanceBasis
impl StructuralPartialEq for BalanceBasis
Auto Trait Implementations§
impl Freeze for BalanceBasis
impl RefUnwindSafe for BalanceBasis
impl Send for BalanceBasis
impl Sync for BalanceBasis
impl Unpin for BalanceBasis
impl UnsafeUnpin for BalanceBasis
impl UnwindSafe for BalanceBasis
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.