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 Property is protected.

securities

securities: SecurityManager

The security manager

This Property is protected.

market_hours_database

market_hours_database: MarketHoursDatabase

The market hours database instance to use

This Property 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(
    symbol: Union[Symbol, str, BaseContract, Security],
    extended_market_hours: bool = False,
) -> IDateRule
every_day() -> IDateRule
every_day(
    symbol: str, extended_market_hours: bool = False
) -> IDateRule

Signature descriptions:

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

  • Specifies an event should fire every day

Parameters:

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

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 the specified symbol trades.]; Case 2: [A date rule that fires every day.]

month_end

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

Signature descriptions:

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

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

Parameters:

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

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

None
days_offset int

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

0
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 tradable date - offset for the specified security each month.]; Case 2: [A date rule that fires on the last of each month - offset.]

month_start

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

Signature descriptions:

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

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

Parameters:

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

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

None
days_offset int

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

0
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 tradable date + offset for the]; Case 2: [A date rule that fires on the first of each month + offset.]

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

()

quarter_end

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

Signature descriptions:

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

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

Parameters:

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

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

None
days_offset int

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

0
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 tradable date - offset for the specified security each quarter.]; Case 2: [A date rule that fires on the last of each quarter - offset.]

quarter_start

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

Signature descriptions:

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

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

Parameters:

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

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

None
days_offset int

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

0
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 tradable date + offset for the]; Case 2: [A date rule that fires on the first of each quarter + offset.]

week_end

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

Signature descriptions:

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

  • Specifies an event should fire on Friday - offset

Parameters:

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

The symbol whose exchange is used to determine the last

None
days_offset int

The amount of tradable days to offset the last tradable day by each week

0
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 the last - offset tradable date for the specified security each week.]; Case 2: [A date rule that fires on Friday each week.]

week_start

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

Signature descriptions:

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

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

Parameters:

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

The symbol whose exchange is used to determine the first

None
days_offset int

The amount of tradable days to offset the first tradable day by

0
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 the first + offset tradable date for the specified]; Case 2: [A date rule that fires on Monday + offset each week.]

year_end

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

Signature descriptions:

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

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

Parameters:

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

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

None
days_offset int

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

0
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 tradable date - offset for the specified security each year.]; Case 2: [A date rule that fires on the last of each year - offset.]

year_start

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

Signature descriptions:

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

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

Parameters:

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

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

None
days_offset int

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

0
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 tradable date + offset for the]; Case 2: [A date rule that fires on the first of each year + offset.]

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_market_open_close_exchange_hours

get_market_open_close_exchange_hours() -> (
    Sequence[SecurityExchangeHours]
)

Helper method to fetch the exchange hours of the securities currently in securities whose markets are not always open. If no such securities are present, falls back to US equities (SPY).

This Class is protected.

get_security_exchange_hours

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

Helper method to fetch the security exchange hours

This Class is protected.

get_symbol

get_symbol(ticker: str) -> Symbol

This Class is protected.