Back to Nautilus Trader

Futures Spread

docs/concepts/instruments/futures_spread.md

1.228.06.7 KB
Original Source

Futures Spread

FuturesSpread represents an exchange-defined futures strategy with more than one leg, such as a calendar spread or inter-commodity spread. The venue defines the strategy, symbol, tick size, and expiry.

Examples include listed futures calendar spreads and exchange-supported spread markets.

Fields

FieldRust typePython typeRequired/defaultNotes
instrument_idInstrumentIdInstrumentIdRequiredStored as id in Rust.
raw_symbolSymbolSymbolRequiredNative venue symbol.
asset_classAssetClassAssetClassRequiredAsset class of the underlying strategy.
exchangeOption<Ustr>str | NoneNoneExchange MIC or venue code when known.
underlyingUstrstrRequiredUnderlying product or product family.
strategy_typeUstrstrRequiredVenue strategy type, such as calendar.
activation_nsUnixNanosintRequiredStrategy activation timestamp.
expiration_nsUnixNanosintRequiredStrategy expiration timestamp.
currencyCurrencyCurrencyRequiredQuote and settlement currency.
price_precisionu8intRequiredDecimal places allowed for prices.
price_incrementPricePriceRequiredSmallest valid price step.
size_precisionu8int0Futures spreads trade in whole contracts.
size_incrementQuantityQuantity1Minimum contract size step.
multiplierQuantityQuantityRequiredStrategy multiplier.
lot_sizeQuantityQuantityRequiredRounded lot or contract lot size.
margin_initOption<Decimal>Decimal | None0Initial margin rate.
margin_maintOption<Decimal>Decimal | None0Maintenance margin rate.
maker_feeOption<Decimal>Decimal | None0Maker fee rate. Negative values rebate.
taker_feeOption<Decimal>Decimal | None0Taker fee rate. Negative values rebate.
max_quantityOption<Quantity>Quantity | NoneNoneMaximum order quantity.
min_quantityOption<Quantity>Quantity | None1Minimum order quantity.
max_priceOption<Price>Price | NoneNoneMaximum valid quote or order price.
min_priceOption<Price>Price | NoneNoneMinimum valid quote or order price.
tick_scheme_nameN/Astr | NoneNoneRegistered variable tick scheme name.
infoOption<Params>dict | NoneNoneAdapter metadata.
ts_eventUnixNanosintRequiredEvent timestamp in nanoseconds.
ts_initUnixNanosintRequiredInitialization timestamp in nanoseconds.

Note: Python constructors use instrument_id; Rust stores the same value as id.

Behavior

  • FuturesSpread has instrument class FuturesSpread.
  • The venue publishes the spread as a single tradable instrument.
  • It trades in whole contracts with size precision 0 and size increment 1.
  • Use leg data from the adapter metadata when a strategy needs venue-specific leg details.

Example

rust
use chrono::{TimeZone, Utc};
use nautilus_core::UnixNanos;
use nautilus_model::{
    enums::AssetClass,
    identifiers::{InstrumentId, Symbol},
    instruments::FuturesSpread,
    types::{Currency, Price, Quantity},
};
use ustr::Ustr;

let activation = Utc.with_ymd_and_hms(2022, 6, 21, 13, 30, 0).unwrap();
let expiration = Utc.with_ymd_and_hms(2024, 6, 21, 13, 30, 0).unwrap();

let es_spread = FuturesSpread::new(
    InstrumentId::from("ESM4-ESU4.GLBX"),
    Symbol::from("ESM4-ESU4"),
    AssetClass::Index,
    Some(Ustr::from("XCME")),
    Ustr::from("ES"),
    Ustr::from("EQ"),
    UnixNanos::from(activation.timestamp_nanos_opt().unwrap() as u64),
    UnixNanos::from(expiration.timestamp_nanos_opt().unwrap() as u64),
    Currency::from("USD"),
    2,
    Price::from("0.01"),
    Quantity::from("1"),
    Quantity::from("1"),
    None,
    None,
    None,
    None,
    None,
    None,
    None,
    None,
    None,
    UnixNanos::default(),
    UnixNanos::default(),
);
python
import pandas as pd

from nautilus_trader.model.currencies import USD
from nautilus_trader.model.enums import AssetClass
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.identifiers import Symbol
from nautilus_trader.model.instruments import FuturesSpread
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity

es_spread = FuturesSpread(
    instrument_id=InstrumentId.from_str("ESM4-ESU4.GLBX"),
    raw_symbol=Symbol("ESM4-ESU4"),
    asset_class=AssetClass.INDEX,
    exchange="XCME",
    underlying="ES",
    strategy_type="EQ",
    activation_ns=pd.Timestamp("2022-06-21T13:30:00", tz="UTC").value,
    expiration_ns=pd.Timestamp("2024-06-21T13:30:00", tz="UTC").value,
    currency=USD,
    price_precision=2,
    price_increment=Price.from_str("0.01"),
    multiplier=Quantity.from_int(1),
    lot_size=Quantity.from_int(1),
    ts_event=0,
    ts_init=0,
)

Adapters

Representative adapters that create or consume FuturesSpread instruments include: