Skip to content
All library documents

TqSdk Examples for Trading, Arbitrage, and Execution Strategies

Article TqSdk

Summary

This page is an index of complete strategy examples intended as starting points for adaptation in TqSdk. It groups examples into classic strategies, trend approaches, arbitrage, mean reversion, and algorithmic execution. Named examples include dual moving averages, momentum, grid trading, random forests, and Turtle trading; trend indicators such as TRIX and Keltner Channels; commodity and futures spreads; pairs strategies using Kalman filters or distance; and iceberg, POV, and VWAP execution methods.

The page gives category labels and difficulty ratings, and points readers to separate strategy explanations and example implementations. The implementations themselves are referenced rather than included in the page text, so it does not provide enough detail here to assess entry rules, sizing, risk controls, or results. It is useful as a map of approaches to investigate, not as evidence that any listed strategy works. The page also suggests introductory TqSdk materials for readers new to the framework.

Key ideas

  • The page catalogs reusable TqSdk examples across several strategy and execution categories.
  • Listed approaches include trend following, spread arbitrage, mean reversion, and algorithmic order execution.
  • Difficulty labels and links to explanations help readers locate examples for further study.
  • The referenced implementations and performance evidence are not present in the page itself.

Tags

Full text
# strategy


.. _demo_strategy:

交易策略示例
====================================================

这一页收集的是可直接改造的完整策略示例。它更适合作为“参考实现”而不是第一篇入门材料;第一次学习 TqSdk,建议先读 :ref:`quickstart` 和 :ref:`demo_base`。

如果你只想先挑几篇代表性示例:

* 趋势与均线::ref:`Doublema <demo-strategy-doublema>`、:ref:`tutorial-t60`、:ref:`tutorial-t70`
* 套利与价差::ref:`PTA 产业链套利 <demo-strategy-pta-spread>`、:ref:`养殖价差套利 <demo-strategy-smash-spread>`、:ref:`tutorial-t80`
* 执行算法::ref:`冰山订单算法 <demo-strategy-iceberg>`、:ref:`盘口下单算法 <demo-strategy-handicap>`、:ref:`跟量下单算法(POV) <demo-strategy-pov>`、:ref:`VWAP(Volume Weighted Average Price) <demo-strategy-vwap>`

.. contents:: 目录


经典策略
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Aberration 策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/aberration/

.. literalinclude:: ../../tqsdk/demo/example/aberration.py
  :language: python


.. _demo-strategy-doublema:

Doublema 双均线策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

.. literalinclude:: ../../tqsdk/demo/example/doublema.py
  :language: python


价格动量策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/momentum-strategy/

.. literalinclude:: ../../tqsdk/demo/example/momentum.py
  :language: python


自动扶梯策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/escalator/

.. literalinclude:: ../../tqsdk/demo/example/escalator.py
  :language: python


菲阿里四价 策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/fairy-four-price/

.. literalinclude:: ../../tqsdk/demo/example/fairy_four_price.py
  :language: python


R-Breaker 交易策略 - 隔夜留仓 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/r-breaker/

.. literalinclude:: ../../tqsdk/demo/example/rbreaker.py
  :language: python


R-Breaker 交易策略 - 非隔夜留仓 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/r-breaker/

.. literalinclude:: ../../tqsdk/demo/example/rbreaker2.py
  :language: python


