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

作者: リン・ハーンチャオチャン開催日:2023年9月14日 20:45:20
タグ:

この記事では,平均逆転とトレンドフォローテクニックの両方を組み合わせた定量的な取引戦略を詳細に説明します.トレンド市場中に反トレンド取引を行い,トレンド市場中にモメンタムに乗ることを目的としています.

I. 戦略の論理

この戦略は主に,シンプル・ムービング・アベアとRSIインジケーターを使用して取引信号を生成します.

  1. 価格が200期SMAを下回ると,現在の市場が下落傾向であると判断されます.

  2. RSIが20を下回ると 反トレンド・ミニアン・リバース・トレードです

  3. 価格が200期SMAを超えると,現在の市場が上昇傾向であると判断されます.

  4. 価格がSMAを超えると トレンドトレードが必要になります

  5. アクジットは,RSIが80を超えたり,価格がSMAを下回り,一定の割合で下がったときに発生します.

  6. 平均逆転とトレンドフォローのポジションサイズを別々に調整できます.

この戦略は,平均逆転とトレンドフォロー技術を組み合わせて,さまざまな市場段階に適用する.

戦略の利点

主な利点は以下の通りです.

  1. 2つの技術を組み合わせることで 戦略の適応性が向上します

  2. トレンドや変動する市場で 取引機会を見つけることができます

  3. リスクはポジションのサイズ調整によって制御できる.

  4. シンプルなパラメータ設定により 簡単に実装できます

III.潜在的なリスク

しかしリスクは次のとおりです

  1. SMAやRSIのような指標は 誤ったブレイクに敏感です

  2. 2つのモードの間の切り替えが遅れる可能性があります.

  3. 長期的に利益を得るためには 引き下げを 耐えなければなりません

IV.要約

この記事では,平均逆転とトレンドフォローテクニックを使用した定量戦略について説明しています.適応性を向上させるために異なる市場段階で取引することができます.しかし,指標の失敗や遅延モード切り替えなどのリスクは管理する必要があります.全体として,異なるテクニックを組み合わせる柔軟なアプローチを提供します.


/*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)

もっと