Merge branch 'dev'

This commit is contained in:
Miha Kralj
2026-03-13 13:47:10 -07:00
404 changed files with 2754 additions and 1763 deletions
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [acf.pine](acf.pine) |
- The Autocorrelation Function (ACF) measures the correlation of a time series with a lagged copy of itself.
- Parameterized by `period`, `lag` (default 1).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [PACF](../pacf/Pacf.md), [Correlation](../correlation/Correlation.md) | **Trading note:** Autocorrelation function; detects mean-reversion (negative ACF) vs momentum (positive ACF) in returns.
- Validated against mathematical properties and theoretical AR-process expectations.
The Autocorrelation Function (ACF) measures the correlation of a time series with a lagged copy of itself. It is fundamental for identifying repeating patterns, seasonal effects, and determining the order of time series models like ARMA/ARIMA.
@@ -175,4 +173,4 @@ A random walk should have ACF ≈ 0 at all lags. Significant ACF values indicate
- Box, G.E.P., Jenkins, G.M. (1970). *Time Series Analysis: Forecasting and Control*. Holden-Day.
- Hamilton, J.D. (1994). *Time Series Analysis*. Princeton University Press.
- Yule, G.U. (1927). "On a Method of Investigating Periodicities in Disturbed Series." *Philosophical Transactions of the Royal Society*.
- Yule, G.U. (1927). "On a Method of Investigating Periodicities in Disturbed Series." *Philosophical Transactions of the Royal Society*.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [beta.pine](beta.pine) |
- Beta measures the volatility of an asset in relation to the overall market.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period + 1` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Correlation](../correlation/Correlation.md), [Covariance](../covariance/Covariance.md) | **Trading note:** Beta coefficient; measures systematic risk vs benchmark. β>1 = amplifies market moves.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Beta measures the volatility of an asset in relation to the overall market. It's the slope of the regression line between the asset's returns and the market's returns. A beta of 1.0 means the asset moves in lockstep with the market. A beta of 2.0 means the asset is twice as volatile as the market.
@@ -109,4 +107,4 @@ var beta = new Beta(20);
// (e.g., AAPL price and SPY price)
TValue result = beta.Update(assetPrice, marketPrice);
Console.WriteLine($"Beta: {result.Value:F4}");
Console.WriteLine($"Beta: {result.Value:F4}");
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [cma.pine](cma.pine) |
- The Cumulative Moving Average (CMA) calculates the arithmetic mean of ALL data points seen so far, not just a fixed window.
- Parameterized by `source`.
- Output range: Varies (see docs).
- Requires `1` bars of warmup before first valid output (IsHot = true).
- **Similar:** [SMA](../../trends_FIR/sma/Sma.md), [EMA](../../trends_IIR/ema/ema.md) | **Trading note:** Cumulative Moving Average; running mean of all data points. Anchored VWAP without volume weighting.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Cumulative Moving Average (CMA) calculates the arithmetic mean of ALL data points seen so far, not just a fixed window. Unlike SMA or EMA which use a sliding window, CMA treats every historical value with equal weight. As the sample size grows, each new value has diminishing impact on the average.
@@ -124,4 +122,4 @@ CMA is a fundamental statistical operation rather than a standard TA library ind
1. **Responsiveness**: CMA becomes nearly unresponsive after many values. For a reactive average, use SMA or EMA instead.
2. **Memory of Bad Data**: A single extreme outlier early in the stream permanently affects the average. Consider filtering before feeding CMA.
3. **No Period Parameter**: Unlike SMA/EMA, CMA has no period. It always includes all data. This is by design.
4. **Session Resets**: If you need per-session averages, call `Reset()` at session boundaries.
4. **Session Resets**: If you need per-session averages, call `Reset()` at session boundaries.
@@ -13,9 +13,7 @@
| **PineScript** | [cointegration.pine](cointegration.pine) |
- The Cointegration indicator measures the long-run equilibrium relationship between two price series using the Engle-Granger two-step method with an...
- Parameterized by `period` (default 20).
- Output range: Varies (see docs).
- Requires `period + 1` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Correlation](../correlation/Correlation.md), [Granger](../granger/Granger.md) | **Trading note:** Tests if two series share a long-run equilibrium. Foundation of statistical arbitrage (pairs trading).
- Validated against TradingView PineScript reference and statistical property tests.
The Cointegration indicator measures the long-run equilibrium relationship between two price series using the Engle-Granger two-step method with an Augmented Dickey-Fuller (ADF) test. Unlike correlation, which measures short-term co-movement, cointegration tests whether two non-stationary series share a common stochastic trend—meaning they may diverge temporarily but are statistically bound to revert to their equilibrium relationship.
@@ -286,4 +284,4 @@ coint.Update(101.0, 51.0, isNew: false); // Recalculates without advancing state
- Engle, R.F. and Granger, C.W.J. (1987). "Co-integration and Error Correction: Representation, Estimation, and Testing." *Econometrica*, 55(2), 251-276.
- Dickey, D.A. and Fuller, W.A. (1979). "Distribution of the Estimators for Autoregressive Time Series with a Unit Root." *Journal of the American Statistical Association*, 74(366), 427-431.
- TradingView. "Cointegration Indicator (PineScript)." *TradingView Community Scripts*.
- Vidyamurthy, G. (2004). "Pairs Trading: Quantitative Methods and Analysis." *Wiley Finance*.
- Vidyamurthy, G. (2004). "Pairs Trading: Quantitative Methods and Analysis." *Wiley Finance*.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [correlation.pine](correlation.pine) |
- The Pearson Correlation Coefficient measures the linear relationship between two variables, returning a value from -1 (perfect negative correlation...
- Parameterized by `period` (default 20).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Spearman](../spearman/Spearman.md), [Kendall](../kendall/Kendall.md) | **Trading note:** Pearson correlation; measures linear relationship strength. Used for portfolio diversification and pairs trading.
- Validated against TradingView reference behavior and mathematical invariants.
The Pearson Correlation Coefficient measures the linear relationship between two variables, returning a value from -1 (perfect negative correlation) to +1 (perfect positive correlation). Zero indicates no linear relationship. This implementation uses running sums for O(1) streaming updates, making it suitable for real-time analysis of price relationships.
@@ -281,4 +279,4 @@ corr.Update(101.0, 51.0, isNew: false); // Recalculates without advancing state
- Pearson, K. (1895). "Notes on regression and inheritance in the case of two parents." *Proceedings of the Royal Society of London*, 58, 240-242.
- TradingView. "ta.correlation() function." *Pine Script Language Reference Manual*.
- Vidyamurthy, G. (2004). "Pairs Trading: Quantitative Methods and Analysis." *Wiley Finance*. Chapter on correlation analysis.
- Embrechts, P., McNeil, A., & Straumann, D. (2002). "Correlation and dependence in risk management: properties and pitfalls." *Risk Management: Value at Risk and Beyond*, Cambridge University Press.
- Embrechts, P., McNeil, A., & Straumann, D. (2002). "Correlation and dependence in risk management: properties and pitfalls." *Risk Management: Value at Risk and Beyond*, Cambridge University Press.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [covariance.pine](covariance.pine) |
- Covariance measures the joint variability of two random variables.
- Parameterized by `period`, `ispopulation` (default false).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Correlation](../correlation/Correlation.md), [Beta](../beta/Beta.md) | **Trading note:** Rolling covariance; measures how two assets move together. Foundation of portfolio theory.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Covariance measures the joint variability of two random variables. It indicates the direction of the linear relationship between variables.
@@ -84,4 +82,4 @@ var cov = new Covariance(20);
cov.Update(price1, price2);
// Access the result
double result = cov.Last.Value;
double result = cov.Last.Value;
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [entropy.pine](entropy.pine) |
- Shannon Entropy measures the unpredictability or randomness of a time series over a sliding window.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Hurst](../hurst/Hurst.md), [StdDev](../stddev/StdDev.md) | **Trading note:** Shannon entropy; measures information content and randomness. High entropy = unpredictable market.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Shannon Entropy measures the unpredictability or randomness of a time series over a sliding window. A low entropy value indicates the series is highly predictable (clustered values), while a high entropy value indicates the data is spread uniformly across its range — maximum randomness.
@@ -108,4 +106,4 @@ var series = Entropy.Batch(source, period: 14);
// Span mode
Entropy.Batch(inputSpan, outputSpan, period: 14);
```
```
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [geomean.pine](geomean.pine) |
- The Geometric Mean computes the nth root of the product of n positive values over a sliding window.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Harmean](../harmean/Harmean.md), [CMA](../cma/Cma.md) | **Trading note:** Geometric mean; proper average for returns/growth rates. Accounts for compounding.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Geometric Mean computes the nth root of the product of n positive values over a sliding window. Unlike the arithmetic mean, it captures multiplicative relationships and is the correct average for growth rates, ratios, and log-normally distributed data. For financial time series, this means it properly accounts for compounding.
@@ -151,4 +149,4 @@ Geomean.Batch(inputSpan, outputSpan, period: 14);
- Euclid, *Elements*, Book VI, Proposition 13 (ca. 300 BCE).
- Cauchy, A.-L. "Cours d'analyse de l'Ecole royale polytechnique" (1821). First rigorous proof of AM-GM.
- Kahan, W. "Pracniques: Further Remarks on Reducing Truncation Errors" (1965).
- PineScript `ta.geomean()` reference implementation.
- PineScript `ta.geomean()` reference implementation.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [granger.pine](granger.pine) |
- The Granger Causality test asks a precise, falsifiable question: does knowing the history of series X improve your ability to predict series Y, bey...
- Parameterized by `period` (default 20).
- Output range: Varies (see docs).
- Requires `period + 1` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Cointegration](../cointegration/Cointegration.md), [Correlation](../correlation/Correlation.md) | **Trading note:** Granger causality test; determines if one time series can forecast another. Lead-lag detection.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
## Introduction
@@ -145,4 +143,4 @@ This indicator validates against statistical properties rather than external TA
- Granger, C.W.J. (1969). "Investigating Causal Relations by Econometric Models and Cross-spectral Methods." Econometrica, 37(3), 424-438.
- Granger, C.W.J. (1980). "Testing for Causality: A Personal Viewpoint." Journal of Economic Dynamics and Control, 2, 329-352.
- Hamilton, J.D. (1994). Time Series Analysis. Princeton University Press. Chapter 11.
- Sims, C.A. (1972). "Money, Income, and Causality." American Economic Review, 62(4), 540-552.
- Sims, C.A. (1972). "Money, Income, and Causality." American Economic Review, 62(4), 540-552.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [harmean.pine](harmean.pine) |
- The Harmonic Mean computes the reciprocal of the arithmetic mean of reciprocals over a sliding window.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Geomean](../geomean/Geomean.md), [CMA](../cma/Cma.md) | **Trading note:** Harmonic mean; appropriate for averaging rates/ratios. Always ≤ geometric mean ≤ arithmetic mean.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Harmonic Mean computes the reciprocal of the arithmetic mean of reciprocals over a sliding window. It is the correct average for quantities defined in terms of rates or ratios (speed, P/E ratios, yield). For financial time series, the harmonic mean gives the largest discount to outliers, making it the most conservative of the three Pythagorean means.
@@ -128,4 +126,4 @@ Self-validated against mathematical properties and Wolfram Alpha known values.
- Bullen, P.S. "Handbook of Means and Their Inequalities." Kluwer Academic Publishers, 2003.
- Ferger, W.F. "The Nature and Use of the Harmonic Mean." Journal of the American Statistical Association, 1931.
- PineScript reference: `lib/statistics/harmean/harmean.pine`
- PineScript reference: `lib/statistics/harmean/harmean.pine`
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [hurst.pine](hurst.pine) |
- The Hurst Exponent ($H$) quantifies long-range dependence in a time series through Rescaled Range (R/S) analysis.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period + 1` bars of warmup before first valid output (IsHot = true).
- **Similar:** [ACF](../acf/Acf.md), [Entropy](../entropy/Entropy.md) | **Trading note:** Hurst exponent; H>0.5 = trending (persistent), H<0.5 = mean-reverting, H=0.5 = random walk.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
## Introduction
@@ -188,4 +186,4 @@ No external library provides a direct R/S-based Hurst exponent for cross-validat
- Mandelbrot, B.B. and Wallis, J.R. (1969). "Robustness of the rescaled range R/S in the measurement of noncyclic long run statistical dependence." *Water Resources Research*, 5(5), 967-988.
- Peters, E.E. (1994). *Fractal Market Analysis*. Wiley.
- Anis, A.A. and Lloyd, E.H. (1976). "The expected value of the adjusted rescaled Hurst range of independent normal summands." *Biometrika*, 63(1), 111-116.
- Lo, A.W. (1991). "Long-term memory in stock market prices." *Econometrica*, 59(5), 1279-1313.
- Lo, A.W. (1991). "Long-term memory in stock market prices." *Econometrica*, 59(5), 1279-1313.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [iqr.pine](iqr.pine) |
- The Interquartile Range measures the spread of the middle 50% of a sorted dataset within a rolling window.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [StdDev](../stddev/StdDev.md), [Percentile](../percentile/Percentile.md) | **Trading note:** Interquartile Range; robust dispersion measure (Q3Q1). Identifies outlier moves.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
## Introduction
@@ -167,4 +165,4 @@ No external library implements a streaming rolling IQR with linear interpolation
- Tukey, J.W. (1977). *Exploratory Data Analysis*. Addison-Wesley.
- Galton, F. (1885). "Statistics by Intercomparison." *Philosophical Magazine*.
- Frigge, M., Hoaglin, D.C., Iglewicz, B. (1989). "Some Implementations of the Boxplot." *The American Statistician*, 43(1), 50-54.
- Frigge, M., Hoaglin, D.C., Iglewicz, B. (1989). "Some Implementations of the Boxplot." *The American Statistician*, 43(1), 50-54.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [jb.pine](jb.pine) |
- The Jarque-Bera test quantifies departure from normality by combining skewness and excess kurtosis into a single chi-squared statistic.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Kurtosis](../kurtosis/Kurtosis.md), [Skew](../skew/Skew.md) | **Trading note:** Jarque-Bera test; tests if returns are normally distributed. Significant = fat tails present.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Jarque-Bera test quantifies departure from normality by combining skewness and excess kurtosis into a single chi-squared statistic. A rolling JB value near zero means the window looks Gaussian. Values exceeding 5.991 (5% significance) reject normality. Financial returns almost always fail this test, which is precisely why the test matters.
@@ -148,4 +146,4 @@ Self-validation:
- Jarque, C. M.; Bera, A. K. (1980). "Efficient tests for normality, homoscedasticity and serial independence of regression residuals." *Economics Letters*, 6(3), 255-259.
- Bowman, K. O.; Shenton, L. R. (1975). "Omnibus test contours for departures from normality based on √b₁ and b₂." *Biometrika*, 62(2), 243-250.
- PineScript reference: `lib/statistics/jb/jb.pine`
- PineScript reference: `lib/statistics/jb/jb.pine`
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [kurtosis.pine](kurtosis.pine) |
- Kurtosis measures the **tailedness** of a probability distribution.
- Parameterized by `period`, `ispopulation` (default false).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Skew](../skew/Skew.md), [JB](../jb/Jb.md) | **Trading note:** Excess kurtosis; >0 = fat tails (leptokurtic), <0 = thin tails. Measures tail risk in returns.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
## Introduction
@@ -143,4 +141,4 @@ O(1) per update using 4th-moment running sums. Numerically sensitive — periodi
- Pearson, K. (1905). "Das Fehlergesetz und seine Verallgemeinerungen durch Fechner und Pearson." *Biometrika*, 4(1-2), 169-212.
- Mandelbrot, B. (1963). "The Variation of Certain Speculative Prices." *The Journal of Business*, 36(4), 394-419.
- Joanes, D. N., & Gill, C. A. (1998). "Comparing measures of sample skewness and kurtosis." *Journal of the Royal Statistical Society: Series D*, 47(1), 183-189.
- DeCarlo, L. T. (1997). "On the meaning and use of kurtosis." *Psychological Methods*, 2(3), 292-307.
- DeCarlo, L. T. (1997). "On the meaning and use of kurtosis." *Psychological Methods*, 2(3), 292-307.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [linreg.pine](linreg.pine) |
- The Linear Regression Curve plots the end point of the linear regression line for each bar.
- Parameterized by `period`, `offset` (default 0).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Polyfit](../polyfit/Polyfit.md), [TSF](../../trends_FIR/tsf/Tsf.md) | **Trading note:** Linear regression; slope = trend direction/speed, R² = trend strength. Foundation of many indicators.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Linear Regression Curve plots the end point of the linear regression line for each bar. It fits a straight line $y = mx + b$ to the data points using the least squares method, providing a smoothed representation of the price trend that is more responsive than a Simple Moving Average (SMA).
@@ -118,4 +116,4 @@ linreg.Update(new TValue(DateTime.UtcNow, 100.0));
// Access result
double value = linreg.Last.Value;
double slope = linreg.Slope;
double r2 = linreg.RSquared;
double r2 = linreg.RSquared;
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [meandev.pine](meandev.pine) |
- ````markdown
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [StdDev](../stddev/StdDev.md), [IQR](../iqr/Iqr.md) | **Trading note:** Mean deviation (average absolute deviation); more robust than StdDev. Used in CCI calculation.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Mean Deviation (also known as Mean Absolute Deviation or Average Absolute Deviation) measures the average of the absolute deviations from the mean. Unlike Standard Deviation, it does not square the deviations, making it more robust to outliers and more intuitive to interpret.
@@ -105,4 +103,4 @@ double value = meanDev.Last.Value;
* **StdDev** — Standard Deviation (quadratic weighting of deviations).
* **Variance** — Variance (squared deviations from mean).
* **Cci** — Commodity Channel Index (uses Mean Deviation as a normalizer).
````
````
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [median.pine](median.pine) |
- The Rolling Median is a robust statistic that represents the middle value of a dataset within a moving window.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Mode](../mode/Mode.md), [Percentile](../percentile/Percentile.md) | **Trading note:** Rolling median; robust central tendency resistant to outliers. Good for support/resistance identification.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Rolling Median is a robust statistic that represents the middle value of a dataset within a moving window. Unlike the Simple Moving Average (SMA), which can be skewed by extreme values, the Median provides a more stable measure of central tendency, making it particularly useful for filtering noise in volatile markets.
@@ -82,4 +80,4 @@ O(N) per update. For large N, a dual-heap (min-heap + max-heap) O(log N) structu
### Common Pitfalls
* **Quantization**: The median moves in discrete steps (jumps from one value to another) rather than smoothly like an average.
* **Flatlining**: In periods of low volatility, the median can remain constant for many bars, which may be interpreted as a lack of trend.
* **Flatlining**: In periods of low volatility, the median can remain constant for many bars, which may be interpreted as a lack of trend.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [mode.pine](mode.pine) |
- The **Mode** is a rolling statistical indicator that identifies the most frequently occurring value within a sliding window of recent observations.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Median](../median/Median.md), [Percentile](../percentile/Percentile.md) | **Trading note:** Statistical mode; most frequent value in window. Identifies price levels with highest activity (value area).
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
## Introduction
@@ -152,4 +150,4 @@ Verified against Wolfram Alpha for static datasets.
## References
- PineScript reference: `mode.pine` (exact value comparison, map-based counting)
- Wolfram MathWorld: [Statistical Mode](https://mathworld.wolfram.com/Mode.html)
- Wolfram MathWorld: [Statistical Mode](https://mathworld.wolfram.com/Mode.html)
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [pacf.pine](pacf.pine) |
- The Partial Autocorrelation Function (PACF) measures the correlation between a time series and its lagged values, after removing the effects of all...
- Parameterized by `period`, `lag` (default 1).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [ACF](../acf/Acf.md), [LinReg](../linreg/LinReg.md) | **Trading note:** Partial autocorrelation; isolates direct lag relationships. Used for ARIMA model order selection.
- Validated against mathematical properties and Durbin-Levinson recursion expectations.
The Partial Autocorrelation Function (PACF) measures the correlation between a time series and its lagged values, after removing the effects of all intermediate lags. While ACF shows total correlation at each lag, PACF isolates the direct correlation, making it essential for AR model identification.
@@ -210,4 +208,4 @@ PACF is used in linear prediction and filter design, where the partial correlati
- Box, G.E.P., Jenkins, G.M. (1970). *Time Series Analysis: Forecasting and Control*. Holden-Day.
- Durbin, J. (1960). "The fitting of time series models." *Review of the International Statistical Institute*, 28, 233-243.
- Levinson, N. (1946). "The Wiener RMS error criterion in filter design and prediction." *Journal of Mathematics and Physics*, 25, 261-278.
- Hamilton, J.D. (1994). *Time Series Analysis*. Princeton University Press.
- Hamilton, J.D. (1994). *Time Series Analysis*. Princeton University Press.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [percentile.pine](percentile.pine) |
- The Rolling Percentile computes the value below which a given percentage of observations fall within a sliding window.
- Parameterized by `period`, `percent` (default 50.0).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Quantile](../quantile/Quantile.md), [Median](../median/Median.md) | **Trading note:** Percentile rank of current value; 90th+ = historically elevated, 10th = historically depressed.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
> But percentiles, at least, tell you exactly where you stand.
@@ -137,4 +135,4 @@ O(N) per update due to sorted-array shift. A skip-list or order-statistics tree
- Hyndman, R.J. and Fan, Y. (1996). "Sample Quantiles in Statistical Packages." _The American Statistician_, 50(4), 361-365.
- Galton, F. (1885). "Some Results of the Anthropometric Laboratory." _Journal of the Anthropological Institute_, 14, 275-287.
- Microsoft Excel Documentation: [PERCENTILE.INC function](https://support.microsoft.com/en-us/office/percentile-inc-function-680f9539-45eb-410b-9a5e-c1355e5fe2ed)
- TradingView PineScript Reference: [ta.percentile_linear_interpolation](https://www.tradingview.com/pine-script-reference/v6/)
- TradingView PineScript Reference: [ta.percentile_linear_interpolation](https://www.tradingview.com/pine-script-reference/v6/)
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [polyfit.pine](polyfit.pine) |
- Polynomial Fitting computes a rolling polynomial regression of configurable degree over a lookback window, returning the fitted value at the curren...
- Parameterized by `period`, `degree` (default 2).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [LinReg](../linreg/LinReg.md), [TSF](../../trends_FIR/tsf/Tsf.md) | **Trading note:** Polynomial curve fitting; captures non-linear trends. Higher order = more responsive but risk of overfitting.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Polynomial Fitting computes a rolling polynomial regression of configurable degree over a lookback window, returning the fitted value at the current bar. Degree 1 produces a linear regression endpoint (identical to LSQR), degree 2 produces a quadratic fit that captures curvature, and degree 3 produces a cubic fit that captures inflection points. The implementation solves the normal equations $\mathbf{X}^T\mathbf{X}\mathbf{a} = \mathbf{X}^T\mathbf{y}$ via Gauss-Jordan elimination with partial pivoting, evaluating the resulting polynomial at $x = 1$ (the current bar position). With $O(Nd + d^3)$ complexity per bar where $N$ is the period and $d$ is the degree, POLYFIT provides a general-purpose curve-fitting tool that subsumes linear regression and extends it to arbitrary polynomial order.
@@ -134,4 +132,4 @@ Batch span path can vectorize sum accumulation and output projection. Inner loop
- Gauss, C.F. "Theoria Motus Corporum Coelestium." 1809.
- Golub, G. & Van Loan, C. "Matrix Computations." 4th edition, Johns Hopkins University Press, 2013.
- Press, W.H. et al. "Numerical Recipes: The Art of Scientific Computing." 3rd edition, Cambridge University Press, 2007. Chapter 15 (Modeling of Data).
- Draper, N. & Smith, H. "Applied Regression Analysis." 3rd edition, Wiley, 1998.
- Draper, N. & Smith, H. "Applied Regression Analysis." 3rd edition, Wiley, 1998.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [quantile.pine](quantile.pine) |
- The Rolling Quantile computes the value below which a given fraction of observations fall within a sliding window.
- Parameterized by `period`, `quantilelevel` (default 0.25).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Percentile](../percentile/Percentile.md), [IQR](../iqr/Iqr.md) | **Trading note:** Value at specified quantile; Q(0.5) = median, Q(0.95) = 95th percentile for risk analysis.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
## Introduction
@@ -140,4 +138,4 @@ O(N) per update. Linear interpolation between adjacent order statistics matches
- Hyndman, R.J. and Fan, Y. (1996). "Sample Quantiles in Statistical Packages." *The American Statistician*, 50(4), 361-365.
- Galton, F. (1885). "Some Results of the Anthropometric Laboratory." *Journal of the Anthropological Institute*, 14, 275-287.
- Microsoft Excel Documentation: [PERCENTILE.INC function](https://support.microsoft.com/en-us/office/percentile-inc-function-680f9539-45eb-410b-9a5e-c1355e5fe2ed)
- TradingView PineScript Reference: [ta.percentile_linear_interpolation](https://www.tradingview.com/pine-script-reference/v6/)
- TradingView PineScript Reference: [ta.percentile_linear_interpolation](https://www.tradingview.com/pine-script-reference/v6/)
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [skew.pine](skew.pine) |
- Skewness measures the asymmetry of the probability distribution of a real-valued random variable about its mean.
- Parameterized by `period`, `ispopulation` (default false).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Kurtosis](../kurtosis/Kurtosis.md), [JB](../jb/Jb.md) | **Trading note:** Skewness; positive = right tail, negative = left tail. Negative skew in equity returns = crash risk.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Skewness measures the asymmetry of the probability distribution of a real-valued random variable about its mean. It tells you where the "tail" of the distribution is.
@@ -104,4 +102,4 @@ var result = skew.Update(new TValue(DateTime.UtcNow, 105.5));
// Result > 0: Positive skew (tail on right)
// Result < 0: Negative skew (tail on left)
// Result = 0: Symmetric
Console.WriteLine($"Skewness: {result.Value:F4}");
Console.WriteLine($"Skewness: {result.Value:F4}");
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [spearman.pine](spearman.pine) |
- Spearman's ρ (rho) measures the strength and direction of monotonic association between two variables.
- Parameterized by `period` (default 20).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Correlation](../correlation/Correlation.md), [Kendall](../kendall/Kendall.md) | **Trading note:** Spearman rank correlation; non-parametric, detects monotonic (not just linear) relationships.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Spearman's ρ (rho) measures the strength and direction of monotonic association between two variables. Unlike Pearson's correlation, which measures linear relationship, Spearman captures any monotonic relationship. A portfolio of stocks whose returns move monotonically together has different risk than one whose components merely share a linear trend. Spearman detects both.
@@ -165,4 +163,4 @@ No external TA library implements Spearman rank correlation. Validation relies o
- Spearman, C. (1904). "The Proof and Measurement of Association between Two Things." *American Journal of Psychology*, 15(1), 72-101.
- Kendall, M. G., & Gibbons, J. D. (1990). *Rank Correlation Methods*. 5th ed. Oxford University Press.
- Croux, C., & Dehon, C. (2010). "Influence Functions of the Spearman and Kendall Correlation Measures." *Statistical Methods & Applications*, 19(4), 497-515.
- Embrechts, P., McNeil, A., & Straumann, D. (2002). "Correlation and Dependence in Risk Management: Properties and Pitfalls." In *Risk Management: Value at Risk and Beyond*, Cambridge University Press.
- Embrechts, P., McNeil, A., & Straumann, D. (2002). "Correlation and Dependence in Risk Management: Properties and Pitfalls." In *Risk Management: Value at Risk and Beyond*, Cambridge University Press.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [stddev.pine](stddev.pine) |
- Standard Deviation measures the amount of variation or dispersion of a set of values.
- Parameterized by `period`, `ispopulation` (default false).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Variance](../variance/Variance.md), [MeanDev](../meandev/MeanDev.md) | **Trading note:** Standard deviation; foundational volatility measure. Used in Bollinger Bands, VaR, and Sharpe ratio.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Standard Deviation measures the amount of variation or dispersion of a set of values. A low standard deviation indicates that the values tend to be close to the mean (also called the expected value) of the set, while a high standard deviation indicates that the values are spread out over a wider range.
@@ -96,4 +94,4 @@ var stdDev = new StdDev(20, isPopulation: false);
var result = stdDev.Update(new TValue(DateTime.UtcNow, 100.0));
// Get the last value
double value = stdDev.Last.Value;
double value = stdDev.Last.Value;
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [stderr.pine](stderr.pine) |
- `Stderr` computes the standard error of an OLS regression fit over a rolling window.
- Parameterized by `period`.
- Output range: non-negative real values (or 0 during insufficient/degenerate windows).
- Requires `period` bars of warmup before first stable output (`IsHot = true`).
- **Similar:** [StdDev](../stddev/StdDev.md), [LinReg](../linreg/LinReg.md) | **Trading note:** Standard error; precision of the mean estimate. Decreases with sample size.
- Validated against an internal brute-force OLS reference implementation.
Standard Error of Regression (also called the Standard Error of the Estimate) measures the average distance that the observed values fall from the regression line. It quantifies the typical size of the residuals, providing a direct measure of how well a linear regression model fits the data.
@@ -101,4 +99,4 @@ double value = stderr.Last.Value;
## See Also
* **LinReg** — Linear Regression Curve (the trend line itself).
- **StdDev** — Standard Deviation (dispersion from the mean, not from a regression line).
- **StdDev** — Standard Deviation (dispersion from the mean, not from a regression line).
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [sum.pine](sum.pine) |
- The Sum indicator calculates a rolling window summation using the Kahan-Babuška algorithm (also known as "improved Kahan" or "second-order compensa...
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Trading note:** Rolling sum; cumulative total over lookback window. Building block for many indicators (e.g., OBV, A/D).
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Sum indicator calculates a rolling window summation using the Kahan-Babuška algorithm (also known as "improved Kahan" or "second-order compensated summation") for maximum numerical precision. This approach captures rounding errors that even classic Kahan summation misses, making it suitable for numerical libraries, statistics, and trading applications where precision matters.
@@ -206,4 +204,4 @@ source.Add(new TValue(DateTime.UtcNow, 100.0));
* Values are similar magnitude
* Sequence length is bounded and small
* Maximum throughput is critical
* Using `decimal` type instead
* Using `decimal` type instead
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [theil.pine](theil.pine) |
- The Theil T Index is an information-theoretic measure of inequality (or concentration) within a distribution of positive values.
- Parameterized by `period`.
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Correlation](../correlation/Correlation.md), [LinReg](../linreg/LinReg.md) | **Trading note:** TheilSen estimator; robust slope calculation using medians of pairwise slopes. Resistant to outliers.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
## Introduction
@@ -150,4 +148,4 @@ No external TA library implements Theil T Index directly. Validation relies on m
- Theil, H. (1967). *Economics and Information Theory*. North-Holland Publishing Company.
- Cowell, F.A. (2011). *Measuring Inequality*. Oxford University Press. 3rd edition.
- Conceicao, P., & Ferreira, P. (2000). "The Young Person's Guide to the Theil Index." UTIP Working Paper No. 14.
- Shorrocks, A.F. (1980). "The Class of Additively Decomposable Inequality Measures." *Econometrica*, 48(3), 613-625.
- Shorrocks, A.F. (1980). "The Class of Additively Decomposable Inequality Measures." *Econometrica*, 48(3), 613-625.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [trim.pine](trim.pine) |
- The Trimmed Mean Moving Average computes a rolling average after discarding a configurable percentage of the most extreme values from each tail of ...
- Parameterized by `period`, `trimpct` (default 10.0).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Wins](../wins/Wins.md), [Median](../median/Median.md) | **Trading note:** Trimmed mean; excludes extreme percentiles. Robust average for volatile data.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Trimmed Mean Moving Average computes a rolling average after discarding a configurable percentage of the most extreme values from each tail of the sorted lookback window. By removing the lowest and highest `trimPct%` of observations, TRIM eliminates the influence of outliers while retaining more information than a pure median. At `trimPct = 0` it degenerates to the SMA; at `trimPct = 50` it becomes the median. The default 10% trim provides a robust central tendency estimator that resists spike contamination with minimal loss of responsiveness, requiring $O(N \log N)$ for the sort plus $O(N)$ for the summation per bar.
@@ -127,4 +125,4 @@ No whole-path SIMD; sort blocks vectorization. Batch is a loop of independent so
- Tukey, J.W. "Exploratory Data Analysis." Addison-Wesley, 1977.
- Huber, P.J. & Ronchetti, E. "Robust Statistics." 2nd edition, Wiley, 2009.
- Wilcox, R.R. "Fundamentals of Modern Statistical Methods." 2nd edition, Springer, 2010.
- Bryan, M. & Cecchetti, S. "Measuring Core Inflation." In Monetary Policy, NBER, 1994.
- Bryan, M. & Cecchetti, S. "Measuring Core Inflation." In Monetary Policy, NBER, 1994.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [variance.pine](variance.pine) |
- Variance measures how far a set of numbers is spread out from their average value.
- Parameterized by `period`, `ispopulation` (default false).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [StdDev](../stddev/StdDev.md), [MeanDev](../meandev/MeanDev.md) | **Trading note:** Rolling variance; squared deviation from mean. Foundation of portfolio risk calculations.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
Variance measures how far a set of numbers is spread out from their average value. In finance, it is a key measure of volatility and risk.
@@ -108,4 +106,4 @@ var variance = new Variance(20, isPopulation: false);
var result = variance.Update(new TValue(DateTime.UtcNow, 100.0));
// Access the last calculated value
Console.WriteLine($"Variance: {variance.Last.Value}");
Console.WriteLine($"Variance: {variance.Last.Value}");
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [wavg.pine](wavg.pine) |
- The Weighted Average computes a rolling linearly-weighted mean where the most recent observation receives weight $N$ and the oldest receives weight...
- Parameterized by `period`.
- Output range: $0$ to $1$.
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [WMA](../../trends_FIR/wma/wma.md), [EMA](../../trends_IIR/ema/ema.md) | **Trading note:** Weighted average with custom weights; flexible aggregation for composite indicators.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Weighted Average computes a rolling linearly-weighted mean where the most recent observation receives weight $N$ and the oldest receives weight 1, making it mathematically identical to the Weighted Moving Average (WMA) but categorized as a statistical measure. The implementation uses a circular buffer with an $O(1)$ incremental update scheme: rather than recomputing the full weighted sum each bar, it maintains running sums and adjusts them through add/subtract operations as values enter and exit the window. This makes WAVG one of the most efficient weighted estimators available, with constant per-bar cost regardless of the lookback period.
@@ -125,4 +123,4 @@ Batch span path benefits from Vector<double> dot product for the weight applicat
- Pring, M.J. "Technical Analysis Explained." 5th edition, McGraw-Hill, 2014.
- Murphy, J.J. "Technical Analysis of the Financial Markets." New York Institute of Finance, 1999.
- Oppenheim, A.V. & Schafer, R.W. "Discrete-Time Signal Processing." 3rd edition, Pearson, 2010.
- Haykin, S. "Adaptive Filter Theory." 5th edition, Pearson, 2013.
- Haykin, S. "Adaptive Filter Theory." 5th edition, Pearson, 2013.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [wins.pine](wins.pine) |
- The Winsorized Mean Moving Average computes a rolling average after replacing (not discarding) the most extreme values in each tail with the bounda...
- Parameterized by `period`, `winpct` (default 10.0).
- Output range: Varies (see docs).
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Trim](../trim/Trim.md), [Percentile](../percentile/Percentile.md) | **Trading note:** Winsorized mean; replaces extreme values instead of removing them. Preserves sample size.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
The Winsorized Mean Moving Average computes a rolling average after replacing (not discarding) the most extreme values in each tail with the boundary values at the trim point. Unlike the trimmed mean (TRIM) which removes outliers entirely, Winsorization preserves the full sample size by clamping extreme values to the nearest non-extreme observation. At `winPct = 0` it degenerates to the SMA; at `winPct = 50` all values equal the median pair. The default 10% Winsorization provides a robust central tendency estimator that dampens outlier impact while maintaining the statistical efficiency advantages of the full sample size.
@@ -134,4 +132,4 @@ Sort blocks SIMD on the main path. The sum phase can use Vector<double> for mode
- Huber, P.J. & Ronchetti, E. "Robust Statistics." 2nd edition, Wiley, 2009.
- Wilcox, R.R. "Introduction to Robust Estimation and Hypothesis Testing." 4th edition, Academic Press, 2017.
- Fama, E.F. & French, K.R. "Common Risk Factors in the Returns on Stocks and Bonds." Journal of Financial Economics, 1993.
- Dixon, W.J. & Tukey, J.W. "Approximate Behavior of the Distribution of Winsorized t." Technometrics, 1968.
- Dixon, W.J. & Tukey, J.W. "Approximate Behavior of the Distribution of Winsorized t." Technometrics, 1968.
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [zscore.pine](zscore.pine) |
- The Z-Score measures how many population standard deviations a value lies from the rolling mean over a lookback window.
- Parameterized by `period` (default 14).
- Output range: Unbounded.
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [Normalize](../../numerics/normalize/Normalize.md), [StdDev](../stddev/StdDev.md) | **Trading note:** Z-score; number of standard deviations from mean. ±2σ indicates unusual move. Mean-reversion signal.
- Validated against manual computation, PineScript parity, and statistical invariants.
## Introduction
@@ -141,4 +139,4 @@ Z-scores are invariant under positive linear transformations. This property make
- Pearson, K. (1894). "Contributions to the Mathematical Theory of Evolution." *Philosophical Transactions of the Royal Society.*
- TradingView PineScript Reference: [ta.zscore](https://www.tradingview.com/pine-script-reference/v6/)
- Bollinger, J. (2001). *Bollinger on Bollinger Bands.* McGraw-Hill. (Z-score normalization of Bollinger %B)
- Bollinger, J. (2001). *Bollinger on Bollinger Bands.* McGraw-Hill. (Z-score normalization of Bollinger %B)
+2 -4
View File
@@ -13,9 +13,7 @@
| **PineScript** | [ztest.pine](ztest.pine) |
- ZTEST computes the **one-sample t-statistic**, measuring how many standard errors the rolling sample mean deviates from a hypothesized population m...
- Parameterized by `period` (default 30), `mu0` (default 0.0).
- Output range: Unbounded.
- Requires `period` bars of warmup before first valid output (IsHot = true).
- **Similar:** [JB](../jb/Jb.md), [Zscore](../zscore/Zscore.md) | **Trading note:** Z-test; tests if sample mean differs from population mean. Used to validate trading edge significance.
- Validated against manual computation, PineScript parity, and testable statistical properties.
## Introduction
@@ -140,4 +138,4 @@ No external TA libraries implement a one-sample t-test indicator. Validation is
- Student (W.S. Gosset), "The Probable Error of a Mean," *Biometrika*, 6(1), 1908, pp. 1-25
- Fisher, R.A., *Statistical Methods for Research Workers*, Oliver and Boyd, 1925
- PineScript reference: `ztest.pine` in this directory
- PineScript reference: `ztest.pine` in this directory