Skip to main content

ExitPolicy

Enum ExitPolicy 

Source
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

Exit at expiration (hold until expiration).

§Example

ⓘ
ExitPolicy::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>)

Exit when ANY condition is met (OR logic).

§Example

ⓘ
// Exit when profit is 50% OR loss is 100%
ExitPolicy::Or(vec![
    ExitPolicy::ProfitPercent(dec!(0.5)),
    ExitPolicy::LossPercent(dec!(1.0)),
])

Implementations§

Source§

impl ExitPolicy

Source

pub fn profit_target(percent: Decimal) -> Self

Creates a standard profit target exit policy.

§Arguments
  • percent - Profit percentage (e.g., 0.5 for 50%)
§Returns

An ExitPolicy::ProfitPercent variant.

Source

pub fn stop_loss(percent: Decimal) -> Self

Creates a standard stop loss exit policy.

§Arguments
  • percent - Loss percentage (e.g., 1.0 for 100%)
§Returns

An ExitPolicy::LossPercent variant.

Source

pub fn profit_or_loss(profit_percent: Decimal, loss_percent: Decimal) -> Self

Creates a combined profit target and stop loss policy.

§Arguments
  • profit_percent - Profit percentage threshold
  • loss_percent - Loss percentage threshold
§Returns

An ExitPolicy::Or variant combining both conditions.

Source

pub fn profit_or_time(profit_percent: Decimal, max_steps: usize) -> Self

Creates a time-limited profit target policy.

Exit when profit target is reached OR time limit is exceeded.

§Arguments
  • profit_percent - Profit percentage threshold
  • max_steps - Maximum number of time steps
§Returns

An ExitPolicy::Or variant combining both conditions.

Source

pub const fn is_composite(&self) -> bool

Checks if this is a composite policy (And/Or).

§Returns

true if the policy contains nested policies.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComposeSchema for ExitPolicy

Source§

impl Debug for ExitPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExitPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ExitPolicy

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ExitPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ExitPolicy

Source§

impl Hash for ExitPolicy

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ExitPolicy

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ExitPolicy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ExitPolicy

Source§

impl ToSchema for ExitPolicy

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PartialSchema for T
where T: ComposeSchema + ?Sized,

Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more