Firedrops

Fractional Differentiation

Description
This Pine Script indicator implements fractional differentiation, a mathematical operation that extends the concept of differentiation to non-integer orders. Fractional differentiation is particularly significant in financial analysis, as it enables analysts to uncover underlying patterns in price series that are not evident with traditional integer-order differentiation. The motivation behind fractional differencing lies in its ability to balance the trade-off between retaining data/feature memory and ensuring stationarity.

Significance
Fractional differentiation offers a nuanced view of market data, allowing for the adjustment of the differentiation order to balance between signal clarity and noise reduction. This is especially useful in financial markets, where the choice of differentiation order can highlight long-term trends or short-term price movements without completely smoothing out the valuable market noise.

Approximations Used
The implementation relies on the Gamma function for the computation of coefficients in the fractional differentiation formula. Given the complexity of the Gamma function, this script uses an approximation method based on the Lanczos approximation for the logarithm of the Gamma function, as detailed in "An Analysis Of The Lanczos Gamma Approximation" by Glendon Ralph Pugh (2004). This approximation strikes a balance between computational efficiency and accuracy, making it suitable for real-time market analysis in Pine Script.

Limitations
While this script opens new avenues for market analysis, it comes with inherent limitations:
- The approximation of the Gamma function, although accurate, is not exact. The precision of the fractional differentiation result may vary slightly, especially for higher-order differentiations.
- The script's performance is subject to Pine Script's execution environment, with a default loop limit set to 100 iterations for practicality. Users might need to adjust this limit based on their specific use case, balancing between computational load and the desired depth of historical data analysis.

Credits
This script makes use of the `MathSpecialFunctionsGamma` library, authored by Ricardo Santos. This library provides essential mathematical functions, including an approximation of the Gamma function, which is crucial for the fractional differentiation calculation.

I also extend my sincere gratitude to

Dr. Marcos López de Prado for his seminal work, Advances in Financial Machine Learning (2018). Dr. López de Prado's insights have significantly influenced our approach to developing sophisticated analytical tools.

Dr. Ernie Chan for his freely and generously sharing valuable insights via discourse on quantitative trading strategies through his talks and publications.
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 a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?