Configuration#
Environment#
-
sigtech.framework.config.sig_settings.de_init()
Clear the cache and shut down the configured environment.
Example:
import sigtech.framework as sig sig.init() sig.de_init()
-
sigtech.framework.config.sig_settings.init(env: Optional[str] = None, env_date: Optional[Union[str, date, datetime]] = None, data_date: Optional[Union[str, date, datetime]] = None, load_env: bool = False, env_file: str = 'env', enable_intraday_memory_saving: bool = True, intraday_memory_saving_location: str = None, **env_overrides: Any) ConfiguredEnvironment
Initialise the environment and invoke pre- and post-init callbacks.
Environment overrides:
log_level
:'INFO'
,'DEBUG'
,'WARNING'
or'ERROR'
(default is'WARNING'
).repeat_mode
: Specify the behaviour in case the init() is called more than once.'reinit'
runs de_init() and then init() again,'error'
terminates the execution with an error,'warning'
continues the execution with a warning (default is'warning'
).log_stdout
: Configuration logging (default is True).init_traceback
: Initialisation traceback (default is False).SIP_ENV
env variable (if set).SIP_ENV_OVERRIDE_
env variables (if set) to override specific properties.
Example:
import datetime as dtm import sigtech.framework as sig # env_date se to 1st Jul 2020, 11am env = sig.init(log_level='ERROR', env_date=dtm.datetime(2020, 7, 1, 11, 0))
- Parameters:
env – Environment is use (set by default in production).
env_date – the today date used by framework, i.e. the date until which the backtest will run. Default is
'today'
.data_date – The market data as-of date, use to pin calculations to a particular version of the market data. Default is
'now'
.enable_intraday_memory_saving – Enable automatic purging of intraday data (default is True).
intraday_memory_saving_location – If provided, purged intraday data will be saved to this folder, and loaded back when required.
Configured environment#
-
class sigtech.framework.config.config.ConfiguredEnvironment(config: Mapping[str, bool], env_asof_datetime: datetime, data_asof_datetime: datetime, default_symbology: Symbology, get_adapter_func: Callable[[DataAdapterID, ConfiguredEnvironment], DataAdapter], env: Mapping[str, Any], enable_sentry: bool = False, is_strategy_job: bool = False, load_env: bool = False, env_file: str = 'env')
Base class implementing a configured environment.
-
property asofdate: date
Return the as-of date of the environment.
-
property asofdatetime: datetime
Return the as-of datetime of the environment.
-
property config
Return a copy of the configured environment.
-
property dag_cpus
Return the number of CPUs configured for remote processing.
-
property data_asof_datetime: datetime
Return the as-of date of the market data.
-
property data_service: DataService
Return the data service endpoint.
-
property default_symbology: Symbology
Return the symbol domain of the configured environment.
-
property display_tz
The timezone object to use by display methods, if not specified in the method input. This will return the | trading manager timezone unless a global TM_DISPLAY_TIMEZONE setting is provided in the environment config.
-
ENVIRONMENT = 'env'
String identifier of the environment.
-
property environment: str
Return the string identifier of the environment.
-
property external_analytics_bridge
Return the library used for external analytics.
-
property fx_cross: FXCross
Return an FXCross object handling FX currency conversions.
-
property identifier: IdentifierFactory
Return the identifier of the configured environment.
-
property is_dag_compute
Return True for multiprocess DAG compute, otherwise False for single process compute.
-
property is_remote_process
Return True if the environment has been set for remote processing.
-
property is_strategy_job
Return True if the environment is set up for a strategy job.
-
log = <FrameworkLogger sigtech.framework.config.config.ConfiguredEnvironment (WARNING)>
-
property object: sigtech.framework.internal.infra.objects.factory.ObjectFactory
Return the object reference of the configured environment.
-
property original_kwargs: dict[str, Any]
Returns the original kwargs used to initiate the environment
-
property quant_bridge: sigtech.framework.internal.quant_bridge.BaseQuantLibrary
Return the library used for analytics.
-
property sentry_manager
Sentry SDK instance for error tracking.
-
property strategy_service_initialised: bool
Returns True if strategy service has been initialised
-
property trade_price_store
Gets the trade price store which is a dict of (trade UTC datetime, instrument name, currency, quantity, transaction_type) to trade price
-
property xray_tolerance_mem_mb
Set the tolerance (in MB) used when logging memory usage, e.g. MDS adapter API calls, DAG remote process times.
-
property xray_tolerance_secs
Set the tolerance (in seconds) used when logging compute times, e.g. MDS adapter API calls, DAG remote process times.
-
change_env_date(new_dt: Union[date, datetime], live_data_updates=None, allow_move_backwards=False)
Update the environment date. Must be after the current environment date.
- Parameters:
new_dt – date or datetime. If no timezone applied, UTC is assumed.
live_data_updates – dict of dobject name to live data update.
allow_move_backwards – bool. Allow the environment date to be moved backwards. In this case the object cache will be cleared.
-
config_hash() int
Return the hash value of the configured environment.
-
dataframe_service() sigtech.framework.services.strategy.ObjectService deprecated
Return the object cache service object.
-
env_get(key: str) Any
Return an attribute value of the configured environment.
- Parameters:
key – Attribute key.
- Returns:
Attribute value.
-
get_adapter(adapter_id: DataAdapterID) DataAdapter
Return a data adapter available for the configured environment.
- Parameters:
adapter_id – Adapter identifier.
- Returns:
Data adapter.
-
go_live(strategies, outputs, output_callback, until_dt, period=datetime.timedelta(seconds=60), strategy_can_step=None, live_objects=None)
Start live strategy streaming mode.
- Parameters:
strategies – List of Strategy classes
outputs – Dictionary of OutputType -> frequency (1 meaning, every output, 2 every other output etc)
output_callback – Callback function with the signature output_callback(env_dt, output_dict):
until_dt – run until this datetime
period – strategy run frequency
strategy_can_step – a function which takes two arguments - a dictionary of object name to last market data point, and a dictionary of object name to timedelta representing the age of the last message
live_objects – optionally, supply a list of object names which will be subscribed to
- Returns:
-
static load_snapshot(file)
Load a snapshot of the environment and add stored objects to the environment.
- Parameters:
file – Input filename.
Example:
import sigtech.framework as sig env = sig.init() env.save_snapshot('example_snapshot.pickle')
-
object_service() sigtech.framework.services.strategy.ObjectService
Return the object cache service object.
-
save_config(file: str = 'env', warning: bool = True) None
Saves a snapshot of the environment variables in .json format for json serializable values and .pkl format for non-json serializable values
- Parameters:
file – Output filename
warning – Boolean flag to indicate that a warning string should be displayed.
Example:
import sigtech.framework as sig # Saves environment config as 'env.json' and 'env.pkl' env = sig.init() env.save_config('env') # Destroys the environment instance sig.de_init() # Loads environment config from 'env.json' and 'env.pkl' loaded_env = sig.init(load_env=True, env_file='env')
-
save_snapshot(file: str, warning: bool = True)
Store a pickle snapshot of the environment with the objects contained in the environment.
- Parameters:
file – Output filename.
warning – Boolean flag to indicate that a warning string should be displayed.
Example:
import sigtech.framework as sig env = sig.init(log_level='ERROR') env.save_snapshot('example_snapshot.pickle', warning=False)
-
set_dag_cpus(cpus: int = None)
Set the number of CPUs to be used by the scalability toolkit.
Note
This function must be run before
set_shared_memory()
is called in order to take effect.- Parameters:
cpus – Number of CPUs.
-
set_shared_memory(on: bool = True, force_remote_calc: bool = False, object_cache_capacity: int = None)
Enable or disable the scalability toolkit.
- Parameters:
on – Whether the scalability toolkit should be enabled or disabled.
force_remote_calc – If
True
, will allowsig.remote_calc
to work even without shared memory.object_cache_capacity – Capacity of local object cache (number of items) - set it to allow eviction with shared memory.
-
sig_master()
Return the SIG Master single stocks object.
Example:
import sigtech.framework as sig env = sig.init(log_level='ERROR') sm = env.sig_master()
-
strategy_service() StrategyServiceProxy
Return the strategy cache service object.
Settings#
Configuration module defining environment settings.
-
class sigtech.framework.config.settings.EnvironmentConfig
Subclasses:
MdsEnvironment
Class implementing environment settings.
-
default_symbology = None
Symbol domain of the configured environment.
-
log_level = 'WARNING'
Log level identifier.
-
playback_date = None
As-of date override.
-
classmethod create(env_date_val: Optional[Union[str, date, datetime]] = None, data_date_val: Optional[Union[str, date, datetime]] = None, enable_sentry: bool = False, load_env: bool = False, env_file: str = 'env', enable_intraday_memory_saving: bool = True, intraday_memory_saving_location: str = None, **env_overrides) ConfiguredEnvironment
Create a new configured environment.
- Parameters:
env_date_val – Environment as-of date (default is
'today'
).data_date_val – Market data as-of date (default is
'now'
).enable_sentry – Enable Sentry error tracking (default is False).
enable_intraday_memory_saving – Enable automatic purging of intraday data (default is True).
intraday_memory_saving_location – If provided, purged intraday data will be saved to this folder, and loaded back when required.
- Returns:
ConfiguredEnvironment
object.
-
classmethod default_config() Mapping[str, Any]
Return the default values of a configured environment.
-
classmethod get_attrs()
Return a dict containing the environment attributes.
-
classmethod init(env_date=None, data_date=None, log_stdout: bool = True, init_traceback: bool = False, enable_sentry: bool = False, repeat_mode: str = 'warning', **env_overrides) ConfiguredEnvironment
Initialise
config
variables (env_date
, etc.) and invoke pre- and post-init callbacks.Environment overrides:
log_level
:'INFO'
,'DEBUG'
,'WARNING'
or'ERROR'
(default is'WARNING'
).SIP_ENV
env variable (if set).SIP_ENV_OVERRIDE_
env variables (if set) to override specific properties.
- Parameters:
env_date – A python date, datetime or string like
'today'
or'yesterday'
. This date sets the calculation date of the calculation engine - no calculation can be made past this date, i.e. this date is used in place of ‘today’ in back-testing.data_date – A python date, datetime or string like
'now'
,'today'
or'yesterday'
. This date sets the as-of date of the data used. For example, ifenv_date
is set to 1st Jan 2010 anddata_date
is set to 1st Jan 2020, then calculations will end on 1st Jan 2010 and all the data used will be exactly the same as the data available in the data store on 1st Jan 2020, regardless of any corrections or additions made subsequently.log_stdout – Configuration logging (default is True).
init_traceback – Initialisation traceback (default is False).
enable_sentry – Enable Sentry for error tracking (default is False).
repeat_mode – Specify the behaviour in case the init() is called more than once.
'reinit'
runs de_init() and then init() again,'error'
terminates the execution with an error,'warning'
continues the execution with a warning (default is'warning'
).
-
classmethod init_logging(log_stdout: bool = True, log_level: Optional[str] = None, log_print: Optional[bool] = True)
Setup up global logging preferences. Calling this more than once in a process is not advised.
- Parameters:
log_stdout – Configuration logging (default is True).
log_level – Log level.
log_print – Print the new log status (default is True).
-
sigtech.framework.config.settings.asofdate() date
Return the as-of date of the environment.
-
sigtech.framework.config.settings.asofdatetime() datetime
Return the as-of datetime of the environment.
-
sigtech.framework.config.settings.configured_env() ConfiguredEnvironment
Return the configured environment.
-
sigtech.framework.config.settings.destroy_env()
Clear the cache and shut down the configured environment. Alternatively, use sig.de_init().
-
sigtech.framework.config.settings.details(strings_only=True, additional_info=None, tb=None, chain=True)
Return a sequence of details about the current configuration / environment. Details are pairs of (detail_name, detail_value).
- Parameters:
strings_only (bool) – If set to False, string values are not formatted (default is True).
additional_info (sequence) – Sequence of (key_str, value_or_func) tuples to be added to the returned string.
tb (traceback) – Traceback to pass to traceback.format_exc() if its default for that arg is to be overridden.
chain (bool) – If set to True, traceback string values are formatted (default is True).
-
sigtech.framework.config.settings.env_get(key)
Return an attribute value of the configured environment.
- Parameters:
key – Attribute key.
- Returns:
Attribute value.
-
sigtech.framework.config.settings.equity_index_options_discount_imply()
Return the default settings to imply the discount from vol surface.
-
sigtech.framework.config.settings.equity_index_options_discount_override_suffix()
Return the default suffix for curve option curves.
-
sigtech.framework.config.settings.equity_index_options_div_yield_stored()
Return the default settings to compute the dividend yields.
-
sigtech.framework.config.settings.equity_index_options_use_spot_from_surface()
Return the default settings for setting the spot data from the vol surface.
-
sigtech.framework.config.settings.fx_fwd_points()
Return the default values of FX forward tenors.
-
sigtech.framework.config.settings.get_environment() str
Return the string identifier of the environment.
-
sigtech.framework.config.settings.get_value(config: str) Any
Return an attribute value of the configured environment.
- Parameters:
config – Attribute key.
- Returns:
Attribute value.
-
sigtech.framework.config.settings.is_initialised() bool
Return True if the global configured environment was set successfully.
Example:
import sigtech.framework as sig if not sig.config.is_initialised(): sig.init()
-
sigtech.framework.config.settings.listed_index_options_greeks()
Return the available option greeks.
-
sigtech.framework.config.settings.listed_options_greeks()
Return the available option greeks.
-
sigtech.framework.config.settings.set_value(config: str, value: Any) None
Set an attribute of the configured environment.
- Parameters:
config – Attribute key.
value – Attribute value.
-
sigtech.framework.config.settings.t_cost_register()
Return the default values of transaction costs.
-
sigtech.framework.config.settings.upsert_configured_environment_singleton(**kwargs) ConfiguredEnvironment
Upsert the configured environment.
-
sigtech.framework.config.settings.usage_counter(prefix: str = None, bucket_name: str = 'usage')
Decorator to track methods/classes usage and send periodic updates to the event endpoint.
- Parameters:
prefix – Customised prefix string (optional).
bucket_name – Bucket used to collect data (optional).
-
sigtech.framework.config.settings.usage_counter_object(obj: any, bucket_name: str = 'usage')
Track object usage and send periodic updates to the event endpoint.
- Parameters:
obj – Object (or tuple object, function) to track or message to collect.
bucket_name – Bucket used to collect data (optional).