pub enum ExitPolicy {
Show 14 variants
ProfitPercent(Decimal),
LossPercent(Decimal),
FixedPrice(Positive),
MinPrice(Positive),
MaxPrice(Positive),
TimeSteps(usize),
DaysToExpiration(Positive),
DeltaThreshold(Decimal),
UnderlyingPrice(Positive),
UnderlyingBelow(Positive),
UnderlyingAbove(Positive),
Expiration,
And(Vec<ExitPolicy>),
Or(Vec<ExitPolicy>),
}Expand description
Defines exit policies for option positions.
Exit policies determine when a position should be closed based on various market conditions, profit/loss levels, or time constraints.
Variants§
ProfitPercent(Decimal)
Exit when profit reaches a percentage of initial premium.
For short options: exit when premium decreases by this percentage. For long options: exit when premium increases by this percentage.
§Example
// Exit when profit reaches 50% of initial premium
ExitPolicy::ProfitPercent(dec!(0.5))LossPercent(Decimal)
Exit when loss reaches a percentage of initial premium.
For short options: exit when premium increases by this percentage. For long options: exit when premium decreases by this percentage.
§Example
// Exit when loss reaches 100% of initial premium (double)
ExitPolicy::LossPercent(dec!(1.0))FixedPrice(Positive)
Exit when the option premium reaches a specific price.
§Example
// Exit when premium reaches $50
ExitPolicy::FixedPrice(pos_or_panic!(50.0))MinPrice(Positive)
Exit when the option premium falls below a minimum price.
Useful for taking profits on short options when premium decays.
§Example
// Exit when premium falls below $5
ExitPolicy::MinPrice(pos_or_panic!(5.0))MaxPrice(Positive)
Exit when the option premium exceeds a maximum price.
Useful for cutting losses on short options when premium increases.
§Example
// Exit when premium exceeds $100
ExitPolicy::MaxPrice(Positive::HUNDRED)TimeSteps(usize)
Exit after a specific number of time steps.
§Example
// Exit after 1000 steps (e.g., 1000 minutes)
ExitPolicy::TimeSteps(1000)DaysToExpiration(Positive)
Exit when days to expiration falls below a threshold.
§Example
// Exit when less than 2 days remain
ExitPolicy::DaysToExpiration(Positive::TWO)DeltaThreshold(Decimal)
Exit when the option’s delta crosses a threshold.
§Example
// Exit when delta exceeds 0.5 (deep in the money)
ExitPolicy::DeltaThreshold(dec!(0.5))UnderlyingPrice(Positive)
Exit when the underlying price reaches a specific level.
§Example
// Exit when underlying reaches $4000
ExitPolicy::UnderlyingPrice(pos_or_panic!(4000.0))UnderlyingBelow(Positive)
Exit when the underlying price falls below a level.
§Example
// Exit when underlying falls below $3900
ExitPolicy::UnderlyingBelow(pos_or_panic!(3900.0))UnderlyingAbove(Positive)
Exit when the underlying price exceeds a level.
§Example
// Exit when underlying exceeds $4100
ExitPolicy::UnderlyingAbove(pos_or_panic!(4100.0))Expiration
And(Vec<ExitPolicy>)
Exit when ALL conditions are met (AND logic).
§Example
// Exit when profit is 50% AND at least 2 days have passed
ExitPolicy::And(vec![
ExitPolicy::ProfitPercent(dec!(0.5)),
ExitPolicy::TimeSteps(2880), // 2 days in minutes
])Or(Vec<ExitPolicy>)
Implementations§
Source§impl ExitPolicy
impl ExitPolicy
Sourcepub fn profit_target(percent: Decimal) -> Self
pub fn profit_target(percent: Decimal) -> Self
Sourcepub fn profit_or_loss(profit_percent: Decimal, loss_percent: Decimal) -> Self
pub fn profit_or_loss(profit_percent: Decimal, loss_percent: Decimal) -> Self
Sourcepub fn profit_or_time(profit_percent: Decimal, max_steps: usize) -> Self
pub fn profit_or_time(profit_percent: Decimal, max_steps: usize) -> Self
Sourcepub const fn is_composite(&self) -> bool
pub const fn is_composite(&self) -> bool
Checks if this is a composite policy (And/Or).
§Returns
true if the policy contains nested policies.
Sourcepub fn condition_count(&self) -> usize
pub fn condition_count(&self) -> usize
Returns the number of conditions in this policy.
For simple policies, returns 1. For composite policies, returns the total number of leaf conditions.
§Returns
The count of conditions.
Trait Implementations§
Source§impl Clone for ExitPolicy
impl Clone for ExitPolicy
Source§impl ComposeSchema for ExitPolicy
impl ComposeSchema for ExitPolicy
Source§impl Debug for ExitPolicy
impl Debug for ExitPolicy
Source§impl Default for ExitPolicy
impl Default for ExitPolicy
Source§impl<'de> Deserialize<'de> for ExitPolicy
impl<'de> Deserialize<'de> for ExitPolicy
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 ExitPolicy
impl Display for ExitPolicy
impl Eq for ExitPolicy
Source§impl Hash for ExitPolicy
impl Hash for ExitPolicy
Source§impl PartialEq for ExitPolicy
impl PartialEq for ExitPolicy
Source§impl Serialize for ExitPolicy
impl Serialize for ExitPolicy
impl StructuralPartialEq for ExitPolicy
Auto Trait Implementations§
impl Freeze for ExitPolicy
impl RefUnwindSafe for ExitPolicy
impl Send for ExitPolicy
impl Sync for ExitPolicy
impl Unpin for ExitPolicy
impl UnsafeUnpin for ExitPolicy
impl UnwindSafe for ExitPolicy
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,
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> PartialSchema for Twhere
T: ComposeSchema + ?Sized,
impl<T> PartialSchema for Twhere
T: ComposeSchema + ?Sized,
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.