quantpylib.standards.intervals
Repo standards for time period intervals.
Period
Bases: Enum
Enumeration representing different time periods for supported data granularity.
Attributes:
Name | Type | Description |
---|---|---|
SECOND |
Represents a second. Value |
|
MINUTE |
Represents a minute. Value |
|
HOURLY |
Represents an hour. Value |
|
DAILY |
Represents a day. Value |
|
WEEKLY |
Represents a week. Value |
|
MONTHLY |
Represents a month. Value |
|
YEARLY |
Represents a year. Value |
get_span(granularity, granularity_multiplier, period_start=None, period_end=None, periods=None)
Get the time span based on the specified granularity and parameters. granularity, granularity_multipler and periods determine the span duration, if provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
granularity
|
Period
|
The granularity of time period. |
required |
granularity_multiplier
|
int
|
The multiplier for the granularity. |
required |
period_start
|
datetime
|
The start of the time period. Defaults to None. |
None
|
period_end
|
datetime
|
The end of the time period. Defaults to None. |
None
|
periods
|
int
|
The number of periods. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the (start,end) of timespan. |
Raises:
Type | Description |
---|---|
InvalidPeriodConfig
|
If the period configuration is invalid. |
AssertionError
|
If the provided parameters are invalid. |
map_granularity_to_relativedelta(granularity, periods)
Map granularity and number of periods to dateutil.relativedelta.relativedelta
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
granularity
|
Period
|
The granularity of time period. |
required |
periods
|
int
|
The number of periods. |
required |
Returns:
Name | Type | Description |
---|---|---|
relativedelta |
Relative delta representing the time period. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the granularity is not a supported type. |