線形回帰移動平均取引戦略

作者: リン・ハーンチャオチャン, 日付: 2023年10月25日 10:58:02
タグ:

img

概要

Linear Regression Moving Averageの取引戦略は,線形回帰線と株式価格の移動平均のクロスオーバーに基づいて買い売り信号を生成する.この戦略は,トレンドフォローと線形回帰分析を組み合わせて,潜在的な逆転を特定し,低価格の購入と高値の販売を達成する.

戦略の論理

この戦略は,まずn日間の線形回帰線と株式価格のm日間の移動平均線を計算する.回帰線は長期的な統計的傾向を捉え,移動平均線は短期的な勢いを反映する.

移動平均線が回帰線の上を横切ると,上向きの勢力の強化をシグナル化し,買い信号を生成する.移動平均線が下を横切ると,上向きの弱まりをシグナル化し,売り信号を生成する.

具体的には,この戦略は,取引信号を決定するための次のステップに従います.

  1. 価格の線形回帰線を計算する

  2. lrLine の m-day 単純な移動平均を計算する.

  3. 価格の指数関数移動平均を計算します.

  4. エマがlrMAを超えると,買い信号を長引く

  5. エマがlrMAを下回ると,売り信号を長出します.

  6. 市場が上昇しているときにのみ購入シグナルを検討します.

  7. シグナルに基づいて取引を実行する

回帰値と移動平均値のクロスオーバーを使用してエントリを決定することで,戦略は誤ったブレイクを効果的にフィルタリングし,低値で購入し高値で販売する逆転を特定することができます.

利点

  • 傾向と回帰分析を組み合わせて,正確な信号識別を行う.
  • 回帰線は計算し,実行するのは簡単です
  • 不利な取引を避けるために市場フィルタリングを使用します
  • 戦略の調整のためのパーマター
  • 低価格で購入し,高価格で販売し,利益を得る

リスク

  • 波動期間の頻繁なクロスオーバーは,誤った信号を生む可能性があります.
  • 不正確な市場フィルターは,誤ったタイミングでエントリーにつながる
  • パラメータの調節が悪ければ戦略のパフォーマンスに影響する
  • 高い取引頻度は高いコストにつながります

パラメータは移動平均値と回帰線期間を増やし,取引頻度を減らすように調整されるべきである.リスクを制御するために合理的なストップ損失が実装されるべきである. 精度を向上させるために市場フィルターを強化することができる.

改良

戦略は,いくつかの側面で最適化することができます:

  1. 移動平均の最適化

  2. 計算期間調整による回帰線最適化

  3. 異なる指標をテストすることによって市場フィルターの最適化

  4. 厳格なバックテストによるパラメータ最適化

  5. ストップ・ロスの最適化は,異なるストップ・ロスの論理をテストする

  6. コストを考慮して取引頻度を調整することでコストの最適化

これらの最適化は,戦略の安定性と収益性をさらに向上させることができます.

結論

線形回帰MA戦略は,効果的な逆転の識別と低価格の高値の購入のために,トレンド分析と線形回帰の強みを統合している.このシンプルな戦略は,中長期間の株式ピックリングに適している.パラメータ調整とリスク制御により,戦略はさらに高い安定性を達成することができる.市場分析のための実行可能な技術取引フレームワークを提供します.


/*backtest
start: 2022-10-18 00:00:00
end: 2023-10-24 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/
// © lazy_capitalist

//@version=5
strategy('Linear Regression MA', overlay=true, initial_capital=10000)
datesGroup = "Date Info"
startMonth = input.int(defval = 1,    title = "Start Month",  minval = 1, maxval = 12,  group=datesGroup)
startDay   = input.int(defval = 1,    title = "Start Day",    minval = 1, maxval = 31,  group=datesGroup)
startYear  = input.int(defval = 2022, title = "Start Year",   minval = 1970,            group=datesGroup)

averagesGroup = "Averages"
lrLineInput     = input.int(title="Linear Regression Line",   defval=55, minval = 1, group=averagesGroup)
lrMAInput       = input.int(title="Linear Regression MA",     defval=55, minval = 1, group=averagesGroup)
emaInput        = input.int(title="EMA Length",               defval=55, minval = 1, group=averagesGroup)


tradesGroup = "Execute Trades"
executeLongInput    = input.bool(title="Execute Long Trades",       defval=true)
executeShortInput   = input.bool(title="Execute Short Trades",      defval=true)
executeStopLoss     = input.bool(title="Execute Stop Loss",         defval=true)

fourHrSMAExpr       = ta.sma(close, 200)
fourHrMA            = request.security(symbol=syminfo.tickerid, timeframe="240", expression=fourHrSMAExpr)

bullish             = close > fourHrMA ? true : false


maxProfitInput              = input.float(  title="Max Profit (%)",         defval=10.0,    minval=0.0)   * 0.01
stopLossPercentageInput     = input.float(  title="Stop Loss (%)",          defval=1.75,    minval=0.0)   * 0.01

start       = timestamp(startYear, startMonth, startDay, 00, 00)            // backtest start  window
window()    => time >= start ? true : false                              // create function "within window of time"
showDate    = input(defval = true, title = "Show Date Range")

lrLine = ta.linreg(close, lrLineInput, 0)
lrMA   = ta.sma(lrLine, lrMAInput)
ema     = ta.ema(close, emaInput)

longEntry   = ema   < lrMA
longExit    = lrMA  < ema

shortEntry  = lrMA  < ema
shortExit   = ema   < lrMA


maxProfitLong   = strategy.opentrades.entry_price(0) * (1 + maxProfitInput)
maxProfitShort  = strategy.opentrades.entry_price(0) * (1 - maxProfitInput)

stopLossPriceShort  = strategy.position_avg_price * (1 + stopLossPercentageInput)
stopLossPriceLong   = strategy.position_avg_price * (1 - stopLossPercentageInput)

if(executeLongInput and bullish)
    strategy.entry( id="long_entry", direction=strategy.long,   when=longEntry and window(),    qty=10,  comment="long_entry")
    strategy.close( id="long_entry", when=longExit,     comment="long_exit")
    // strategy.close( id="long_entry", when=maxProfitLong <= close, comment="long_exit_mp")
    
if(executeShortInput and not bullish)
    strategy.entry( id="short_entry", direction=strategy.short,   when=shortEntry and window(),    qty=10,  comment="short_entry")
    strategy.close( id="short_entry", when=shortExit,     comment="short_exit")
    // strategy.close( id="short_entry", when=maxProfitShort <= close, comment="short_exit_mp")

if(strategy.position_size > 0 and executeStopLoss)
    strategy.exit(  id="long_entry",        stop=stopLossPriceLong,             comment="exit_long_SL")
    strategy.exit(  id="short_entry",       stop=stopLossPriceShort,            comment="exit_short_SL")
    
// plot(series=lrLine,     color=color.green)
plot(series=lrMA,       color=color.red)
plot(series=ema,        color=color.blue)


もっと