TradingManager#
-
class sigtech.framework.schedules.trading_manager.TradingManager
A class implementing a trading manager. Calendar, timezone, open/close times information are used to provide a collection of trading functionalities.
Example of usage:
import datetime as dtm tm = sig.TradingManager.instance() xmas_date = dtm.datetime(2020, 12, 25) next_business_date = tm.current_next_trading_date(xmas_date)
-
property trading_holidays
Return the calendar identifier.
-
adjusted_delivery_dt(delivery_dt)
Return an adjusted delivery datetime after considering open and close time.
- Parameters:
delivery_dt – Input datetime.
- Returns:
datetime.
-
adjusted_notice_dt(notice_dt)
Return an adjusted notice datetime after considering open and close time.
- Parameters:
notice_dt – Input datetime.
- Returns:
datetime.
-
adjusted_trade_schedule(schedule)
Return an adjusted trade schedule using the schedule provided.
- Parameters:
schedule – Input schedule.
- Returns:
Schedule object.
-
check_trade_dt(dt: datetime, instrument: sigtech.framework.instruments.base.Instrument) bool
Check the execution time for an instrument sits in the open hours.
- Parameters:
dt – Proposed execution time.
instrument – Instrument object.
- Returns:
True
if the instrument is available to trade at the proposed time andFalse
otherwise.
-
close_datetime(d)
Return the close datetime using the date provided.
- Parameters:
d – Input date.
- Returns:
datetime.
-
close_time()
Return the close time.
-
current_next_trading_date(d)
Return the closest business day to [
d
, …, future), inclusive, i.e.d
if it is a business day, or the closest business day afterd
.- Parameters:
d – Input date.
- Returns:
date.
-
current_previous_trading_date(d)
Returns the closest business day to (past, …,
d
], inclusive, i.e.d
if it is a business day, or the closest business day befored
.- Parameters:
d – Input date.
- Returns:
date.
-
data_point_from_time(dt: ~datetime.datetime, data_points: list[sigtech.framework.infra.data_adapter.common.DataPoint], instrument=None, calendar=None) -> (<class 'sigtech.framework.infra.data_adapter.common.DataPoint'>, typing.Union[datetime.date, datetime.datetime])
Return the best data point available for this instrument to use to query a value at
dt
. It will use a daily time-series data point (e.g.:EOD
,LONDON_1600
) if there is an exact match.Failing that it will use an intra-day dataset.
Failing that it will use the closest available daily time-series.
If a daily data point is returned, then the other value returned is the date to use. If an intra-day data point is selected, then the other value returned will be the input datetime.
- Parameters:
dt – Input datetime.
data_points – List of data points available for this instrument.
instrument – Instrument object if available.
calendar – Calendar if available.
- Returns:
tuple(DataPoint, union(date, datetime))
.
-
data_point_from_time_daily(t: time, tz: timezone, data_points, instrument=None, calendar=None) list[sigtech.framework.infra.data_adapter.common.DataPoint]
Return the data points required for this instrument to use to query a value daily at time t (under timezone tz) It will use a daily time-series data point (e.g.:
EOD
,LONDON_1600
) if there is an exact match.Failing that it will use an intra-day dataset.
Failing that it will use the closest available daily time-series.
- Parameters:
t – Input time.
tz – Input timezone.
data_points – List of data points available for this instrument.
instrument – Instrument object if available.
calendar – Calendar if available.
- Returns:
list(DataPoint)
.
-
datetime_from_date_and_time(date: date, time: time, timezone=None, before: Optional[datetime] = None, after: Optional[datetime] = None, use_trading_manager_calendar: bool = True, calendar: str = 'None', instrument=None)
Return a datetime given date, time and timezone inputs. If
before
orafter
are supplied, then the resulting datetime will be bumped forward or back such that the constraint is satisfied.- Parameters:
date – Input date.
time – Input time.
timezone – Input timezone (
pytz.tzinfo
).before – Constrain on latest date accepted (optional).
after – Constrain on earliest date accepted (optional).
use_trading_manager_calendar – If True, the internal calendar is used (optional, default is True).
calendar – Calendar identifier (optional).
instrument – Instrument identifier (optional).
- Returns:
datetime.
-
get_data_point(default_data_point, data_points)
Return the available data points.
- Parameters:
default_data_point – Default data points returned if none of the internal ones are in
data_points
.data_points – List of data points checked against the internal list.
- Returns:
Data point identifier/s.
-
get_default_data_point(available_data_points)
Return the available default data points.
- Parameters:
available_data_points – List of data points checked against the internal list.
- Returns:
Data point identifier/s.
-
static instance()
Singleton instance of a trading manager.
-
is_trading_date(d)
Check if the provided date is a trading date.
- Parameters:
d – Input date.
- Returns:
bool.
-
next_trading_date(d)
Return the closest next business day from
d
.- Parameters:
d – Input date.
- Returns:
date.
-
open_datetime(d)
Return the open datetime using the date provided.
- Parameters:
d – Input date.
- Returns:
datetime.
-
open_time()
Return the open time.
-
previous_trading_date(d)
Return the closest previous business day from
d
.- Parameters:
d – Input date.
- Returns:
date.
-
static reset_instance()
Reset singleton instance of a trading manager.
-
static set_global_trade_manager(calendar='London,CHR CALENDAR', timezone='Europe/London', open=datetime.time(7, 30), close=datetime.time(18, 0))
Set the internal attributes of the trading manager.
- Parameters:
calendar – Calendar identifier.
timezone – Timezone identifier.
open – Open time.
close – Close time.
-
timezone()
Timezone identifier.
-
trade_execution_dt_from_date(instrument, d)
Find the closest execution datetime for a given instrument after or on the supplied date.
- Parameters:
instrument – Instrument object.
d – Reference date.
- Returns:
datetime.
-
trade_execution_dt_from_datetime(instrument, dt, always_use_intraday=False)
Find the closest execution datetime for a given instrument after the supplied datetime.
- Parameters:
instrument – Instrument object.
dt – Reference datetime.
always_use_intraday – Always consider intraday points, defaults to
False
.
- Returns:
datetime.
-
trade_schedule()
Return the trade schedule.
-
tzinfo()
datetime.tzinfo
implementation for the given timezone.