nautilus_trader icon indicating copy to clipboard operation
nautilus_trader copied to clipboard

Support for continuous futures contracts

Open rterbush opened this issue 1 year ago • 5 comments

Feature Request

Thought I would create this as a feature request in issues. This is based from discussion https://github.com/nautechsystems/nautilus_trader/discussions/935

Below are some addidtional thoughts about creation of custom contracts and the ability to configure rolling schedules. Taken from some experience with Tradestation and its method of defining custom contracts.

Along with defining roll schedules, it would also be nice to be able to support the different methods of back adjustment mentioned in the above discussion.

# Tradestation Custom Future Symbols
# "What I do is plot a multidata chart with all the months and apply an indicator
# showing all their volumes. That will help you figure out when the volume roll
# usually happens. Format symbol - properties will give you the first notice and
# expiration dates. The indicator will also help you spot futures like gold where
# some months never trade with the highest volume. In that case you can explicitly
# tell the symbol which months to include, e.g. @GCQ18=103NC+GJMQZ."
#
# NC = "First Notice"
# XC = "Expiration"
#
# Recommended settings per market
# @AD=102XC
# @BO=110NC+FHKNZ
# @BP=102XC
# @CC=107NC+HKNUZ
# @CD=103XC
# @CL=105XC
# @CT=107NC+HKNZ
# @C=110NC+HKNZ
# @DX=102XC
# @EC=102XC
# @EMD=106XC
# @ES=106XC
# @FV=102NC
# @GC=103NC+GJMQZ
# @HG=103NC+HKNUZ
# @HO=110XC
# @JY=102XC
# @KC=106NC+HKNUZ
# @MP1=102XC
# @NE1=102XC
# @NG=105XC
# @NQ=106XC
# @PL=103NC+FJNV
# @RB=110XC
# @RTY=106XC
# @SB=110XC+HKNV
# @SF=102XC
# @SI=103NC+HKNUZ
# @SM=110NC+FHKNZ
# @S=110NC+FHKNX
# @TY=102NC
# @US=102NC
# @W=110NC+HKNUZ
# @YM=106XC
#
# TradeStation Custom Continuous Futures Symbology
# A custom continuous futures contract symbol is created by adding several parameter
# characters to a continuous contract root or individual symbol as follows:
#
# [Symbol root][ Month code][ Year code]=[Custom Continuous Parameters]
# [Symbol root]=[Custom Continuous Parameters]
#
# Custom Continuous Parameters (those following the equals sign)
# ================================================================================================
#
# Character 1 (contract on which to base the continuous data series)
#
# 1 = nearest contract (1st nearest)
# 2 = second nearest contract (2nd nearest)
# 3 = third nearest contract (3rd nearest)
#
# Characters 2-4
#
# For activity based rollovers:
# ------------------------------------------------------------------------------------------------
# Character 2 (consecutive occurrences of rollover event needed to trigger the actual rollover)
# A number from 1-9
#
# Characters 3-4 (activity based rollover event code)
# IN = Open Interest
# VO = Volume
# OR = Open Interest OR Volume
# AN = Open Interest AND Volume
# ------------------------------------------------------------------------------------------------
#
# For time based rollovers:
# ------------------------------------------------------------------------------------------------
# Characters 2-3 (number of days associated with the time based event used to trigger the actual rollover)
# A two digit number from 00-99
#
# Character 4 (time based rollover event code)
# X = Trading Days Prior to the Expiration Date
# D = Trading Days Prior to the Delivery Date
# N = Trading Days Prior to the First Notice Date
# E = Calendar Days Prior to the End of the Delivery Month
# B = Calendar Days into the Beginning Delivery Month
# ------------------------------------------------------------------------------------------------
#
# Character 5 (back adjustment calculation method)
# N = None
# C = Constant
# R = Ratio
#
# Character 6 (optional)  (number of prior months to offset a time based trigger)
# A number from 1-9 that offsets a time based trigger by an additional 1-9 months
# Additional characters (optional)  (expiration months to include or exclude in the continuous data series)
# Additional Char 1 (include or exclude one or more contract expiration months)
# -*- coding: utf-8; py-indent-offset:4 -*-
#
# +  = Include the expiration month characters that follow in the continuous contract
# -  = Exclude the expiration month characters that follow from the continuous contract
#
# Additional Chars 2-7 (expiration month codes to include/exclude)
#
# Example 1
# @SPM06=11INC represents a custom continuous contract based on the S&P 500 June 2006
# with a rollover to the 1st nearest contract (September 2006) based on 1st instance of
# higher open interest and using a constant back adjustment calculation.
#
# Example 2
# @ES=209XR represents a custom continuous contract based on the E-Mini with a rollover
# to the 2nd nearest contract (March 2007) occurring 9 days prior to expiration and using
# a ratio back adjustment calculation.
#
# Example 3
# @ESM07=105NC+MZ represents a custom continuous contract based on the E-Mini June 2007
# with a rollover to the 1st nearest contract (December 2007) occurring 5 days prior to
# expiration and using a constant back adjustment calculation. Note the December contract
# is the 1st nearest because only the June and December contracts are included in this
# continuous contract as specified by the +MZ suffix.

rterbush avatar May 13 '23 16:05 rterbush