タイムステップピラミディング 単純な量子戦略

作者: リン・ハーンチャオチャン開催日:2023年12月27日 17:39:40
タグ:

img

概要

この戦略は,タイムステップピラミディングを使用する単純な量子取引戦略です.主なアイデアは,固定時間ごとに毎日ロングポジションを開き,各ポジションに異なる利益とストップ損失レベルを設定して,バッチド利益とストップ損失を実現することです.

原則

戦略は3つの主要な論理に基づいています

  1. 時間のピラミッド

    試しにsessionTime取引時間枠を設定するパラメータ,ピラミッド・ロング・ポジションは,この期間中にオープンする市場で段階的に設定されます.ポジションサイズは,最大資本の平均配分です.

  2. 利回りと停止損失を個別化した

    利益を得るレベルに対応するセットtakeProfitストップ損失レベルstopLossオープンしたポジションごとに,各ポジションは,バッチ実行を実現するために,独自の利益と損失を停止する論理を持っています.

  3. タイムウィンドウが終了するとすべてのポジションを閉じる

    タイムウィンドウの終わりに オープンしたすべてのポジションを閉めるかどうかを選択します.

利点

この戦略には以下の利点があります.

  1. リスクの多様化 単一のポジションの損失を効果的に制御するために,資本を異なるポジションに均等に分配する.

  2. バッチ利益とストップ損失.異なるポジションは,大量ストップ損失を避けるために独立した論理を持っています.

  3. 柔軟な構成.最大ピラミッド化時間,日々の時間窓,利益/ストップ損失比など,カスタマイズ可能なパラメータ.

  4. シンプルでわかりやすい論理です

リスク

リスクもあります:

  1. すべてのポジションが利益を得る前にストップ・ロスを引き起こす場合 資本が完全に固定されるリスクは,ストップ・ロスの比率を合理的に設定することで回避できます.

  2. オープンポジション総資本の制限なし. 過剰なポジションは,異常な市場状況に直面した場合,資本容量を超えることがあります. 最大の総ポジション資本を1日追加することを検討してください.

  3. 不適切な時間窓の設定は,取引機会を逃す可能性があります. 取引資産のアクティブ・トレード・タイム・ウィンドウを参照してください.

強化

戦略は次の側面から強化される:

  1. 技術指標に基づく オープンポジション条件を追加して 無謀なピラミディングを避ける

  2. 公開ポジションの総日額資本上限を追加し,資本負担性を超えることを防止する.

  3. 異なるポジションに対して異なる取利益/ストップ損失比を設定し,差別化された取利益とストップ損失を実現する.

  4. ポジション額と資本プール残高を結びつける論理を追加する.

結論

結論として,これは時間段階ピラミッド化方法論を利用した非常にシンプルな量子取引戦略テンプレートです.論理はシンプルで明確ですが,いくつかのリスクと改善余地もあります.開発者は比較的安定し信頼性の高い量子戦略になるために適切に最適化することができます.


/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © A3Sh

//@version=5
strategy("Simple_Pyramiding", overlay=true, pyramiding=99, initial_capital=500, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.075, close_entries_rule='FIFO')

// Study of a Simple DCA strategy that opens a position every day at a specified time.
// A position is opened at the start time of the Timeframe.
// Positions exit individually when the take profit level is triggered.
// Option to activate Stop Loss and/or Position exit at the end of the Timeframe


// Backtest Window
start_time   = input(defval=timestamp("01 April 2021 20:00"), group = "Backtest Window", title="Start Time")
end_time     = input(defval=timestamp("01 Aug 2022 20:00"),  group = "Backtest Window", title="End Time")
window() => true


// Inputs
posCount     = input.int    (6,           group = "Risk",         title = "Max Amount of DCA Entries")
takeProfit   = input.float  (2.5,         group = "Risk",         title = "Take Profit %")
slSwitch     = input.bool   (true,        group = "Risk",         title = "Activate Stop Loss")
stopLoss     = input.float  (9,           group = "Risk",         title = "Stop Loss %")
sessionTime =  input("1800-1700", group = "DCA Settings", title = "DCA Order Timeframe", tooltip="Open order at the start/If ativated, close order at the end")
exitDCA     =  input.bool   (false,       group = "DCA Settings", title = "Exit DCA Entry at end of Timeframe")


// Order size based on max amount of pyramid orders
q = (strategy.equity  / posCount) / open


// Timeframe for opening and closing a DCA order
// example taken from https://stackoverflow.com/questions/69230164/pinescript-basic-question-open-a-trade-at-a-set-time-each-day
t       = time("D", sessionTime)
isStart = na(t[1]) and not na(t) or t[1] < t
isEnd   = na(t) and not na(t[1]) or t[1] < t
bgcolor(t ? color.new(color.blue,95) : na, title = " TimeFrame Color")


// Create DCA Entries
entry_price = 0.0
if isStart and window() 
    for i = 0 to strategy.opentrades
        if strategy.opentrades == i
            entry_price := close
            entry_id = "PE_" + str.tostring(i + 1) 
            strategy.entry(id = entry_id, direction=strategy.long, limit=entry_price, qty=q)
        if strategy.opentrades == posCount
            break
            
 
//Exit DCA Entries when take profit or stop loss is triggered
if strategy.opentrades > 0 and window() 
    for i = 0 to strategy.opentrades 
        exit_from = "PE_" + str.tostring(i + 1)
        exit_id = "Exit_" + str.tostring(i + 1)
        strategy.exit(id= exit_id, from_entry= exit_from, profit = close * takeProfit / 100 / syminfo.mintick, loss = slSwitch ? close * stopLoss /100 / syminfo.mintick :na)
        

//Exit DCA Entries at end of DCA Timeframe
if strategy.opentrades > 0 and exitDCA and isEnd and window() 
    for i = 0 to strategy.opentrades 
        exit_from = "PE_" + str.tostring(i + 1)
        exit_id = "Exit_" + str.tostring(i + 1)
        strategy.exit(id= exit_id, from_entry= exit_from, stop = close)




もっと