移動平均に基づく定量取引戦略


作成日: 2024-01-26 16:29:23 最終変更日: 2024-01-26 16:29:23
コピー: 0 クリック数: 555
1
フォロー
1617
フォロワー

移動平均に基づく定量取引戦略

概要

移動平均の交差戦略は,移動平均に基づいて定量的な取引戦略である.この戦略は,期間中の証券の平均価格を計算し,価格の移動平均の交差を利用して取引信号を生成し,利益を上げる.

戦略原則

この戦略は,価格の傾向を判断し,取引シグナルを生成するために,主に高速移動平均と遅い移動平均の交差を使用します.具体的には,10日線と20日線のような2つの異なる周期長さの移動平均を使用します.

急速移動平均線が下方からゆっくり移動平均線を突破すると,市場が下方からに転じ,買入シグナルを生成すると考えます. 急速移動平均線が上方から下方からゆっくり移動平均線を突破すると,市場がから下方へ転じ,売出シグナルを生成すると考えます.

この戦略は,価格トレンドの転換点を捉えることで,好転時に買い,好転時に売り,利益を得ることができます.

優位分析

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

  1. 概念はシンプルで理解し実行しやすい
  2. 移動平均の周期等を調整できるカスタマイズ可能なパラメータ
  3. 予測の効果が高く,特にトレンド性のある状況に適しています.
  4. ストップ・ストップ・ロージックに組み込み,リスクを制御

リスク分析

この戦略には以下のリスクもあります.

  1. 市場を整理する際に誤信号や過剰取引が起こりやすい
  2. パラメータをデビューする必要があります. パラメータの組み合わせによって反測効果は大きく異なります.
  3. 取引コストと滑り点を考慮しない場合,リッドディスクの効果は回測よりも弱くなる可能性があります.
  4. 価格の急激な逆転の機会を逃す可能性のある時間遅れがある

これらのリスクは適切な最適化によって軽減できます.

最適化の方向

この戦略は以下の方向から最適化できます.

  1. 集積時に誤った取引を避けるために,量能指数,振動指数などの他の指標のフィルター信号と組み合わせる
  2. 価格を把握するために,周期パラメータの動的変化に適応した移動平均を追加します.
  3. 移動平均の周期パラメータを最適化して,最適なパラメータの組み合わせを探します.
  4. 取引の頻度を減らすために再入場条件を設定する
  5. 実際の取引コストと滑り点を考慮し,ストップ・ストップ・ロスを調整します.

戦略の実用性を大幅に向上させることができます.

要約する

移動平均交差戦略は,全体として,習得しやすく実行可能な量化取引戦略である.それは,価格平均の交差原理を利用して,市場動向を簡単に,直観的に判断し,取引信号を生成する.パラメータを調整し,他の技術指標と組み合わせることで,この戦略の現場効果を強め,それを信頼性の高い量化利益のツールにすることができる.

ストラテジーソースコード
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © HPotter
//  Simple SMA strategy
//
// WARNING:
//      - For purpose educate only
//      - This script to change bars colors
//@version=4
strategy(title="Simple SMA Strategy Backtest", shorttitle="SMA Backtest", precision=6, overlay=true)
Resolution = input(title="Resolution", type=input.resolution, defval="D")
Source = input(title="Source", type=input.source, defval=close)
xSeries = security(syminfo.tickerid, Resolution, Source)
Length = input(title="Length", type=input.integer, defval=14, minval=2)
TriggerPrice = input(title="Trigger Price", type=input.source, defval=close)
TakeProfit = input(50, title="Take Profit", step=0.01)
StopLoss = input(20, title="Stop Loss", step=0.01)
UseTPSL = input(title="Use Take\Stop", type=input.bool, defval=false)
BarColors = input(title="Painting bars", type=input.bool, defval=true)
ShowLine = input(title="Show Line", type=input.bool, defval=true)
UseAlerts = input(title="Use Alerts", type=input.bool, defval=false)
reverse = input(title="Trade Reverse", type=input.bool, defval=false)
pos = 0
xSMA = sma(xSeries, Length)
pos := iff(TriggerPrice > xSMA, 1,
         iff(TriggerPrice < xSMA, -1, nz(pos[1], 0)))
nRes = ShowLine ? xSMA : na
alertcondition(UseAlerts == true and pos != pos[1] and pos == 1, title='Signal Buy', message='Strategy to change to BUY')
alertcondition(UseAlerts == true and pos != pos[1] and pos == -1, title='Signal Sell', message='Strategy to change to SELL')
alertcondition(UseAlerts == true and pos != pos[1] and pos == 0, title='FLAT', message='Strategy get out from position')
possig =iff(pos[1] != pos,
         iff(reverse and pos == 1, -1,
           iff(reverse and pos == -1, 1, pos)), 0)
if (possig == 1)
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)
    
if (UseTPSL)    
    strategy.close("Long", when = high > strategy.position_avg_price + TakeProfit, comment = "close buy take profit")
    strategy.close("Long", when = low < strategy.position_avg_price - StopLoss, comment = "close buy stop loss")
    strategy.close("Short", when = low < strategy.position_avg_price - TakeProfit, comment = "close buy take profit")
    strategy.close("Short", when = high > strategy.position_avg_price + StopLoss, comment = "close buy stop loss")
nColor = BarColors ? strategy.position_avg_price != 0  and pos == 1 ? color.green :strategy.position_avg_price != 0 and pos == -1 ? color.red : color.blue : na
barcolor(nColor)
plot(nRes, title='SMA', color=#00ffaa, linewidth=2, style=plot.style_line)