Search…
4. Multi-instrument futures strategy
Create a simple basket strategy that maintains specific weightings for different instruments.

A multi-instrument strategy in seven steps

In SigTech's Research environment, create a new notebook and run the following seven code blocks:

1. Set up environment

1
# Import necessary libraries
2
import sigtech.framework as sig
3
import datetime as dtm
4
5
# Initalise the environment
6
sig.init();
Copied!

2. Define instruments

1
# Create a list of object names (found in Data)
2
my_instruments = [
3
'C COMDTY FUTURES GROUP', # corn
4
'S COMDTY FUTURES GROUP', # soybeans
5
'SB COMDTY FUTURES GROUP' # sugar
6
]
7
8
# Convert the list of object names into a list of objects
9
my_instruments = [sig.obj.get(i) for i in my_instruments]
Copied!

3. Define historical period

As you'll need to use the start and end dates multiple times, store them as variables:
1
my_start = dtm.date(2019, 1, 1)
2
my_end = dtm.date(2020, 12, 31)
Copied!

4. Define a function for creating similar RollingFutureStrategy instances

Create multiple RollingFutureStrategy instances—one for each instrument listed above. Create them using this function:
1
def create_rfs(instrument):
2
rfs = sig.RollingFutureStrategy(
3
start_date=my_start,
4
end_date=my_end,
5
currency=instrument.currency,
6
contract_code=instrument.contract_code,
7
contract_sector=instrument.contract_sector,
8
rolling_rule='F_0'
9
)
10
# Returning the strategy object's name is needed for a future step
11
return rfs.name
Copied!

5. Build the RollingFutureStrategy instances inside a dictionary

Build the RollingFutureStrategy instances and store them inside a dictionary:
1
# Create an empty dictionary
2
basket = {}
3
4
# Populate the dictionary with the chosen instruments
5
6
# for each instrument in the dictionary
7
# the key is a simple description (the "asset")
8
# the value is the instrument object
9
for instrument in my_instruments:
10
basket[instrument.asset] = create_rfs(instrument)
11
12
# Let's see what it looks like
13
print(basket)
Copied!

6. Build the BasketStrategy

The BasketStrategy building block is a strategy of strategies—it is a container for managing multiple sub-strategies.
With the following code build a BasketStrategy to manage the three RollingFutureStrategy instances created above:
1
my_bs = sig.BasketStrategy(
2
3
# Add the RollingFutureStrategy objects into this basket strategy
4
constituent_names=basket.values(),
5
6
# Define the relative weights of the instruments
7
# These correspond to RollingFutureStrategy objects, so:
8
# Corn: 10%
9
# Soybeans: 20%
10
# Sugar: 70%
11
# The basket strategy will strive to maintain these weightings
12
weights=[0.1, 0.2, 0.7],
13
14
# Every three months, the basket strategy will rebalance in order to
15
# maintain the weightings defined above
16
rebalance_frequency='3M',
17
18
currency='USD',
19
start_date=my_start,
20
end_date=my_end
21
)
Copied!

7. Run the basket strategy and view its performance

1
my_bs.plot.performance()
Copied!

👷
Your turn: customise the strategy

Add more instruments and define each instrument's weighting in the strategy.