Search…
Calendars & timezones

Introduction

This page demonstrates how to configure the timezone and calendar features when initializing your environment. It also explains how to search and work with the schedule and calendar functions available within the framework.
This information would be valuable for any SigTech user wanting to build strategies which trade outside of the UTC timezone and trading calendar.

Environment

When initializing your environment with the sig.init() command, calendar and timezone settings will be configured by default.
1
import sigtech.framework as sig
2
import datetime as dtm
3
import pandas as pd
4
import numpy as np
5
6
sig.init()
Copied!

TradingManager

A TradingManager object is automatically created during environment initialization. These objects manage calendar, timezone and open/close time information for strategies. They also provide a collection of useful trading functionalities. Configuration parameters including the initials TM are referencing the TradingManager.

Relevant defaults

Parameter
Default
TM_CALENDAR
'None'
TM_TIMEZONE
'Europe/London'
TM_OPEN
datetime.time(7, 30, 0)
TM_CLOSE
datetime.time(18, 0, 0)
TM_DEFAULT_DATA_POINTS
[DataPoints.LONDON_1600, DataPoints.LAST]
TM_INTRADAY_OUT_OF_HOURS
False

Available options

Timezones

Available timezones are included in the standard python timezone library, pytz. To generate a list of the available options, you can run the following command:
1
import pytz
2
pytz.all_timezones
Copied!

Calendars

Available calendars are listed in the Calendars folder of our Data browser: available calendars. The object name can be retrieved from the VIEW DETAILS page, under CODE EXAMPLE.
The most commonly used calendars are:
1
'BANGKOK': 'BANGKOKB CALENDAR',
2
'BUDAPEST': 'BUDAPESTB CALENDAR',
3
'HONG KONG': 'HONGKONGB CALENDAR',
4
'ISTANBUL': 'ISTANB CALENDAR',
5
'JOHANNESBURG': 'JOHANNESBB CALENDAR',
6
'LONDON': 'LONDONB CALENDAR',
7
'MEXICO CITY': 'MEXICOB CALENDAR',
8
'MOSCOW': 'MOSCOWB CALENDAR',
9
'MUMBAI': 'MUMBAIB CALENDAR',
10
'NEW YORK': 'FEDFUND CALENDAR',
11
'OSLO': 'OSLOB CALENDAR',
12
'PARIS': 'PARISB CALENDAR',
13
'SEOUL': 'SEOULB CALENDAR',
14
'SINGAPORE': 'SINGAPOREB CALENDAR',
15
'STOCKHOLM': 'STOCKHOLMB CALENDAR',
16
'SYDNEY': 'SYDNEYB CALENDAR',
17
'TARGET': 'TARGET CALENDAR',
18
'EUR': 'TARGET CALENDAR',
19
'TOKYO': 'TOKYOB CALENDAR',
20
'TORONTO': 'TORONTOB CALENDAR',
21
'WARSAW': 'WARSAWB CALENDAR',
22
'WELLINGTON': 'WELLINGTB CALENDAR',
23
'USD': 'FEDFUND CALENDAR',
24
'ZURICH': 'ZURICHB CALENDAR'
Copied!
The Data Browser lists all available calendars, and provides sample code showing how to get them. For example, to get the A2X South Africa calendar:
1
calendar = sig.obj.get("A2XSE(T) CALENDAR")
2
3
# Description
4
print(calendar.description)
5
6
# List all holidays
7
print(calendar.holidays)
Copied!

FX market currency pairs

To identify relevant calendars for currency pairs, use FXMarket.instance() to retrieve specific schedules.
Input
Output
1
from sigtech.framework.infra.analytics.fx.fx_market import FXMarket
2
3
FXMarket.instance().schedule_stub('HKD', 'USD').holidays
Copied!
1
'HKD CALENDAR,WMCO CALENDAR'
Copied!

Exchange & OTC calendars

For futures based strategies, you can retrieve exchange calendars directly from the futures group with the following code.
Input
Output
1
start_date = dtm.date(2010, 1, 4)
2
3
strategy = sig.RollingFutureStrategy(
4
currency='USD',
5
start_date=start_date,
6
contract_code='GC',
7
contract_sector='COMDTY',
8
rolling_rule='front',
9
front_offset='-5:-4',
10
total_return=False,
11
include_trading_costs=False
12
)
13
strategy.contract_group.holidays
Copied!
1
'CMECOMF(T) CALENDAR'
Copied!
You can then retrieve their relevant holiday calendars.
Input
Output
1
sig.obj.get('COU21 COMDTY').group().holidays
Copied!
1
'ICE_EU_IPE(T) CALENDAR'
Copied!
For equities based strategies, you can retrieve exchange calendars with the following command.
1
holiday_calendar = sig.obj.get('1000045.SINGLE_STOCK.TRADABLE').exchange().holidays
Copied!
For business days, you will need to fetch the holiday_calendar object and then call business_days, specifying a start and end date.
1
business_days = sig.obj.get(holiday_calendar).business_days(
2
start=dtm.date(2020, 1, 1),
3
end=dtm.date(2022, 3, 15)
4
)
Copied!
OTC instruments contain a .holiday method which retrieves the relevant calendars without the need for calling sig.obj.get.
Input
Output
1
irs = sig.InterestRateSwap(currency='USD',
2
trade_date=dtm.date(2017, 4, 14),
3
start_date=dtm.date(2017, 5, 3),
4
tenor='5Y')
5
irs.history();
6
irs.holidays
Copied!
1
'FEDFUND, LONDONB CALENDAR'
Copied!

Changing the default values

