平均回帰とトレンドフォローを組み合わせた定量戦略


作成日: 2023-09-14 20:45:20 最終変更日: 2023-09-14 20:45:20
コピー: 0 クリック数: 1109
1
フォロー
1617
フォロワー

この記事では,平均回帰とトレンド追跡技術を同時に使用する量化取引戦略について詳しく説明します. この戦略は,トレンドの状況で逆行取引を行うことと,トレンドを追跡して同方向取引を行うことを目的としています.

戦略の原則

この戦略は,主に単純な移動平均とRSIの指標によって取引シグナルを生成します.

  1. 価格が200周期移動平均より低いとき,現在下方期にあると判断する.

  2. RSIが20を下回ったとき,逆の平均回帰取引を行います.

  3. 価格が200サイクル移動平均より高いとき,現在上昇段階にあると判断する.

  4. 価格が移動平均を上から突破する時に,順調なトレンドをフォローする取引を行う.

  5. 平仓条件は,RSIが80以上または価格が移動平均より一定幅下落である.

  6. 平均回帰とトレンド追跡の取引ポジションをそれぞれ設定できます.

この戦略は,平均回帰とトレンド追跡技術を統合して,異なる段階で適切な操作を行う.

2 戦略的優位性

この戦略の利点は以下の通りです.

  1. 戦略の適応性を向上させるための2つの異なる技術を組み合わせる

  2. 市場が動いている時と動いている時の両方で取引の機会を見つけることができます.

  3. ポジションを調整することで,異なるモデルのリスクをコントロールできます.

  4. パラメータ設定はシンプルで実行しやすい.

3 潜在的リスク

しかし,この戦略には次のリスクもあります.

  1. 移動平均とRSIなどの指標は偽の突破の影響を受けやすい.

  2. この2つの取引形態の切り替えは遅れている可能性がある.

  3. 長期的利益を得るために,一定額の撤収が必要になります.

内容と要約

この記事では,平均回帰とトレンド追跡技術を活用した量化取引戦略について詳しく説明する.この戦略は,異なる市場段階での取引を可能にし,適応性を向上させる.しかし,指標の失敗やパターン交換の遅れのリスクを防ぎることも必要である.全体的に,それは,異なる技術と柔軟な組み合わせの戦略理念を提供する.

ストラテジーソースコード
/*backtest
start: 2022-09-07 00:00:00
end: 2023-04-05 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/
// © I11L

//@version=5
strategy("Mean Reversion and Trendfollowing", overlay=true, pyramiding=1, default_qty_value=100000, initial_capital=100000, default_qty_type=strategy.cash, process_orders_on_close=false, calc_on_every_tick=false)

// Input for the starting date
start_date = input(timestamp("1 Feb 2000 12:00"), title="Starting Date")
enableMeanReversion = input.bool(true)
enableTrendfollowing = input.bool(true)
trendPositionFactor = input.float(1)
meanReversionPositionFactor = input.float(0.5)

// Convert the input string to a timestamp
start_ts = timestamp(year(start_date), month(start_date), dayofmonth(start_date), 0, 0)

// Check if the current bar's time is greater than or equal to the start timestamp
start_condition = time >= start_ts

var tradeOrigin = ""

sma200 = ta.sma(close,200)
rsi2 = ta.rsi(close,2)

isMeanReversionMode = close < sma200 or not(enableTrendfollowing)
isTrendfollowingMode = close > sma200 or not(enableMeanReversion)

isRsiBuy = rsi2 < 20 and enableMeanReversion
isRsiClose = rsi2 > 80 and enableMeanReversion

isSmaBuy = close > sma200 and enableTrendfollowing
isSmaClose = close < sma200 * 0.95 and enableTrendfollowing

isBuy = (isMeanReversionMode and isRsiBuy) or (isTrendfollowingMode and isSmaBuy)

positionSizeFactor = isSmaBuy ? trendPositionFactor : meanReversionPositionFactor

// Only execute the strategy after the starting date
if (start_condition)
    if (isBuy and strategy.opentrades == 0)
        tradeOrigin := isSmaBuy ? "SMA" : "RSI"
        strategy.entry("My Long Entry Id", strategy.long, qty=(strategy.equity / close) * positionSizeFactor, comment=str.tostring(positionSizeFactor))
    isClose = tradeOrigin == "SMA" ? isSmaClose : isRsiClose
    if (isClose)
        strategy.exit("Exit", limit = close)

plot(sma200)
plot(sma200 * 0.95, color=color.orange)