SignalStrategy

SignalStrategy#

class sigtech.framework.signal.signal_strategy.SignalStrategy

Baseclasses: DailyStrategy

Subclasses: IntradaySignalStrategy, RatesSignalStrategy, EquityFactorBasket

A class implementing a strategy based on a signal object.

Keyword arguments:

  • signal_name: Signal object name.

  • signal_input: Can be a signal object or a dataframe.

  • allocation_function: Function mapping signal value to allocation weights.

  • allocation_kwargs: Extra parameters required for the allocation function.

  • instrument_mapping: Dictionary mapping from the column name of the signal DataFrame, to the instrument name we want to trade.

  • payment_currency: Cash currency that is used to execute trade.

  • threshold_function: Function to test if a rebalance should be triggered.

  • threshold_kwargs: Extra key word arguments for threshold_function.

  • rebalance_frequency: Set rebalance dates, e.g.: '1BD', '2BD', '1W', '2W', '1M', '2M', '1W-WED', '1W-FRI', '3M_IMM', 'SOM', 'EOM', 'YEARLY', '1DOM'.

  • rebalance_bdc: Set rebalance business day convention, e.g. 'PRECEDE', 'FOLLOWING', 'MOD_PRE', 'MOD_FOL', 'NONE_RULE'.

  • rebalance_offset_sticky_end: If True, applied month end rule in the offset bump.

  • rebalance_offset: Optional input to bump the final dates from the periodic schedule.

  • extra_rebalance_dates: Force extra rebalance on list of dates.

  • extra_holidays (list or str): Additional holiday calendars. You can pass either a list or a string: ['CMX(T) CALENDAR','SINGEX_JP(T) CALENDAR'] or 'CMX(T) CALENDAR,SINGEX_JP(T) CALENDAR'

  • nav_holidays: Additional holiday calendars to be applied to rebalance dates. (replaced by extra_holidays)

  • leverage: Amount of extra leverage to apply to the strategy.

  • use_first_entry_date: Bool to choose if the strategy trades on the first date (default is True).

  • use_signal_for_rebalance_dates: Bool to use signal dates for rebalancing (default is False).

  • t0_execution: Set to True if no lag is required between signals and execution (default is False).

  • execution_delay: If set (default is None), the execution datetime will be set to decision datetime plus execution_delay. Can be expressed in terms of dtm.timedelta or pd.Timestamp.

  • bump_execution_delay: When using the execution_delay, flag to trigger bumping of the delayed execution times, if they are executing when the market is closed. If False the trades are ignored (default is True).

  • unit_type: Units used for weights, defaults to 'WEIGHT'.

Example of object creation:

import numpy as np
import datetime as dtm
from sigtech.framework.default_strategy_objects.rolling_futures import es_index_front

signal_ts = np.sign(es_index_front().history().pct_change(fill_method=None))
signal_df = signal_ts.to_frame(es_index_front().name)

strategy = sig.SignalStrategy(
    currency='USD',
    signal_input=signal_df,
    start_date=dtm.date(2016, 1, 4),
    rebalance_frequency='1W-WED'
)

strategy.history()

Extra arguments rarely needed:

  • allocation_function_name: Function name for db persistence of allocation function.

  • threshold_function_name: Function name for db persistence of threshold function.

  • convert_long_short_weight: Set if the strategy applies long-short conversion (default is True).

  • use_db_for_short_version: Set if the long-short conversion looks in the DB (default is False).

  • excluded_diagnostics: Exclude serialised signal items in this list from being stored, e.g.: 'signal', 'allocations', 'weights', 'realised_weights'.

  • store_realized_weights: Realise weight saving (default is True).

  • trade_out_end: If true, closes all positions on last trading day of strategy.

allocation_function: Optional[Callable]
allocation_function_name: Optional[str]
allocation_kwargs: Optional[dict]
bump_execution_delay: Optional[bool]
convert_long_short_weight: Optional[bool]
excluded_diagnostics: Optional[list[str]]
execution_delay: Optional[Union[timedelta, Timedelta, str]]
extra_holidays: Optional[Union[list, str]]
extra_rebalance_dates: Optional[list[datetime.date]]
instrument_mapping: Optional[dict]
leverage: Optional[float]
nav_holidays: Optional[str]
payment_currency: Optional[str]
rebalance_bdc: Optional[str]
property rebalance_dates

Rebalancing dates.

rebalance_frequency: Optional[Union[dict[Union[datetime.datetime, datetime.date], str], str]]
rebalance_offset: Optional[str]
rebalance_offset_sticky_end: Optional[bool]
signal_input: Optional[Union[Signal, DataFrame]]
signal_name: Optional[str]
store_realized_weights: Optional[bool]
t0_execution: Optional[bool]
threshold_function: Optional[Callable]
threshold_function_name: Optional[str]
threshold_kwargs: Optional[dict]
trade_out_end: Optional[bool]
unit_type: Optional[str]
use_db_for_short_version: Optional[bool]
use_first_entry_date: Optional[bool]
use_signal_for_rebalance_dates: Optional[bool]
approx_return()

Compute the estimated return based on strategy allocations without actually building the strategy.

AVAILABLE_ALLOCATION_FUNCTIONS

alias of StandardAllocationFunctions

AVAILABLE_REBALANCE_FREQS

Baseclasses: ScheduleFrequencies

alias of ScheduleFrequenciesWithIntraday

AVAILABLE_THRESHOLD_FUNCTIONS

alias of StandardThresholdFunctions

rebalance(dt)

Rebalance portfolio to desired allocations.

Note

allocation_ts.asof provides the last available value.

Parameters:

dt – Reference datetime.

schedule_information()

Return the schedule information for this strategy.

signal_date_to_decision_dt(signal_date)

Given a signal date, return the decision datetime

strategy_initialization(dt)

Initial decision run on the start date of the strategy.

Parameters:

dt – Reference datetime.