Futures Contracts Expiry Date Handling
This page describes handling of futures expiry dates for contracts used in the algo strategy
When your algo is dealing with Futures, you need to specify the correct futures contract name as the symbol ticker to trade. This introduces challenges in backtesting, as the algo has to have the logic of changing the futures contract name per each month of backtesting.
Algorum allows you to specify the futures contract in a more generic way, based on the fact that at any point of time there are only three futures contracts trading on NSE. Current Month, Mid Month and Far Month. And since the futures are based on a underlying asset or index, Algorum allows you to specify a futures contract using the underlying asset/index ticker symbol, along with the number of the month of the contract that your strategy want to deal with. For instance below code snippet shows how to subscribe for NIFTY futures for various monthly contracts.
// Symbol object representing the current month NIFTY futures
var symbolCurrentMonth = new Symbol() {
SymbolType = SymbolType.FuturesIndex,
Ticker = "NIFTY",
FNOPeriodType = FNOPeriodType.Monthly,
FNOMonth = 0 // Current Month
};
// Symbol object representing the mid month NIFTY futures
var symbolMidMonth = new Symbol() {
SymbolType = SymbolType.FuturesIndex,
Ticker = "NIFTY",
FNOPeriodType = FNOPeriodType.Monthly,
FNOMonth = 1 // Mid Month
};
// Symbol object representing the far month NIFTY futures
var symbolFarMonth = new Symbol() {
SymbolType = SymbolType.FuturesIndex,
Ticker = "NIFTY",
FNOPeriodType = FNOPeriodType.Monthly,
FNOMonth = 2 // Far Month
};
# Symbol object representing the current month NIFTY futures
self.symbol_current_month = AlgorumQuantClient.algorum_types.TradeSymbol(
AlgorumQuantClient.algorum_types.SymbolType.FuturesIndex,
'NIFTY',
AlgorumQuantClient.algorum_types.FNOPeriodType.Monthly,
0,
0,
AlgorumQuantClient.algorum_types.OptionType.Unspecified,
0,
0)
# Symbol object representing the mid month NIFTY futures
self.symbol_mid_month = AlgorumQuantClient.algorum_types.TradeSymbol(
AlgorumQuantClient.algorum_types.SymbolType.FuturesIndex,
'NIFTY',
AlgorumQuantClient.algorum_types.FNOPeriodType.Monthly,
1,
0,
AlgorumQuantClient.algorum_types.OptionType.Unspecified,
0,
0)
# Symbol object representing the far month NIFTY futures
self.symbol_far_month = AlgorumQuantClient.algorum_types.TradeSymbol(
AlgorumQuantClient.algorum_types.SymbolType.FuturesIndex,
'NIFTY',
AlgorumQuantClient.algorum_types.FNOPeriodType.Monthly,
2,
0,
AlgorumQuantClient.algorum_types.OptionType.Unspecified,
0,
0)
The value of 0 for FNOMonth property of Symbol object indicates current month contract, value of 1 indicates mid month contract and value of 2 indicates far month contract. For instance in the above code snippet, if the current month is Jan 2022, the current month symbol indicates NIFTY futures for Jan 2022, mid month symbol indicates NIFTY futures for Feb 2022 and far month symbol indicates NIFTY futures for Mar 2022.
Auto handling of monthly expiry dates during Backtesting
The monthly futures contracts expire every Thursday of the month, and if Thursday is a holiday, a day before that (and goes back in time based on holidays). For instance, Jan 2022 NIFTY futures expire on Jan 27, 2022 (Thursday). So on Jan 28, the current month futures will become Feb 2022 futures. Algorum backtesting, paper trading and live trading engines takes care of this changes and will stream the correct tick data from correct futures contract to your strategy when the expiry happens every month.
Updated about 3 years ago