Skip to content

quantpylib.standards

Period

Bases: Enum

Enumeration representing different time periods for supported data granularity.

Attributes:

Name Type Description
SECOND

Represents a second. Value s.

MINUTE

Represents a minute. Value m.

HOURLY

Represents an hour. Value h.

DAILY

Represents a day. Value d.

WEEKLY

Represents a week. Value w.

MONTHLY

Represents a month. Value M.

YEARLY

Represents a year. Value y.

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.