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.0Variants§
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
impl TimeFrame
Sourcepub fn periods_per_year(&self) -> Positive
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));