Rolling future strategy#

This page shows how to use the RollingFutureStrategy building block.

Learn more: Futures | Example notebooks

Environment#

Setting up your environment takes three steps:

  • Import the relevant internal and external libraries

  • Configure the environment parameters

  • Initialise the environment

import sigtech.framework as sig

import datetime as dtm
import pandas as pd
import uuid
import seaborn as sns

sns.set(rc = {'figure.figsize': (18, 6)})
sig.init();

Learn more: Setting up the environment

Creating RollingFutureStrategy objects#

The RollingFutureStrategy building block is used for most of SigTech’s futures-based strategies.

The class takes a number of rolling rules which direct how and when the strategy will roll into the next contract. The rolling rules provide the following information:

  • When to roll. Example: n days before expiry.

  • What contract to enter next.

  • Over how many days to roll.

The following example shows how to build a RollingFutureStrategy with S&P 500 E-mini futures:

rfs = sig.RollingFutureStrategy(
    currency='USD',
    contract_code='ES',
    contract_sector='INDEX',
    rolling_rule='front',
    front_offset='-6:-4',
    start_date=dtm.date(2010, 1, 4),
    ticker=f'Rolling Future Strat ES {str(uuid.uuid4())[:4]}',
)

You can then retrieve a pd.series for the strategy:

Input:

rfs.history().head()

Output:

2010-01-04    1000.000000
2010-01-05     999.928437
2010-01-06    1000.191043
2010-01-07    1004.181088
2010-01-08    1007.728179
Name: (LastPrice, EOD, ROLLING FUTURE STRAT ES CC0A STRATEGY), dtype: float64

You can also plot this time series.

rfs.history().plot();

Alternatively, you can generate a timeline of the strategy using .plot.portfolio_table():

rfs.plot.portfolio_table(
    'TOP_ORDER_PTS',
    end_dt = rfs.valuation_dt(rfs.start_date + dtm.timedelta(days=90))
)

Sizing RollingFutureStrategy#

You can size your RollingFutureStrategy with either initial_cash or fixed_contracts. The latter will maintain a fixed exposure throughout the life of the strategy. If unspecified, your strategy will default to 1000 currency units.

rfs_contracts = sig.RollingFutureStrategy(
    currency='USD',
    contract_code='ES',
    contract_sector='INDEX',
    rolling_rule='front',
    front_offset='-6:-4',
    start_date=dtm.date(2010, 1, 4),
    # set a number of futures contracts
    fixed_contracts=10
)

Rolling table#

You can construct a rolling table with the use of a contract table and roll method. The output will contain notional weights for relevant futures on their respective execution dates. The following example demonstrates a roll over two days, generating two rows for each roll:

rfs.rolling_table

The column entries range from December (Z) to November (X). For example when we have an entry U[0] in column M then we expect to hold the September futures contract in June. Similarly when we have an entry F[1] in column U, we expect to hold next year’s January contract in September.

from sigtech.framework.schedules.roll_schedules.tables import energy_table

energy_table

Roll schedule#

The RollingFutureStrategy class allows you to pass values through the rolling_rule parameter. You have several options for rolling rules, listed in the RollSchedule docstrings.

Learn more: RollSchedule

FX Hedged Rolling Futures#

The RollingFutureFXHedged class takes two more inputs than theRollingFutureStrategy. These inputs allow you to control the FX hedging agenda.

cash_rebalance_threshold#

This parameter allows you to set an FX cash exposure threshold. If exceeded, FX cash is converted into the base currency. For example, if the value is set to 0.02, the cash in the future currency is converted into the strategy currency if its absolute value exceeds 2% of the strategy model value.

exposure_rebalance_threshold#

This parameter allows you to set an FX exposure threshold for the underlying future. If breached, it will buy or sell the necessary amount of the underlying future to maintain the desired exposure.

rf_fx = sig.RollingFutureFXHedged(
    currency='USD',
    start_date=dtm.date(2018, 1, 4),
    contract_code='VG',
    contract_sector='INDEX',
    rolling_rule='front',
    front_offset='-3:-1',
    cash_rebalance_threshold=0.02,
    exposure_rebalance_threshold=0.02,
)

To tabulate the history of this strategy.

Input:

rf_fx.history().tail()

Output:

2021-04-21    1298.509831
2021-04-22    1310.833052
2021-04-23    1310.669080
2021-04-26    1313.695190
2021-04-27            NaN
Name: (LastPrice, EOD, USD VG INDEX LONG 672065DF RFFXH STRATEGY), dtype: float64

Strategy shortcuts#

Some rolling future strategies with pre-defined parameters can be instantiated by running a helper function:

Learn more: Default strategies

API documentation#

Learn more: RollingFutureStrategy | RollingFutureFXHedged