pub enum PositionSize {
Quantity(f64),
RiskAmount(f64),
RiskPercent {
account_size: f64,
percent: f64,
},
}Expand description
How a long or short position drawing sizes its quantity.
Variants§
Quantity(f64)
A fixed quantity, interpreted as lots by Self::quantity_with_sizing.
RiskAmount(f64)
The quantity that loses this amount if the stop is hit.
RiskPercent
The quantity that loses percent of account_size if the stop is hit.
Implementations§
Source§impl PositionSize
impl PositionSize
Sourcepub fn quantity_with_sizing(
&self,
entry: f64,
stop: f64,
sizing: &PositionSizing,
) -> Option<f64>
pub fn quantity_with_sizing( &self, entry: f64, stop: f64, sizing: &PositionSizing, ) -> Option<f64>
Size in lots using the instrument’s point value and lot size. Risk-based sizes and
fixed lot quantities round down to quantity_step, so rounding cannot increase risk.
Returns None if no positive permitted quantity fits, or inputs are invalid.
Sourcepub fn quantity(&self, entry: f64, stop: f64) -> Option<f64>
pub fn quantity(&self, entry: f64, stop: f64) -> Option<f64>
Unit quantity at entry with its stop at stop, without instrument conversion.
Use Self::quantity_with_sizing for lot sizing and quantity-step rounding.
None when a size from the risk has its stop at the entry, or a
setting is out of bounds (not positive and finite, or a percent above 100).
Trait Implementations§
Source§impl Clone for PositionSize
impl Clone for PositionSize
Source§fn clone(&self) -> PositionSize
fn clone(&self) -> PositionSize
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 PositionSize
Source§impl Debug for PositionSize
impl Debug for PositionSize
Source§impl Default for PositionSize
impl Default for PositionSize
Source§impl<'de> Deserialize<'de> for PositionSize
impl<'de> Deserialize<'de> for PositionSize
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 PartialEq for PositionSize
impl PartialEq for PositionSize
Source§impl Serialize for PositionSize
impl Serialize for PositionSize
impl StructuralPartialEq for PositionSize
Auto Trait Implementations§
impl Freeze for PositionSize
impl RefUnwindSafe for PositionSize
impl Send for PositionSize
impl Sync for PositionSize
impl Unpin for PositionSize
impl UnsafeUnpin for PositionSize
impl UnwindSafe for PositionSize
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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