Skip to content

DateRules

QuantConnect.Scheduling.DateRules

DateRules(
    algorithm: IAlgorithm,
    securities: SecurityManager,
    time_zone: Any,
    market_hours_database: MarketHoursDatabase,
)

Bases: BaseScheduleRules

Helper class used to provide better syntax when defining date rules

Initializes a new instance of the DateRules helper class

Parameters:

Name Type Description Default
algorithm IAlgorithm

The algorithm instance

required
securities SecurityManager

The security manager

required
time_zone Any

The algorithm's default time zone

required
market_hours_database MarketHoursDatabase

The market hours database instance to use

required

today

today: IDateRule

Specifies an event should only fire today in the algorithm's time zone using _securities.UtcTime instead of 'start' since ScheduleManager backs it up a day

tomorrow

tomorrow: IDateRule

Specifies an event should only fire tomorrow in the algorithm's time zone using _securities.UtcTime instead of 'start' since ScheduleManager backs it up a day

time_zone

time_zone: Any

The algorithm's default time zone

This codeEntityType is protected.

securities

securities: SecurityManager

The security manager

This codeEntityType is protected.

market_hours_database

market_hours_database: MarketHoursDatabase

The market hours database instance to use

This codeEntityType is protected.

every

every(day: DayOfWeek) -> IDateRule
every(
    *days: Union[DayOfWeek, Iterable[DayOfWeek]]
) -> IDateRule

Specifies an event should fire on each of the specified days of week

Parameters:

Name Type Description Default
day Optional[DayOfWeek]

The day the event should fire

None
days Union[DayOfWeek, Iterable[DayOfWeek]]

The days the event should fire

()

Returns:

Type Description
IDateRule

A date rule that fires on every specified day of week.

every_day