You can reconfigure the calendar and timezone values during initialization. However, if you have already initialized your environment the sig.de_init() call will allow you to reset the values. The following code block will change the defaults.
1
# Destroy your environment
2
sig.de_init()
3
4
# Reconfigure your environment
5
env = sig.init()
6
sig.config.set('TM_TIMEZONE', 'Asia/Tokyo')
7
sig.config.set('TM_CALENDAR', 'HKD CALENDAR')
Copied!
This code block can be used if initializing your environment for the first time by simply removing the sig.de_init() command.
You can check these changes have been successful by running the following commands:
Input
Output
1
env[sig.config.TM_TIMEZONE]
Copied!
1
'Asia/Tokyo'
Copied!
Input
Output
1
env[sig.config.TM_CALENDAR]
Copied!
1
'HKD CALENDAR'
Copied!

Adjusting the date

You can add or adjust business day conventions, and retrieve month-end and IMM dates using sig.calendar.
Input
Output
1
# adding business days
2
sig.calendar.date_increment(
3
dtm.date(2021, 12, 1),
4
'1W',
5
calendar='HKD CALENDAR',
6
bdc='FOLLOWING'
7
)
Copied!
1
datetime.date(2021, 12, 8)
Copied!
Input
Output
1
# month-end
2
sig.calendar.get_month_end_dates(
3
start=dtm.date(2021, 9, 1),
4
end=dtm.date(2022, 1, 3),
5
calendar_names='WMCO CALENDAR'
6
)
Copied!
1
[datetime.date(2021, 9, 30),
2
datetime.date(2021, 10, 29),
3
datetime.date(2021, 11, 30),
4
datetime.date(2021, 12, 31)]
Copied!
Input
Output
1
# IMM dates
2
sig.calendar.imm_date(ref_date=dtm.date.today(), currency='USD')
Copied!
1
datetime.date(2022, 6, 15)
Copied!

Rebalancing frequencies

SigTech supports the majority of common rebalancing schedules.
Using a BasketStrategy as an example, the AVAILABLE_REBALANCE_FREQS object can help you to locate the correct string to supply for rebalancing.
Input
Output
1
freqs = sig.BasketStrategy.AVAILABLE_REBALANCE_FREQS
2
frequencies = [f for f in dir(freqs) if not f.startswith('_')]
3
frequency_strings = sorted([f for f in frequencies if f == f.upper()])
4
frequency_strings
Copied!
1
['END_OF_MONTH', 'IMM', 'START_OF_MONTH', 'YEARLY']
Copied!
You can use the values outputted above to determine the correct input string:
Input
Output
1
print(freqs.END_OF_MONTH)
2
print(freqs.IMM)
3
print(freqs.START_OF_MONTH)
4
print(freqs.YEARLY)
Copied!
1
EOM
2
3M_IMM
3
SOM
4
YEARLY
Copied!
Input
Output
1
frequency_methods = sorted([f for f in frequencies if f == f.lower()])
2
frequency_methods
Copied!
1
['business_days',
2
'day_of_month',
3
'fridays',
4
'mondays',
5
'months',
6
'thursdays',
7
'tuesdays',
8
'wednesdays',
9
'weeks']
Copied!
The values outputted above are methods that take an input and return the correct string format. You can use the thursdays method is an example:
Input
Output
1
freqs.thursdays?
Copied!
1
Signature: freqs.thursdays(n=1)
2
Docstring:
3
Rebalance every ``n`` weeks on Thursdays.
4
5
:param n: Number of weeks, 1 by default.
6
:return: Rebalance string value.
7
File: /opt/conda/envs/sig-env/lib/python3.7/site-packages/sigtech/framework/schedules/schedule.py
8
Type: method
Copied!
The input n determines how often, in terms of weeks, to rebalance. For instance, freqs.thursdays(2) returns the string to input to rebalance a strategy every second Thursday.
The following cell block runs some of these methods and outputs the strings necessary for the rebalancing_frequency.
Input
Output
1
print(freqs.business_days(2))
2
print(freqs.day_of_month(2))
3
print(freqs.fridays(2))
4
print(freqs.thursdays(2))
5
print(freqs.weeks(2))
Copied!
1
2BD
2
2DOM
3
2W-FRI
4
2W-THU
5
2W
Copied!

Custom schedules

SigTech includes a range of rebalancing schedules; EOD, 1W, 2W, 1M, SOM, EOD, 2BD, 2DOM, 2W-FRI, 2W-THU, 2W.
The rebalancing schedules listed above are not exhaustive. The Rebalancing frequencies section of this page provides the necessary code to list all of the available options.
If your desired rebalancing frequency is unavailable, a custom schedule can be created from the SchedulePeriodic class.
Python
Output
1
from sigtech.framework.schedules import SchedulePeriodic
2
3
end_date = dtm.date(2021, 5, 14)
4
frequency = '1W-Fri'
5
6
# Custom schedule for 3rd Friday Quarterly Rebalance
7
custom_schedule = SchedulePeriodic(
8
start_date=start_date,
9
end_date=end_date,
10
holidays='NYSE(T) CALENDAR',
11
frequency=frequency,
12
).all_data_dates()
13
14
custom_schedule = [x for x in custom_schedule
15
if x.month in [3, 6, 9, 12]] # Quarterly rebalancing
16
custom_schedule = [x for x in custom_schedule
17
if x.day >= 15 and x.day <= 21] # third Friday
18
custom_schedule[-5:]
Copied!
1
[datetime.date(2020, 3, 20),
2
datetime.date(2020, 6, 19),
3
datetime.date(2020, 9, 18),
4
datetime.date(2020, 12, 18),
5
datetime.date(2021, 3, 19)]
Copied!