Statistical Volatility Backtest Strategy Based on Extreme Value Method
Overview
This strategy uses the extreme value method to calculate the statistical volatility, also known as historical volatility. It measures the volatility based on the extreme values of highest price, lowest price and close price, combined with the time factor. The volatility reflects the fluctuation of the asset price. The strategy will make corresponding long or short trades when the volatility is higher or lower than the threshold.
Strategy Principle
- Calculate the extreme values of highest price, lowest price and close price in a certain time period
- Apply the extreme value method formula to calculate the statistical volatilitySqrTime = sqrt(253 / Length) Vol = ((0.6 * log(xMaxC / xMinC) * SqrTime) + (0.6 * log(xMaxH / xMinL) * SqrTime)) * 0.5
- Compare the volatility with the upper and lower thresholds to generate trading signalspos = iff(nRes > TopBand, 1, iff(nRes < LowBand, -1, nz(pos[1], 0)))
- Make long or short trades based on the trading signals
Advantage Analysis
The main advantages of this strategy are:
- Using the statistical volatility indicator can effectively capture market hotspots and reversal opportunities
- The extreme value method for calculating volatility is not sensitive to extreme prices, resulting in more stable and reliable results
- Parameters can be adjusted to adapt to trading in different volatility environments
Risk Analysis
The main risks of this strategy are:
- The statistical volatility itself has some lag, and cannot accurately grasp market turning points
- The volatility indicator reacts slowly to sudden events, possibly missing short-term trading opportunities
- There are some risks of wrong trades and stop loss
Countermeasures and solutions:
- Appropriately shorten the statistical cycle to increase sensitivity to market changes
- Use other indicators as an aid to improve signal accuracy
- Set stop loss points to control single loss
Optimization Directions
The optimization directions for this strategy:
- Test different statistical period parameters to find the optimal parameters
- Add a position management module to adjust positions based on volatility
- Add filter conditions like moving average lines to reduce wrong trades
Summary
This strategy uses the extreme value method to calculate statistical volatility, and generates trading signals by capturing volatility anomalies. Compared to simple indicators like moving average lines, it better reflects market volatility and captures reversals. Meanwhile, the extreme value method algorithm also makes the results more stable and reliable. Through parameter adjustment and optimization, this strategy can adapt to different market conditions, and its trading logic and statistical volatility indicator are worth further research and application.
/*backtest
start: 2022-12-19 00:00:00
end: 2023-12-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 22/11/2014
// This indicator used to calculate the statistical volatility, sometime - 1

