DynamicStrategy

DynamicStrategy#

class sigtech.framework.strategies.dynamic_strategy.DynamicStrategy

Baseclasses: DailyStrategy

Strategy trading a custom basket of instrument. Base strategy class for dynamic strategies.

Parameters are the same as in the base DailyStrategy.

Additional attributes:

  • trade_dictionary (dict): Dictionary of date, instrument basket pairs.

  • basket_creation_method (object): Method to call to determine instrument to trade.

  • basket_creation_kwargs (dict): Extra key word arguments for basket_creation_method. If the basket_creation_method has the parameters strike and maturity, these can be passed adding: { 'strike': 'SPOT', 'maturity': '2M' }

  • 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'

The instrument traded can be passed in as a dictionary to trade_dictionary. The keys determine the trade dates.

For example:

import datetime as dtm

fx_option_group = sig.obj.get('EURUSD OTC OPTION GROUP')

trade_dictionary = {dtm.date(2010, 4, 7): {
        fx_option_group.get_option('Call', 1.3, dtm.date(2010, 4, 6), dtm.date(2011, 4, 6)) : 1,
        fx_option_group.get_option('Put', 1.3, dtm.date(2010, 4, 6), dtm.date(2011, 4, 6)) : -1
    }
}

strat = sig.DynamicStrategy(
    currency=fx_option_group.over,
    start_date=dtm.date(2010, 1, 6),
    end_date=dtm.date(2012, 1, 20),
    trade_dictionary=trade_dictionary
)

strat.history()

Alternatively, a basket_creation_method function can be passed in which gets called on each roll dates and provides a dictionary or tuple of instruments to trade. The method should take the strategy, decision time and positions as input and provide a dictionary of instruments. Any additional parameters can be passed in as a dictionary to basket_creation_kwargs.

For example:

import datetime as dtm
import numpy as np
import pandas as pd

def basket_creation_method(strategy, dt, positions, **additional_parameters):
    signal = additional_parameters['signal']
    option_group = additional_parameters['option_group']
    strike = additional_parameters['strike']
    maturity = additional_parameters['maturity']
    size_date = dt.date()
    d = pd.Timestamp(dt.date())
    if d in signal.index:
        opt_type = 'Call' if signal.loc[d] >= 0 else 'Put'
        opt = option_group.get_option(start_date=size_date, option_type=opt_type,
                                      strike=strike, maturity=maturity)
        return {opt: 100}
    else:
        return {}

index = sig.obj.get("SPX INDEX")
spx_option_name = sig.obj.get('SPX INDEX OTC OPTION GROUP')

signal = np.sign(index.history().pct_change()).dropna().loc['2022-01-01':'2022-03-05']
signal = signal[signal.shift() !=  signal]

bc_params = {'signal': signal,
             'option_group': spx_option_name,
             'strike': 'SPOT',
             'maturity': '2M'}

strat = sig.DynamicStrategy(
    currency='USD',
    start_date=dtm.date(2022,1,1),
    end_date=dtm.date(2022, 3, 5),
    trade_frequency='1BD',
    basket_creation_method=basket_creation_method,
    basket_creation_kwargs=bc_params
)

strat.history()
basket_creation_kwargs: Optional[dict]
basket_creation_method: Optional[object]
extra_holidays: Optional[Union[list, str]]
property holidays

List of known holiday calendars.

trade_dictionary: Optional[dict]
trade_frequency: Optional[str]
create_schedule()

Create periodic schedule for strategy initialization

schedule_information()

Return the schedule information for this strategy.

set_positions(dt)

Set instrument positions. :param dt: Decision datetime.

strategy_initialization(dt)

Initial decision run on the start date of the strategy.

Parameters:

dt – Reference datetime.