Comment on page
4. Multi-instrument futures strategy
Create a simple basket strategy that maintains specific weightings for different instruments.
In SigTech's Research environment, create a new notebook and run the following seven code blocks:
# Import necessary libraries
import sigtech.framework as sig
import datetime as dtm
# Initalise the environment
sig.init();
# Create a list of object names (found in Data)
my_instruments = [
'C COMDTY FUTURES GROUP', # corn
'S COMDTY FUTURES GROUP', # soybeans
'SB COMDTY FUTURES GROUP' # sugar
]
# Convert the list of object names into a list of objects
my_instruments = [sig.obj.get(i) for i in my_instruments]
As you'll need to use the start and end dates multiple times, store them as variables:
my_start = dtm.date(2019, 1, 4)
my_end = dtm.date(2020, 12, 31)
Create multiple
RollingFutureStrategy
instances—one for each instrument listed above. Create them using this function:def create_rfs(instrument):
rfs = sig.RollingFutureStrategy(
start_date=my_start,
end_date=my_end,
currency=instrument.currency,
contract_code=instrument.contract_code,
contract_sector=instrument.contract_sector,
rolling_rule='F_0'
)
# Returning the strategy object's name is needed for a future step
return rfs.name
Build the
RollingFutureStrategy
instances and store them inside a dictionary:# Create an empty dictionary
basket = {}
# Populate the dictionary with the chosen instruments
# for each instrument in the dictionary
# the key is the asset description
# the value is the instrument object
for instrument in my_instruments:
basket[instrument.asset_description] = create_rfs(instrument)
# Let's see what it looks like
print(basket)
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:my_bs = sig.BasketStrategy(
# Add the RollingFutureStrategy objects into this basket strategy
constituent_names=basket.values(),
# Define the relative weights of the instruments
# These correspond to RollingFutureStrategy objects, so:
# Corn: 10%
# Soybeans: 20%
# Sugar: 70%
# The basket strategy will strive to maintain these weightings
weights=[0.1, 0.2, 0.7],
# Every three months, the basket strategy will rebalance in order to
# maintain the weightings defined above
rebalance_frequency='3M',
currency='USD',
start_date=my_start,
end_date=my_end
)
my_bs.plot.performance()
Add more instruments and define each instrument's weighting in the strategy.
Last modified 10mo ago