波動性フィルタ付き市場タイミング戦略

作者: リン・ハーンチャオチャン開催日:2024年1月15日12時27分47秒
タグ:

img

概要

この戦略は,過去変動に基づくフィルターを追加することで,強化された購入・保有戦略を実装する.フィルターは,変動が高い市場体制ではロングポジションを閉鎖し,変動が低いときロングポジションを再入力し,最大引き上げを減らす.

戦略の論理

  1. 過去100日間のSPYの過去変動を計算する
  2. 現在の変動が過去100日間の変動の95%以上である場合,その取引日のフィルタを外し,ロングポジションを閉じる.
  3. 波動が95パーセント以下である場合は,ロングポジションを入力します.

利点分析

フィルタなしで単純な買いと保持と比較して,この戦略は28年間のバックテスト期間 (7.95%対9.92%) で年収を向上させ,最大引き下げを大幅に減少させた (50.79%対31.57%).これは,変動フィルターを追加することで,リターンを向上させ,リスクを一定程度低下させることが示されています.

リスク分析

主なリスクは波動性計算方法の正確性とフィルターパラメータ調整から生じる.波動性計算が不正確であれば,フィルターは失敗する.フィルターパラメータが調節が悪い (保守的または攻撃的すぎる) なら,戦略のリターンに悪影響を及ぼす可能性があります.また,過去のパフォーマンスが将来の結果を保証するものではありません.

オプティマイゼーションの方向性

長期移動平均,ADX指数など,追加のフィルターとして他の確認指標を追加することを検討してください. パラメータチューニングも,異なるバックバック期間,フィルタリングしきい値などのテストのような重要なものです. 機動性予測モデルを構築し,最適化するために,機械学習と時間系列分析技術も使用できます.

概要

この戦略は,シンプルな変動フィルターを通じて,SPYのバイ&ホール戦略のリターンを大幅に改善し,最大引き上げを削減しました.これは市場体制の識別と資産配置の重要性を示しています.我々は変動モデルを最適化し,確認信号を追加することによってさらに精製することができます.


/*backtest
start: 2023-01-08 00:00:00
end: 2024-01-14 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/
// 
// @author Sunil Halai
//
// This script has been created to demonstrate the effectiveness of using market regime filters in your trading strategy, and how they can improve your returns and lower your drawdowns
//
// This strategy adds a simple filter (The historical volatility filter, which can be found on my trading profile) to a traditional buy and hold strategy of the index SPY. There are other filters
// that could also be added included a long term moving average / percentile rank filter / ADX filter etc, to improve the returns further.
//
// The filter added closes our long position during periods of volatility that exceed the 95th percentile (or in the top 5% of volatile days)
//
// Have included the back test results since 1993 which is 28 years of data at the time of writing,  Comparing  buy and hold of the SPY (S&P 500), to improved by and hold offered here.
//
// Traditional buy and hold:
//
// Return per year:     7.95   % (ex Dividends)
// Total return :       851.1  %
// Max drawdown:        50.79  %
//
// 'Modified' buy and hold (this script):
//
// Return per year:     9.92    % (ex Dividends)
// Total return:        1412.16 %
// Max drawdown:        31.57   %
//
// Feel free to use some of the market filters in my trading profile to improve and refine your strategies further, or make a copy and play around with the code yourself. This is just 
// a simple example for demo purposes.
//

//@version=4
strategy(title = "Simple way to beat the market [STRATEGY]", shorttitle = "Beat The Market [STRATEGY]", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, currency="USD", default_qty_value=100)


upperExtreme = input(title = "Upper percentile filter (Do not trade above this number)", type = input.integer, defval = 95)
lookbackPeriod = input(title = "Lookback period", type = input.integer, defval = 100)

annual = 365
per = timeframe.isintraday or timeframe.isdaily and timeframe.multiplier == 1 ? 1 : 7
hv = lookbackPeriod * stdev(log(close / close[1]), 10) * sqrt(annual / per)

filtered = hv >= percentile_nearest_rank(hv, 100, upperExtreme)

if(not(filtered))
    strategy.entry("LONG", strategy.long)
else
    strategy.close("LONG")

もっと