Search…
3. Single-instrument futures strategy
Learn how to create, test and customise a simple strategy based on a single commodity future instrument.

A futures strategy in four code blocks

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

1. Set up environment

# Import necessary libraries
import sigtech.framework as sig
import datetime as dtm
# Initalise the environment
sig.init();

2. Define the strategy

# Define the instrument to use in this strategy
# The object name "KC COMDTY FUTURES GROUP" refers to coffee futures contract group.
# You can find other financial instruments in the SigTech platform's Data section.
my_instrument = sig.obj.get("KC COMDTY FUTURES GROUP")
# Create the strategy using the RollingFutureStrategy building block
my_rfs = sig.RollingFutureStrategy(
# Define the historical period to run the strategy in
# (this example runs from 1 Jan 2019 to 31 Dec 2021):
start_date=dtm.date(2019, 1, 1),
end_date=dtm.date(2021, 12, 31),
# Use the currency, contract code and contract sector corresponding
# to this instrument
currency=my_instrument.currency,
contract_code=my_instrument.contract_code,
contract_sector=my_instrument.contract_sector,
# Define the rolling rule for this strategy
# 'F-0' refers to a type of rolling rule
rolling_rule="F_0"
)

3. Run the strategy and view its performance

my_rfs.plot.performance()

👷
Your turn: customise the strategy

Make sure you understand SigTech basics by customising this strategy:

1. Choose a different instrument

The example above uses a coffee futures instrument. Browse SigTech's Data to find another futures instrument and try building a strategy with that instead.
The code in this page only works with futures data.
i. Find an instrument you're interested in:
Coffee Futures (KC)
ii. Click VIEW DETAILS to obtain the correct object name for referring to it in code:
"KC COMDTY FUTURES GROUP"

2. Use a different historical period

Try running the strategy over a different historical period by changing the start_date and end_date.

3. Append ? to view docstrings

Run the following code to view the docstring corresponding to the instrument you're using in this strategy:
my_instrument?
Run the following code to view the docstring corresponding to the RollingFutureStrategy building block:
sig.RollingFutureStrategy?
Tip: add .? to any object to get its docstring.. Docstrings are part of our API reference and are aimed at advanced users. Don't worry if much of it is unclear to you right now.