Tutorial: commodity momentum strategy
Beginner tutorial on creating a systematic strategy using futures contracts.
This tutorial shows new SigTech users how to construct a systematic investment strategy where the strategy involves a number of different commodities, and where the investment decision is based on a simple momentum signal.
Learn more: Example notebooks
Workflow overview
When creating an investment strategy on the SigTech platform, the workflow tends to follow these steps:
Set up the environment
Define the investment universe
Create the strategy
Construct the portfolio
Generate the performance report
Environment
Setting up your environment takes three steps:
Import the relevant internal and external libraries
Configure the environment parameters
Initialise the environment
Learn more: Setting up the environment
Define the investment universe
In this step, you will define the futures contracts that will form the universe of the investment strategy. When defining the strategy's futures contracts it's important to use each contract's exact ContractCode
.
Example: the ContractCode
of corn futures is 'C '
Browse SigTech's Market Data to find futures contracts and their corresponding ContractCode
.
Note: all futures contracts issued by a particular futures exchange, such as CBOT for the same underlying asset, such as corn, will share the same ContractCode
.
Define the relevant start and end date for the strategy over which the historical performance will be simulated:
When the investment universe contains futures contracts, it's of high importance to handle the rolling of futures—since a given futures contract has an expiry date, it's crucial to systematically handle how the strategy trades in and out of futures contracts to maintain an exposure to the underlying asset. The SigTech platform offers the RollingFutureStrategy
class which allows the user to easily handle the rolling of contracts along a futures strip.
In this tutorial we will create eight RollingFutureStrategy
objects. The function below allows you to easily create these RollingFutureStrategy
objects by just passing in a few parameters.
The RollingFutureStrategy
objects are instantiated using a few different parameters, such as rolling_rule
and contract_sector
.
Learn more: Rolling Future Strategy
Note: the RollingFutureStrategy
objects assumes a constant long exposure from start_date
to end_date
.
Using a dictionary comprehension, all of the previously defined instruments will be passed into the function defined above, creating a RollingFutureStrategy
object for each of the instruments:
Create the strategy
The strategy consists of a simple momentum strategy, which in this case will mean that an asset is bought if it has had a positive price movement over a three month period, and be sold if it has had a negative price movement over a three month period.
The function below, generate_signals_momentum
, will not perform any buying or selling actions. Instead it will generate a pandas DataFrame with a buying or selling signal for each data point with a given timeframe, such as daily, for each RollingFutureStrategy
. The signals will be expressed as +1 or -1 depending on if it is a buying or selling signal.
In the code block below, all the instruments in the universe get passed in as a list to the function defined above, to convert the performance history of the RollingFutureStrategy
objects to a pandas DataFrame holding signals. The signals will be +1 or -1 on each date for each asset, which indicates a buying or selling signal in that given asset.
Construct the portfolio
To apply the strategy to the universe and combine all the assets into a portfolio, the SignalStrategy
class is used. But before we can use the SignalStrategy
class, we need to convert the pandas DataFrame of signals into a signal object:
Once the signal object is created, a SignalStrategy
object is created. There are many different parameters and alternatives that the user can make use of, such as different allocation functions between the assets in the strategy.
Learn more: Signal Strategy
Generate the performance report
After having created the strategy, the code block below can be used to create a performance report which contains information on:
Metrics
Rolling performance charts
Performance calendar
There are a wide range of different performance views and reports available.
Learn more: Performance Analytics
Another useful tool is to delve into the different strategy constituents' performance attribution to the overall strategy. The strategy is built up in a layered way, and each layer can be further investigated in terms of performance attribution.
The different layers can be viewed using the .pnl_breakdown
method, and by changing the parameter levels
.
The different levels can be view—levels=0
is the top level, and levels=1
is the next one.
Next steps
Learn more: Strategy building blocks | Instruments
Last updated