OPEN-SOURCE SCRIPT

Bandwidth Volatility - Silverman Rule of thumb Estimator

Updated
Overview
This indicator calculates volatility using the Rule of Thumb bandwidth estimator and incorporating the standard deviations of returns to get historical volatility. There are two options: one for the original rule of thumb bandwidth estimator, and another for the modified rule of thumb estimator. This indicator comes with the bandwidth, which is shown with the color gradient columns, which are colored by a percentile of the bandwidth, and the moving average of the bandwidth, which is the dark shaded area.

The rule of thumb bandwidth estimator is a simple and quick method for estimating the bandwidth parameter in kernel density estimation (KSE) or kernel regression. It provides a rough approximation of the bandwidth without requiring extensive computation resources or fine-tuning. One common rule of thumb estimator is Silverman rule, which is given by
h = 1.06*σ*n^(-1/5)
where
  • h is the bandwidth
  • σ is the standard deviation of the data
  • n is the number of data points


This rule of thumb is based on assuming a Gaussian kernel and aims to strike a balance between over-smoothing and under-smoothing the data. It is simple to implement and usually provides reasonable bandwidth estimates for a wide range of datasets. However, it is important to note that this rule of thumb may not always have optimal results, especially for non-Gaussian or multimodal distributions. In such cases, a modified bandwidth selection, such as cross-validation or even applying a log transformation (if the data is right-skewed), may be preferable.

How it works:
This indicator computes the bandwidth volatility using returns, which are used in the standard deviation calculation. It then estimates the bandwidth based on either the Silverman rule of thumb or a modified version considering the interquartile range. The percentile ranks of the bandwidth estimate are then used to visualize the volatility levels, identify high and low volatility periods, and show them with colors.

Modified Rule of thumb Bandwidth:
The modified rule of thumb bandwidth formula combines elements of standard deviations and interquartile ranges, scaled by a multiplier of 0.9 and inversely with a number of periods. This modification aims to provide a more robust and adaptable bandwidth estimation method, particularly suitable for financial time series data with potentially skewed or heavy-tailed data.

Formula for Modified Rule of Thumb Bandwidth:
h = 0.9 * min(σ, (IQR/1.34))*n^(-1/5)
This modification introduces the use of the IQR divided by 1.34 as an alternative to the standard deviation. It aims to improve the estimation, mainly when the underlying distribution deviates from a perfect Gaussian distribution.

Analysis
  • Rule of thumb Bandwidth: Provides a broader perspective on volatility trends, smoothing out short-term fluctuations and focusing more on the overall shape of the density function.
  • Historical Volatility: Offers a more granular view of volatility, capturing day-to-day or intra-period fluctuations in asset prices and returns.


Modelling Requirements
  • Rule of thumb Bandwidth: Provides a broader perspective on volatility trends, smoothing out short-term fluctuations and focusing more on the overall shape of the density function.
  • Historical Volatility: Offers a more granular view of volatility, capturing day-to-day or intra-period fluctuations in asset prices and returns.


Pros of Bandwidth as a volatility measure
  • Robust to Data Distribution: Bandwidth volatility, especially when estimated using robust methods like Silverman's rule of thumb or its modifications, can be less sensitive to outliers and non-normal distributions compared to some other measures of volatility
  • Flexibility: It can be applied to a wide range of data types and can adapt to different underlying data distributions, making it versatile for various analytical tasks.


How can traders use this indicator?
In finance, volatility is thought to be a mean-reverting process. So when volatility is at an extreme low, it is expected that a volatility expansion happens, which comes with bigger movements in price, and when volatility is at an extreme high, it is expected for volatility to eventually decrease, leading to smaller price moves, and many traders view this as an area to take profit in.

In the context of this indicator, low volatility is thought of as having the green color, which indicates a low percentile value, and also being below the moving average. High volatility is thought of as having the yellow color and possibly being above the moving average, showing that you can eventually expect volatility to decrease.

Release Notes
Correct version
Release Notes
Fixed a bug
Release Notes
Renamed variables to be more clear
analysisbigmovecryptoeducationalkernelkernelestimationstandarddevationstatisticsStocksVolatilityvolatilityindicator

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


Also on:

Disclaimer