변동성 필터링 시장 타이밍 전략

저자:차오장, 날짜: 2024-01-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")

더 많은