Skip to main content

TimeFrame

Enum TimeFrame 

Source
pub enum TimeFrame {
    Microsecond,
    Millisecond,
    Second,
    Minute,
    Hour,
    Day,
    Week,
    Month,
    Quarter,
    Year,
    Custom(Positive),
}
Expand description

Represents different timeframes for volatility calculations.

This enum provides a standardized way to represent various time periods used in financial calculations, including common periods like days, weeks, months, and years, as well as custom periods defined by the user.

The TimeFrame enum is used throughout the library to specify the timeframe for calculations like volatility, returns, and other time-dependent metrics.

§Examples

use optionstratlib_core::utils::time::TimeFrame;
use positive::pos_or_panic;

// Using standard timeframes
let daily = TimeFrame::Day;
let weekly = TimeFrame::Week;

// Using custom timeframes
let custom_period = TimeFrame::Custom(pos_or_panic!(360.0));

// Accessing the number of periods per year
let periods_per_year = daily.periods_per_year(); // Returns 252.0
let custom_periods = custom_period.periods_per_year(); // Returns 360.0

Variants§

§

Microsecond

1-microsecond data.

§

Millisecond

1-millisecond data.

§

Second

1-second data.

§

Minute

1-minute data.

§

Hour

1-hour data.

§

Day

Daily data.

§

Week

Weekly data.

§

Month

Monthly data.

§

Quarter

Quarterly data.

§

Year

Yearly data.

§

Custom(Positive)

Custom periods per year.

Implementations§

Source§

impl TimeFrame

Source

pub fn periods_per_year(&self) -> Positive

Returns the number of periods in a trading year for this timeframe.

This function calculates the number of periods that occur within a trading year based on the chosen TimeFrame. A trading year is assumed to have 252 days and 6.5 trading hours per day.

For custom timeframes, the number of periods is directly specified by the user.

§Examples
use optionstratlib_core::utils::time::TimeFrame;
use positive::pos_or_panic;

let daily = TimeFrame::Day;
let periods_per_year = daily.periods_per_year(); // Returns 252
assert_eq!(periods_per_year, pos_or_panic!(252.0));

let hourly = TimeFrame::Hour;
let periods_per_year = hourly.periods_per_year(); // Returns 1638
assert_eq!(periods_per_year, pos_or_panic!(1638.0));

let custom = TimeFrame::Custom(pos_or_panic!(360.0));
let periods_per_year = custom.periods_per_year(); // Returns 360
assert_eq!(periods_per_year, pos_or_panic!(360.0));

Trait Implementations§

Source§

impl Clone for TimeFrame

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 TimeFrame

Source§

impl Copy for TimeFrame

Source§

impl Debug for TimeFrame

Source§

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

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

impl<'de> Deserialize<'de> for TimeFrame

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 TimeFrame

Source§

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

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

impl PartialEq for TimeFrame

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 PartialOrd for TimeFrame

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for TimeFrame

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 TimeFrame

Source§

impl ToSchema for TimeFrame

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