自己適応型量子グリッド取引戦略

作者: リン・ハーンチャオチャン,日付: 2024-02-02 18:08:22
タグ:

img

概要

この戦略は,不安定な市場の中で安定した利益を達成するために動的な取引グリッドを確立する. 既定のグリッドラインの数に基づいてグリッド間隔と上限/下限を自動的に計算する. 価格が各グリッドラインを突破すると,ロング/ショートポジションがバッチで構築される. 価格が元のグリッドラインに再び突入すると利益を得られる. この戦略は,変化する市場状況に適応するためにグリッドパラメータの手動および自動調整の両方をサポートする.

戦略の論理

  1. 入力パラメータに基づいてグリッド境界とグリッドライン価格配列を計算する.

  2. 価格が対応するオーダーなしのグリッドラインを下回ると,ロングオーダーはグリッドライン価格に置かれます.価格が既存のポジションで前のグリッドライン (最初の除外) を上回ると,前のラインのロングオーダーは閉鎖されます.

  3. 自動調整が有効であれば,グリッド上下限,グリッド間隔,グリッド配列は,最近のキャンドルスタイクデータに基づいて定期的に再計算されます.

利点分析

  1. 不安定な市場の中で安定した利益を実現する.全体的な利益を達成するために,ロング/ショートポジションは異なる価格レベルでバッチで構築され,閉鎖されます.

  2. 手動および自動パラメータ調整の両方をサポートします. 手動調整はより良い制御を提供しますが,介入が必要です. 自動調整は作業量を削減し,変化する市場動態に適応します.

  3. 最大損失は,最大数のグリッドラインを制限することで制限されます.価格がすべてのグリッドラインを壊すと,リスクは抑えられます.

  4. 格子間隔を調整して,取引ごとに利益/損失を調整します.より小さい間隔は,取引ごとに露出量を低下させます.

リスク分析

  1. 網域内での価格変動は損失につながる可能性があります.

  2. 十分な初期資本が必要です 十分な資金が供給できないので

  3. 格段なグリッド数は利益を不利にします.格段なグリッドが波動性を完全に利用できず,格段なグリッドが取引ごとに最小限の利益をもたらします.最適な設定を決定するために広範なテストが必要です.

  4. 自動調整は価格操作の危険性がある.短期的な価格操作の影響を受ける可能性のある最近のキャンドルスタイクに依存する.

最適化

  1. ストップ・ロスのロジックを導入し,方向性ごとにダウンサイドリスクをさらに制限します.

  2. 機械学習によるグリッドパラメータの最適化 市場の条件に合わせて異なるパラメータをテストし,最適で適応可能なパラメータを得るためにMLモデルを訓練します

  3. 追加的な技術指標を組み込む MACD や RSI などの指標で現在のトレンド強さを評価し,グリッド量とパラメータ調整をガイドする.

  4. 最大許容される引き上げパーセントを設定することによってリスク管理を強化します. リスク制限が破られたときに戦略を無効にします.

結論

この戦略は不安定な市場の特徴を完全に活用し,パラメータの柔軟性と操作の容易さを兼ね備えたダイナミックなグリッド取引フレームワークを通じて安定した利益を達成する.損失制御と自動パラメータ最適化のさらなる強化により,市場の変動から持続的な利益を生み出す理想的なモデルになることができます.


