8. Intertemporal Arbitrage Trading Strategies (Equivalent Educational Version)

Reference source: docs/_joinquant_migration_source/Example_08_intertemporal arbitrage.ipynb First Markdown cell.

8.1. Strategy and Ideas

  • Construct price spreads using contracts of the same type but with different expiration dates;

  • Use a rolling window to estimate the degree of price spread deviation (zscore).

  • Short the spread when it crosses above the upper band, and go long when it crosses below the lower band.

  • Close the position when it returns to the neutral range.

8.2. QtEasy Implementation Instructions

  • The strategy class in this example is Example08CalendarSpread;

  • For the sake of teaching stability, the default script uses the daily index frequency for inter-period logical approximation;

  • If switching to a real futures contract, please handle the rollover logic at the same time and record the rollover rules in the documentation.

from examples.strategies.example_strategies import Example08CalendarSpread
import qteasy as qt

stg = Example08CalendarSpread()
op = qt.Operator(stg, signal_type='PT')
op.op_type = 'stepwise'
op.set_blender('1.0*s0')
res = qt.run(
    op,
    mode=1,
    asset_type='IDX',
    asset_pool=['000300.SH', '000905.SH'],
    benchmark_asset='000300.SH',
    invest_start='20190101',
    invest_end='20211231',
    invest_cash_amounts=[1000000],
    trade_batch_size=0.01,
    sell_batch_size=0.01,
    allow_sell_short=True,
    trade_log=True,
)

8.3. Executable script

  • examples/strategy_example_08.py