StopStrategy#
-
class sigtech.framework.strategies.stop_strategy.StopStrategy
Baseclasses:
DailyStrategy
Subclasses:
StopLossStrategy
,TakeProfitStrategy
StopStrategy - wrapper for constituent instrument/strategy with a triggered close-out.
Keyword arguments:
instrument_name
: Name of instrument/strategy to trade.trigger_type
: Type of trigger to use, string options are listed below.valuation_lag
: Time window between decision time and valuation, defaults to1BD
.trigger_level
: Level used by the trigger.trigger_method
: Optional method to use as close out trigger, takes (dt, valuation, strategy, ).trigger_params
: Optional parameters to use in trigger method.trade_date
: Date to set initial value and determine start date.limit_period
: Time window to trigger close out once exceeded, defaults toNone
.initial_units
: Units of underlier to trade, defaults to1
.initial_cash
: Cash to include, defaults to0
.automatic_closeout
: Activate automatic closeout of the stop strategy if held by a strategy, defaults toTrue
.
The trigger types available are:
'FIXED_PCT_LOSS'
- Trigger close if percentage loss exceeds level from trade date.'FIXED_ABS_LOSS'
- Trigger close if absolute on one unit loss exceeds level from trade date.'TRAILING_PCT_LOSS'
- Trigger close if percentage loss exceeds level from high.'TRAILING_ABS_LOSS'
- Trigger close if absolute loss on one unit exceeds level from high.'FIXED_PCT_PROFIT'
- Trigger close if percentage profit exceeds level from trade date.'FIXED_ABS_PROFIT'
- Trigger close if absolute profit on one unit exceeds level from trade date.'TRAILING_PCT_PROFIT'
- Trigger close if percentage profit exceeds level from low.'TRAILING_ABS_PROFIT'
- Trigger close if absolute profit on one unit exceeds level from low.'FIXED_PCT_RANGE'
- Trigger close if percentage profit or loss exceeds level from trade date.'FIXED_ABS_RANGE'
- Trigger close if absolute profit or loss on one unit exceeds level from trade date.'TRAILING_PCT_RANGE'
- Trigger close if percentage profit or loss exceeds level from low.'TRAILING_ABS_RANGE'
- Trigger close if absolute profit or loss on one unit exceeds level from low.'CUSTOM_RANGE'
- Trigger close using custom range params.'METHOD'
- Trigger close using custom trigger method.
For RANGE trigger types, the following parameters are available through
trigger_params
:stop_loss
(float, optional): Specifies the stop-loss trigger level. If not provided, the default is thetrigger_level
.take_profit
(float, optional): Specifies the take-profit trigger level. If not provided, the default is thetrigger_level
.abs
(bool, optional): If set to True, the trigger uses absolute loss on one unit instead of percentage loss. Default is False. Only use for'CUSTOM_RANGE'
or'METHOD'
.abs_profit
(bool, optional): Can be used to apply absolute only to take profit.Default is
abs
. Only use for'CUSTOM_RANGE'
or'METHOD'
.
abs_loss
(bool, optional): Can be used to apply absolute only to stop loss.Default is
abs
. Only use for'CUSTOM_RANGE'
or'METHOD'
.
trailing
(bool, optional): If set to True, the trigger uses a trailing mechanism instead of a fixed one. Default is False. Only use for'CUSTOM_RANGE'
or'METHOD'
.trailing_profit
(bool, optional): Can be used to apply trailing only to take profit.Default is
trailing
. Only use for'CUSTOM_RANGE'
or'METHOD'
.
trailing_loss
(bool, optional): Can be used to apply trailing only to stop loss.Default is
trailing
. Only use for'CUSTOM_RANGE'
or'METHOD'
.
Example object creation:
import datetime as dtm future = env.object.get('ESZ19 INDEX') sl = sig.StopStrategy( currency='USD', trade_date=dtm.date(2019,9,1), instrument_name=future.name, trigger_type='FIXED_PCT_LOSS', trigger_level=0.01, )
Alternatively, a strategy wrapper can be generated to trade a specified object using the helper method:
sl = sig.StopStrategy.get_for_trade(future, dtm.date(2019,9,1))
-
TRIGGER_METHOD = {'CUSTOM_RANGE': <function range_trigger>, 'FIXED_ABS_LOSS': <function fixed_abs_loss_trigger>, 'FIXED_ABS_PROFIT': <function fixed_abs_profit_trigger>, 'FIXED_ABS_RANGE': <function fixed_abs_range_trigger>, 'FIXED_PCT_LOSS': <function fixed_pct_loss_trigger>, 'FIXED_PCT_PROFIT': <function fixed_pct_profit_trigger>, 'FIXED_PCT_RANGE': <function fixed_pct_range_trigger>, 'TRAILING_ABS_LOSS': <function trailing_abs_loss_trigger>, 'TRAILING_ABS_PROFIT': <function trailing_abs_profit_trigger>, 'TRAILING_ABS_RANGE': <function trailing_abs_range_trigger>, 'TRAILING_PCT_LOSS': <function trailing_pct_loss_trigger>, 'TRAILING_PCT_PROFIT': <function trailing_pct_profit_trigger>, 'TRAILING_PCT_RANGE': <function trailing_pct_range_trigger>}
-
automatic_closeout: Optional[bool]
-
currency: Optional[str]
-
initial_cash: Optional[float]
-
initial_units: Optional[float]
-
instrument: Optional[Instrument]
-
instrument_name: Optional[str]
-
limit_period: Optional[Union[datetime, date, str]]
-
trade_date: date
-
trigger_level: Optional[float]
-
trigger_method: Optional[Union[Callable, str]]
-
trigger_params: Optional[dict]
-
trigger_type: Optional[Literal['FIXED_PCT_LOSS', 'FIXED_ABS_LOSS', 'TRAILING_PCT_LOSS', 'TRAILING_ABS_LOSS', 'FIXED_PCT_PROFIT', 'FIXED_ABS_PROFIT', 'TRAILING_PCT_PROFIT', 'TRAILING_ABS_PROFIT', 'FIXED_PCT_RANGE', 'FIXED_ABS_RANGE', 'TRAILING_PCT_RANGE', 'TRAILING_ABS_RANGE', 'CUSTOM_RANGE', 'METHOD']]
-
valuation_lag: Optional[str]
-
close_out(dt)
Close out of underlying position.
- Parameters:
dt – Reference datetime.
-
classmethod get_for_trade(instrument: Instrument, trade_date: date, strategy: Optional[Strategy] = None, **kwargs)
Helper method to create a stop strategy.
- Parameters:
instrument – Instrument/Strategy object to trade.
trade_date – Date to trade and register initial value.
strategy – Strategy to trade within - used to match total return and cost settings.
kwargs – Additional StopStrategy parameters.
- Returns:
StopStrategy object.
-
history_end_date_eventual()
The last day strategy will have a value - apply underlying end date.
-
schedule_information()
Take schedule from underlying instrument.
-
strategy_initialization(dt)
Initial decision run on the start date of the strategy.
- Parameters:
dt – Reference datetime.