mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-13 08:08:05 +00:00
1.4 KiB
1.4 KiB
The Math Behind ALMA
Components of ALMA
ALMA is a single-formula moving average that incorporates elements of several advanced techniques:
- Gaussian distribution
- Weighted moving average
- Offset parameter
ALMA Formula
ALMA_t = \sum_{i=0}^{n-1} w_i \cdot P_{t-i}
Where:
ALMA_tis the ALMA value at timetnis the window size (number of periods)P_{t-i}is the price at timet-iw_iare the weights
Weight Calculation
The weights w_i are calculated using a Gaussian distribution function with an offset:
w_i = \exp\left(-\frac{(i - m)^2}{2s^2}\right)
Where:
iis the position of the price in the window (0 ton-1)mis the offset of the Gaussian distribution, calculated asm = \text{floor}(offset \cdot (n - 1))sis the standard deviation of the Gaussian distribution, calculated ass = \frac{n}{sigma}
Parameter Definitions
ALMA uses three main parameters:
- Window size (
n): Affects the overall reactivity of the indicator. - Offset: Influences the lag of the moving average. Lower values reduce lag but may increase noise.
- Sigma: Controls the smoothness of the indicator. Higher values increase smoothness but may increase lag.
Computational Process
For each new data point:
- Calculate the weights for the entire window.
- Apply these weights to the most recent
nprices. - Sum the weighted prices to produce the final ALMA value.