every_day() -> IDateRule
every_day(
    symbol: str, extended_market_hours: bool = False
) -> IDateRule
every_day(
    symbol: Union[Symbol, str, BaseContract],
    extended_market_hours: bool = False,
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire every day

  • Specifies an event should fire every day the symbol is trading

Parameters:

Name Type Description Default
symbol Optional[str | Union[Symbol, str, BaseContract]]

The symbol whose exchange is used to determine tradable dates

None
extended_market_hours Optional[bool]

True to include days with extended market hours only, like sunday for futures

False

Returns:

Type Description
IDateRule

Depends on the signature used. Case 1: [A date rule that fires every day.]; Case 2: [A date rule that fires every day the specified symbol trades.]

month_end

month_end(days_offset: int = 0) -> IDateRule
month_end(
    symbol: str,
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule
month_end(
    symbol: Union[Symbol, str, BaseContract],
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire on the last of each month

  • Specifies an event should fire on the last tradable date - offset for the specified symbol of each month

Parameters:

Name Type Description Default
days_offset int

The amount of days to offset the schedule by; must be between 0 and 30

0
symbol Optional[str | Union[Symbol, str, BaseContract]]

The symbol whose exchange is used to determine the last tradable date of the month

None
extended_market_hours Optional[bool]

True to include days with extended market hours only, like sunday for futures

True

Returns:

Type Description
IDateRule

Depends on the signature used. Case 1: [A date rule that fires on the last of each month - offset.]; Case 2: [A date rule that fires on the last tradable date - offset for the specified security each month.]

month_start

month_start(days_offset: int = 0) -> IDateRule
month_start(
    symbol: str,
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule
month_start(
    symbol: Union[Symbol, str, BaseContract],
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire on the first of each month + offset

  • Specifies an event should fire on the first tradable date + offset for the specified symbol of each month

Parameters:

Name Type Description Default
days_offset int

The amount of days to offset the schedule by; must be between 0 and 30.

0
symbol Optional[str | Union[Symbol, str, BaseContract]]

The symbol whose exchange is used to determine the first tradable date of the month

None
extended_market_hours Optional[bool]

True to include days with extended market hours only, like sunday for futures

True

Returns:

Type Description
IDateRule

Depends on the signature used. Case 1: [A date rule that fires on the first of each month + offset.]; Case 2: [A date rule that fires on the first tradable date + offset for the]

on

on(year: int, month: int, day: int) -> IDateRule
on(
    *dates: Union[datetime, Iterable[datetime]]
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire only on the specified day

  • Specifies an event should fire only on the specified days

Parameters:

Name Type Description Default
year Optional[int]

The year

None
month Optional[int]

The month

None
day Optional[int]

The day

None
dates Union[datetime, Iterable[datetime]]

The dates the event should fire

()

week_end

week_end(days_offset: int = 0) -> IDateRule
week_end(
    symbol: str,
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule
week_end(
    symbol: Union[Symbol, str, BaseContract],
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire on Friday - offset

  • Specifies an event should fire on the last - offset tradable date for the specified symbol of each week

Parameters:

Name Type Description Default
days_offset int

The amount of days to offset Friday by; must be between 0 and 6

0
symbol Optional[str | Union[Symbol, str, BaseContract]]

The symbol whose exchange is used to determine the last

None
extended_market_hours Optional[bool]

True to include extended market hours, false otherwise

True

Returns:

Type Description
IDateRule

Depends on the signature used. Case 1: [A date rule that fires on Friday each week.]; Case 2: [A date rule that fires on the last - offset tradable date for the specified security each week.]

week_start

week_start(days_offset: int = 0) -> IDateRule
week_start(
    symbol: str,
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule
week_start(
    symbol: Union[Symbol, str, BaseContract],
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire on Monday + offset each week

  • Specifies an event should fire on the first tradable date + offset for the specified symbol each week

Parameters:

Name Type Description Default
days_offset int

The amount of days to offset monday by; must be between 0 and 6

0
symbol Optional[str | Union[Symbol, str, BaseContract]]

The symbol whose exchange is used to determine the first

None
extended_market_hours Optional[bool]

True to include extended market hours, false otherwise

True

Returns:

Type Description
IDateRule

Depends on the signature used. Case 1: [A date rule that fires on Monday + offset each week.]; Case 2: [A date rule that fires on the first + offset tradable date for the specified]

year_end

year_end(days_offset: int = 0) -> IDateRule
year_end(
    symbol: str,
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule
year_end(
    symbol: Union[Symbol, str, BaseContract],
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire on the last of each year

  • Specifies an event should fire on the last tradable date - offset for the specified symbol of each year

Parameters:

Name Type Description Default
days_offset int

The amount of days to offset the schedule by; must be between 0 and 365

0
symbol Optional[str | Union[Symbol, str, BaseContract]]

The symbol whose exchange is used to determine the last tradable date of the year

None
extended_market_hours Optional[bool]

True to include days with extended market hours only, like sunday for futures

True

Returns:

Type Description
IDateRule

Depends on the signature used. Case 1: [A date rule that fires on the last of each year - offset.]; Case 2: [A date rule that fires on the last tradable date - offset for the specified security each year.]

year_start

year_start(days_offset: int = 0) -> IDateRule
year_start(
    symbol: str,
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule
year_start(
    symbol: Union[Symbol, str, BaseContract],
    days_offset: int = 0,
    extended_market_hours: bool = True,
) -> IDateRule

Signature descriptions:

  • Specifies an event should fire on the first of each year + offset

  • Specifies an event should fire on the first tradable date + offset for the specified symbol of each year

Parameters:

Name Type Description Default
days_offset int

The amount of days to offset the schedule by; must be between 0 and 365.

0
symbol Optional[str | Union[Symbol, str, BaseContract]]

The symbol whose exchange is used to determine the first tradable date of the year

None
extended_market_hours Optional[bool]

True to include days with extended market hours only, like sunday for futures

True

Returns:

Type Description
IDateRule

Depends on the signature used. Case 1: [A date rule that fires on the first of each year + offset.]; Case 2: [A date rule that fires on the first tradable date + offset for the]

set_default_time_zone

set_default_time_zone(time_zone: Any) -> None

Sets the default time zone

Parameters:

Name Type Description Default
time_zone Any

The time zone to use for helper methods that can't resolve a time zone

required

get_security_exchange_hours

get_security_exchange_hours(
    symbol: Union[Symbol, str, BaseContract],
) -> SecurityExchangeHours

Helper method to fetch the security exchange hours

This codeEntityType is protected.

get_symbol

get_symbol(ticker: str) -> Symbol

This codeEntityType is protected.