Dual Thrust 策略 (难度:中级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/dual-thrust/

.. literalinclude:: ../../tqsdk/demo/example/dualthrust.py
  :language: python


网格交易策略 (难度:中级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/grid-trading/

.. literalinclude:: ../../tqsdk/demo/example/gridtrading.py
  :language: python


网格交易策略 - 异步代码 (难度:中级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/grid-trading/

.. literalinclude:: ../../tqsdk/demo/example/gridtrading_async.py
  :language: python


随机森林 (难度:中级)
""""""""""""""""""""""""""""""""""""""""""""""""

.. literalinclude:: ../../tqsdk/demo/example/random_forest.py
  :language: python


海龟交易策略 (难度:中级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/turtle/

.. literalinclude:: ../../tqsdk/demo/example/turtle.py
  :language: python


.. _demo-strategy-vwap:

Volume Weighted Average Price 策略 (难度:高级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/blog/vwap/

.. literalinclude:: ../../tqsdk/demo/example/vwap.py
  :language: python


趋势策略
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

三重指数平滑平均线 (TRIX) 趋势策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/trix-strategy

.. literalinclude:: ../../tqsdk/demo/example/TRIX.py
  :language: python


基于分形的趋势突破策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/fractal-trend-strategy

.. literalinclude:: ../../tqsdk/demo/example/fractal-trend.py
  :language: python


基于钱德动量震荡指标(CMO)的期货量化交易策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/cmo-strategy

.. literalinclude:: ../../tqsdk/demo/example/CMO.py
  :language: python


涡旋指标期货量化策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/vortex-indicator-strategy

.. literalinclude:: ../../tqsdk/demo/example/vortex-indicator.py
  :language: python


Hull移动平均线策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/hull-strategy

.. literalinclude:: ../../tqsdk/demo/example/hull.py
  :language: python


Keltner Channel策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/keltner-channel-strategy

.. literalinclude:: ../../tqsdk/demo/example/Keltner_Channel.py
  :language: python


Qstick趋势策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/qstick-strategy

.. literalinclude:: ../../tqsdk/demo/example/Qstick.py
  :language: python


Aroon指标趋势策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/aroon-strategy

.. literalinclude:: ../../tqsdk/demo/example/Aroon.py
  :language: python



量价趋势策略(VPT) (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/trend-following/vpt-strategy

.. literalinclude:: ../../tqsdk/demo/example/volume_price.py
  :language: python


套利策略
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. _demo-strategy-pta-spread:

PTA产业链套利 (涤纶短纤生产利润)策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/pta-spread

.. literalinclude:: ../../tqsdk/demo/example/pta_spread.py
  :language: python


.. _demo-strategy-smash-spread:

养殖价差套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/smash-spread

.. literalinclude:: ../../tqsdk/demo/example/smash_spread.py
  :language: python

双焦(焦煤-焦炭)套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/jm-j-spread

.. literalinclude:: ../../tqsdk/demo/example/jm-j-spread.py
  :language: python


甲醇制烯烃(MTO)产业链套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/mto-spread

.. literalinclude:: ../../tqsdk/demo/example/mto_spread.py
  :language: python


铜铝比价套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/cu-al-spread

.. literalinclude:: ../../tqsdk/demo/example/cu-al-spread.py
  :language: python


压榨价差套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/crush-spread

.. literalinclude:: ../../tqsdk/demo/example/crush_spread.py
  :language: python


裂解价差套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/crack-spread

.. literalinclude:: ../../tqsdk/demo/example/crack_spread_arbitrage.py
  :language: python


股指期货跨期套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/stock-future-cross-period-spread

.. literalinclude:: ../../tqsdk/demo/example/stock-future-cross-period-spread.py
  :language: python

钢厂利润套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/rb-i-jt-spread

.. literalinclude:: ../../tqsdk/demo/example/rb-i-jt-spread.py
  :language: python


菜油、豆油、棕榈油多品种套利策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/arbitrage/oi-y-p-spreads

.. literalinclude:: ../../tqsdk/demo/example/oi-y-p-spreads.py
  :language: python


均值回归策略
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

卡尔曼滤波配对交易策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/mean-reversion/kalman-filter-strategy

.. literalinclude:: ../../tqsdk/demo/example/kalman_filter_pairs_trading.py
  :language: python


基于距离的配对交易策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/mean-reversion/distance-based-strategy

.. literalinclude:: ../../tqsdk/demo/example/distance_based.py
  :language: python


枢轴点反转策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/mean-reversion/pivot-point-strategy

.. literalinclude:: ../../tqsdk/demo/example/pivot_point.py
  :language: python


CCI均值回归策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/mean-reversion/cci-strategy

.. literalinclude:: ../../tqsdk/demo/example/CCI.py
  :language: python


RSI超买/超卖交易策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/mean-reversion/rsi-strategy

.. literalinclude:: ../../tqsdk/demo/example/RSI.py
  :language: python


Z-Score均值回归策略 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/mean-reversion/zscore-strategy

.. literalinclude:: ../../tqsdk/demo/example/z_score.py
  :language: python

算法交易策略
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. _demo-strategy-iceberg:

冰山订单算法 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/other/iceberg-order

.. literalinclude:: ../../tqsdk/demo/example/iceberg_algorithm.py
  :language: python


.. _demo-strategy-handicap:

盘口下单算法 (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/other/handicap

.. literalinclude:: ../../tqsdk/demo/example/handicap_algorithm.py
  :language: python


.. _demo-strategy-pov:

跟量下单算法(POV) (难度:初级)
""""""""""""""""""""""""""""""""""""""""""""""""

策略说明 https://www.shinnytech.com/articles/trading-strategy/other/pov

.. literalinclude:: ../../tqsdk/demo/example/pov.py
  :language: python

Shown in full with attribution under the source's licence. Licence: Apache-2.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.