/*backtest
start: 2024-01-02 00:00:00
end: 2024-02-01 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("(IK) Grid Script", overlay=true, pyramiding=14, close_entries_rule="ANY", default_qty_type=strategy.cash, initial_capital=100.0, currency="USD", commission_type=strategy.commission.percent, commission_value=0.1)
i_autoBounds    = input(group="Grid Bounds", title="Use Auto Bounds?", defval=true, type=input.bool)                             // calculate upper and lower bound of the grid automatically? This will theorhetically be less profitable, but will certainly require less attention
i_boundSrc      = input(group="Grid Bounds", title="(Auto) Bound Source", defval="Hi & Low", options=["Hi & Low", "Average"])     // should bounds of the auto grid be calculated from recent High & Low, or from a Simple Moving Average
i_boundLookback = input(group="Grid Bounds", title="(Auto) Bound Lookback", defval=250, type=input.integer, maxval=500, minval=0) // when calculating auto grid bounds, how far back should we look for a High & Low, or what should the length be of our sma
i_boundDev      = input(group="Grid Bounds", title="(Auto) Bound Deviation", defval=0.10, type=input.float, maxval=1, minval=-1)  // if sourcing auto bounds from High & Low, this percentage will (positive) widen or (negative) narrow the bound limits. If sourcing from Average, this is the deviation (up and down) from the sma, and CANNOT be negative.
i_upperBound    = input(group="Grid Bounds", title="(Manual) Upper Boundry", defval=0.285, type=input.float)                      // for manual grid bounds only. The upperbound price of your grid
i_lowerBound    = input(group="Grid Bounds", title="(Manual) Lower Boundry", defval=0.225, type=input.float)                      // for manual grid bounds only. The lowerbound price of your grid.
i_gridQty       = input(group="Grid Lines",  title="Grid Line Quantity", defval=8, maxval=15, minval=3, type=input.integer)       // how many grid lines are in your grid

f_getGridBounds(_bs, _bl, _bd, _up) =>
    if _bs == "Hi & Low"
        _up ? highest(close, _bl) * (1 + _bd) : lowest(close, _bl)  * (1 - _bd)
    else
        avg = sma(close, _bl)
        _up ? avg * (1 + _bd) : avg * (1 - _bd)

f_buildGrid(_lb, _gw, _gq) =>
    gridArr = array.new_float(0)
    for i=0 to _gq-1
        array.push(gridArr, _lb+(_gw*i))
    gridArr

f_getNearGridLines(_gridArr, _price) =>
    arr = array.new_int(3)
    for i = 0 to array.size(_gridArr)-1
        if array.get(_gridArr, i) > _price
            array.set(arr, 0, i == array.size(_gridArr)-1 ? i : i+1)
            array.set(arr, 1, i == 0 ? i : i-1)
            break
    arr

var upperBound      = i_autoBounds ? f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, true) : i_upperBound  // upperbound of our grid
var lowerBound      = i_autoBounds ? f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, false) : i_lowerBound // lowerbound of our grid
var gridWidth       = (upperBound - lowerBound)/(i_gridQty-1)                                                       // space between lines in our grid
var gridLineArr     = f_buildGrid(lowerBound, gridWidth, i_gridQty)                                                 // an array of prices that correspond to our grid lines
var orderArr        = array.new_bool(i_gridQty, false)                                                              // a boolean array that indicates if there is an open order corresponding to each grid line

var closeLineArr    = f_getNearGridLines(gridLineArr, close)                                                        // for plotting purposes - an array of 2 indices that correspond to grid lines near price
var nearTopGridLine = array.get(closeLineArr, 0)                                                                    // for plotting purposes - the index (in our grid line array) of the closest grid line above current price
var nearBotGridLine = array.get(closeLineArr, 1)                                                                    // for plotting purposes - the index (in our grid line array) of the closest grid line below current price
strategy.initial_capital = 50000
for i = 0 to (array.size(gridLineArr) - 1)
    if close < array.get(gridLineArr, i) and not array.get(orderArr, i) and i < (array.size(gridLineArr) - 1)
        buyId = i
        array.set(orderArr, buyId, true)
        strategy.entry(id=tostring(buyId), long=true, qty=(strategy.initial_capital/(i_gridQty-1))/close, comment="#"+tostring(buyId))
    if close > array.get(gridLineArr, i) and i != 0
        if array.get(orderArr, i-1)
            sellId = i-1
            array.set(orderArr, sellId, false)
            strategy.close(id=tostring(sellId), comment="#"+tostring(sellId))

if i_autoBounds
    upperBound  := f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, true)
    lowerBound  := f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, false)
    gridWidth   := (upperBound - lowerBound)/(i_gridQty-1)
    gridLineArr := f_buildGrid(lowerBound, gridWidth, i_gridQty)

closeLineArr    := f_getNearGridLines(gridLineArr, close)
nearTopGridLine := array.get(closeLineArr, 0)
nearBotGridLine := array.get(closeLineArr, 1)



もっと