Custom Roll Table for Rolling Future Strategies
Contents
Custom Roll Table for Rolling Future Strategies#
New user? The best way to learn SigTech is to follow the steps in our user guide.
Unrestricted data: This notebook only uses data in our core offer to all users. Go ahead and run it.
Changes will not be saved: Edits made to SigTech’s example notebooks like this will only persist for the duration of your session. When you restart the research environment, this notebook will have been restored to its original state, and any changes you have made will have been lost. To make permanent changes, copy and paste the content to a new notebook in one of your workspaces.
Introduction#
The purpose of this notebook is to show how to create to create a RollingFutureStrategy
with a custom roll table. ## Environment This section will import relevant internal and external libraries, as well as setting up the platform environment.
[ ]:
import sigtech.framework as sig
import datetime as dtm
import pandas as pd
import seaborn as sns
from typing import Optional
sns.set(rc={'figure.figsize': (18, 6)})
env = sig.init(env_date=dtm.date(2024, 2, 22))
Universe#
[ ]:
rfs = sig.RollingFutureStrategy(
currency="USD",
contract_code="SP",
contract_sector="INDEX",
rolling_rule="front",
front_offset="-7,-4",
start_date=dtm.date(2010, 1, 4)
)
rfs.build()
rfs.rolling_table.head(10)
Explanation of columns:
Index: the date at which to execute the trade
rolled_in_contract
: the contract to buyrolled_out_contract
: the contract to sellrolled_in_weight
: the desired weight of therolled_in_contract
after the row has been processedrolled_out_weight
: the desired weight of therolled_out_contract
after the row has been processedfirst_execution_date
: the date of the first row in the particular roll
Strategy#
The RollingFutureStrategy
class has a build_rolling_table()
method that can be overridden to return a custom rolling table:
[ ]:
class CustomRollingTableRFS(sig.RollingFutureStrategy):
custom_roll_table: pd.DataFrame
def build_rolling_table(self):
return self.custom_roll_table
Thus we can pass in a custom table and use that:
[ ]:
my_roll_table = pd.DataFrame.from_dict({
dtm.date(2000, 1, 5): ["SPM00 INDEX", None, 1.0, 0.0, dtm.date(2000, 1, 5)],
dtm.date(2000, 3, 8): ["SPZ00 INDEX", "SPM00 INDEX", 0.356, 1-0.356, dtm.date(2000, 3, 8)],
dtm.date(2000, 3, 13): ["SPZ00 INDEX", "SPM00 INDEX", 1.0, 0.0, dtm.date(2000, 3, 8)],
},
orient="index",
columns=["rolled_in_contract", "rolled_out_contract", "rolled_in_weight", "rolled_out_weight", "first_execution_date"]
)
rfs_custom = CustomRollingTableRFS(
end_date=dtm.date(2000, 10, 1),
custom_roll_table=my_roll_table,
currency="USD",
# These are still needed but will not affect the strategy
contract_code="SP",
contract_sector="INDEX",
rolling_rule="front",
front_offset="-7,-4",
start_date=dtm.date(2000, 7, 3)
)
rfs_custom.build()
rfs_custom.rolling_table
Performance Analytics#
[ ]:
sig.PerformanceReport(rfs_custom.history()).report()