Skip to main content

OptionSeries

Struct OptionSeries 

Source
pub struct OptionSeries {
    pub symbol: String,
    pub underlying_price: Positive,
    pub chains: BTreeMap<ExpirationDate, OptionChain>,
    pub risk_free_rate: Option<Decimal>,
    pub dividend_yield: Option<Positive>,
}
Expand description

Represents a series of option chains for an underlying asset, providing detailed information about its options market and related financial data.

Fields§

§symbol: String

The ticker symbol for the underlying asset (e.g., “AAPL”, “SPY”).

§underlying_price: Positive

The current market price of the underlying asset.

§chains: BTreeMap<ExpirationDate, OptionChain>

A sorted collection of option chains, each corresponding to a different expiration date.

§risk_free_rate: Option<Decimal>

The risk-free interest rate used for option pricing models.

§dividend_yield: Option<Positive>

The annual dividend yield of the underlying asset.

Implementations§

Source§

impl OptionSeries

Source

pub fn new(symbol: String, underlying_price: Positive) -> Self

Creates a new instance of the struct with the specified symbol and underlying price.

§Parameters
  • symbol: A String representing the symbol of the entity being created (e.g., a stock or asset).
  • underlying_price: A Positive value representing the current price of the underlying asset. This must be a positive value.
§Returns

A new instance of the struct initialized with:

  • The provided symbol and underlying_price.
  • An empty chains field of type BTreeMap.
  • None for both risk_free_rate and dividend_yield.
Source

pub fn odte(&self) -> Option<OptionChain>

Retrieves the nearest expiring option chain from the collection of option chains.

§Returns
  • Some(OptionChain) if there is an option chain with the closest expiration date that is within 1 day or less.
  • None if there are no option chains or if the nearest expiration date is more than 1 day away.
§Behavior

The function checks the first key-value pair in the chains collection. If the expiration date is within one day (ExpirationDate::Days(Positive::ONE)), it returns a cloned instance of the corresponding OptionChain. Otherwise, it returns None.

§Notes
  • The chains collection must be ordered by expiration date for this function to work correctly.
  • This method assumes that there is a defined threshold of “1 day” to determine closeness.
§Errors

This function does not return errors but may return None if no conditions are met.

Source

pub fn get_expiration_dates(&self) -> Result<Vec<Positive>, ChainError>

Retrieves the expiration dates associated with the chains.

This function iterates through the keys of the chains field, attempting to extract expiration dates by calling the get_days method on each key. The expiration dates are collected into a Vec<Positive> and returned. If any error occurs during this process, a boxed error is returned.

§Returns
  • Ok(Vec<Positive>) - A vector of expiration dates represented as Positive values if all operations succeed.
  • Err(Box<dyn Error>) - A boxed error if any step in retrieving or mapping the keys fails.
§Errors

This function will return an error if:

  • The get_days method on any key fails.
  • The process of mapping and collecting the keys fails.
Source

pub fn build_series( params: &OptionSeriesBuildParams, ) -> Result<Self, ChainError>

Builds an option series object (Self) based on the provided parameters.

This method takes in an OptionSeriesBuildParams object, clones its data, and constructs a series of option chains for each expiration date specified in the input parameters. Each option chain is built and associated with its corresponding expiration date, and the resulting data is stored in a BTreeMap for ordered access.

§Parameters
  • params: A reference to an OptionSeriesBuildParams object, which contains configuration details such as series to generate, price parameters, symbol, and chain parameters.
§Returns

A new instance of the object (Self) representing the constructed option series, which includes:

  • symbol: The symbol associated with the series.
  • underlying_price: The price of the underlying asset.
  • chains: A BTreeMap mapping expiration dates (ExpirationDate) to their corresponding option chains (OptionChain).
  • risk_free_rate: The risk-free interest rate, extracted from the input parameters, if specified.
  • dividend_yield: The dividend yield of the underlying asset, extracted from the input parameters, if specified.
§Process
  1. Clones the input parameters for local modifications.
  2. Iterates over each expiration date in the series field of the parameters.
  3. For each expiration date:
    • Converts it into an ExpirationDate type.
    • Updates the chain parameters by setting the expiration date and resetting the strike interval.
    • Builds an individual option chain using the updated chain parameters.
    • Updates the expiration date string within the chain.
    • Inserts the constructed chain into the BTreeMap with its associated expiration date.
  4. Constructs and returns the resulting instance of the option series with all computed data.
§Notes
  • This method assumes that valid expiration dates and series data are provided. Ensure proper validation of params before calling this method.
  • The use of a BTreeMap ensures that the resulting chains are sorted based on the expiration dates.
§Errors

Returns ChainError if:

  • Failed to build any option chain in the series
  • Failed to get date string from expiration date
  • Missing underlying price in price params
Source

pub fn to_build_params(&self) -> Result<OptionSeriesBuildParams, ChainError>

Converts the current object to OptionSeriesBuildParams.

This method performs the following steps:

  1. Attempts to retrieve the first key-value pair from self.chains.
  2. Fetches expiration dates by calling self.get_expiration_dates().
  3. Extracts chain parameters by calling to_build_params on the first option chain (if found).
  4. If no chains are available, returns an error indicating that no chains were found.
§Returns
  • On success, returns Ok(OptionSeriesBuildParams) which contains:
    • Chain parameters (chain_params) obtained from the first option chain.
    • Expiration dates (series).
  • On failure, returns an Err wrapped in a Box<dyn Error> with appropriate error details.
§Errors
  • Returns an error if there are no chains in self.chains.
  • Propagates any errors encountered by:
    • self.get_expiration_dates().
    • option_chain.to_build_params().
  • OptionSeriesBuildParams: The resulting struct after conversion.
  • to_build_params(): Method on individual option_chain objects to extract parameters.

Trait Implementations§

Source§

impl Clone for OptionSeries

Source§

fn clone(&self) -> OptionSeries

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 OptionSeries

Source§

impl Debug for OptionSeries

Source§

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

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

impl Default for OptionSeries

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for OptionSeries

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 OptionSeries

Source§

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

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

impl From<&OptionSeries> for Positive

Source§

fn from(value: &OptionSeries) -> Self

Converts to this type from the input type.
Source§

impl From<OptionSeries> for Positive

Source§

fn from(value: OptionSeries) -> Self

Converts to this type from the input type.
Source§

impl Len for OptionSeries

Source§

fn len(&self) -> usize

Returns the number of elements in the collection or the size of the object. Read more
Source§

fn is_empty(&self) -> bool

Returns true if the collection contains no elements or the object has zero size. Read more
Source§

impl Serialize for OptionSeries

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 ToSchema for OptionSeries

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<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<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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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