7. Cross-product arbitrage trading strategies (educational equivalent version)
Reference source: docs/_joinquant_migration_source/Example_07_跨商品套利.ipynb First Markdown cell. Note: The original notebook was marked “Information issues require correction”. This example is based on the reproducible implementation in qteasy.
7.1. Strategy and Ideas
Select two highly correlated trading instruments and construct a price spread
spread = p1 - p2;The mean and standard deviation of the price difference are calculated within a scrolling window to obtain the zscore.
When zscore is above the upper threshold, short spreads are opened (sell the first one and buy the second one); when zscore is below the lower threshold, long spreads are opened.
Close the position when the price returns to near the exit threshold.
7.2. QtEasy Implementation Instructions
This article uses the
PTsignal and the strategy class isExample07CrossSymbolSpread;To reduce data dependency, the example script uses daily index pairs (approximate for teaching purposes) by default, instead of the original minute futures contract pairs;
If you have local futures minute data, you can replace
asset_type/asset_pool/freqin the script with the futures version.
from examples.strategies.example_strategies import Example07CrossSymbolSpread
import qteasy as qt
stg = Example07CrossSymbolSpread()
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,
)
7.3. Executable script
examples/strategy_example_07.py