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: StringThe ticker symbol for the underlying asset (e.g., “AAPL”, “SPY”).
underlying_price: PositiveThe 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
impl OptionSeries
Sourcepub fn new(symbol: String, underlying_price: Positive) -> Self
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: AStringrepresenting the symbol of the entity being created (e.g., a stock or asset).underlying_price: APositivevalue 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
symbolandunderlying_price. - An empty
chainsfield of typeBTreeMap. Nonefor bothrisk_free_rateanddividend_yield.
Sourcepub fn odte(&self) -> Option<OptionChain>
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.Noneif 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
chainscollection 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.
Sourcepub fn get_expiration_dates(&self) -> Result<Vec<Positive>, ChainError>
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 asPositivevalues 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_daysmethod on any key fails. - The process of mapping and collecting the keys fails.
Sourcepub fn build_series(
params: &OptionSeriesBuildParams,
) -> Result<Self, ChainError>
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 anOptionSeriesBuildParamsobject, 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: ABTreeMapmapping 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
- Clones the input parameters for local modifications.
- Iterates over each expiration date in the
seriesfield of the parameters. - For each expiration date:
- Converts it into an
ExpirationDatetype. - 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
BTreeMapwith its associated expiration date.
- Converts it into an
- 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
paramsbefore calling this method. - The use of a
BTreeMapensures 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
Sourcepub fn to_build_params(&self) -> Result<OptionSeriesBuildParams, ChainError>
pub fn to_build_params(&self) -> Result<OptionSeriesBuildParams, ChainError>
Converts the current object to OptionSeriesBuildParams.
This method performs the following steps:
- Attempts to retrieve the first key-value pair from
self.chains. - Fetches expiration dates by calling
self.get_expiration_dates(). - Extracts chain parameters by calling
to_build_paramson the first option chain (if found). - 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).
- Chain parameters (
- On failure, returns an
Errwrapped in aBox<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().
§Related
OptionSeriesBuildParams: The resulting struct after conversion.to_build_params(): Method on individualoption_chainobjects to extract parameters.
Trait Implementations§
Source§impl Clone for OptionSeries
impl Clone for OptionSeries
Source§fn clone(&self) -> OptionSeries
fn clone(&self) -> OptionSeries
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ComposeSchema for OptionSeries
impl ComposeSchema for OptionSeries
Source§impl Debug for OptionSeries
impl Debug for OptionSeries
Source§impl Default for OptionSeries
impl Default for OptionSeries
Source§impl<'de> Deserialize<'de> for OptionSeries
impl<'de> Deserialize<'de> for OptionSeries
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 OptionSeries
impl Display for OptionSeries
Source§impl From<&OptionSeries> for Positive
impl From<&OptionSeries> for Positive
Source§fn from(value: &OptionSeries) -> Self
fn from(value: &OptionSeries) -> Self
Source§impl From<OptionSeries> for Positive
impl From<OptionSeries> for Positive
Source§fn from(value: OptionSeries) -> Self
fn from(value: OptionSeries) -> Self
Source§impl Len for OptionSeries
impl Len for OptionSeries
Source§impl Serialize for OptionSeries
impl Serialize for OptionSeries
Auto Trait Implementations§
impl Freeze for OptionSeries
impl RefUnwindSafe for OptionSeries
impl Send for OptionSeries
impl Sync for OptionSeries
impl Unpin for OptionSeries
impl UnsafeUnpin for OptionSeries
impl UnwindSafe for OptionSeries
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<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
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.