mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 12:38:06 +00:00
fix: update validation logic to prevent negative start index and improve error message for alpha parameter
This commit is contained in:
@@ -11,7 +11,7 @@ public static class ValidationHelper
|
||||
Assert.Equal(qSeries.Count, sSeries.Count);
|
||||
|
||||
int count = qSeries.Count;
|
||||
int start = count - skip;
|
||||
int start = Math.Max(0, count - skip);
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ public static class ValidationHelper
|
||||
Assert.Equal(qResults.Count, sSeries.Count);
|
||||
|
||||
int count = qResults.Count;
|
||||
int start = count - skip;
|
||||
int start = Math.Max(0, count - skip);
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -47,7 +47,7 @@ public static class ValidationHelper
|
||||
Assert.Equal(qOutput.Length, sSeries.Count);
|
||||
|
||||
int count = qOutput.Length;
|
||||
int start = count - skip;
|
||||
int start = Math.Max(0, count - skip);
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public static class ValidationHelper
|
||||
public static void VerifyData(TSeries qSeries, double[] tOutput, int lookback, int skip = 100, double tolerance = 1e-6)
|
||||
{
|
||||
int count = qSeries.Count;
|
||||
int start = count - skip;
|
||||
int start = Math.Max(0, count - skip);
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ public static class ValidationHelper
|
||||
public static void VerifyData(List<double> qResults, double[] tOutput, int lookback, int skip = 100, double tolerance = 1e-6)
|
||||
{
|
||||
int count = qResults.Count;
|
||||
int start = count - skip;
|
||||
int start = Math.Max(0, count - skip);
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ public static class ValidationHelper
|
||||
public static void VerifyData(double[] qOutput, double[] tOutput, int lookback, int skip = 100, double tolerance = 1e-6)
|
||||
{
|
||||
int count = qOutput.Length;
|
||||
int start = count - skip;
|
||||
int start = Math.Max(0, count - skip);
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -123,8 +123,9 @@ public static class ValidationHelper
|
||||
public static void VerifyData(TSeries qSeries, double[] tOutput, Range outRange, int lookback, int skip = 100, double tolerance = 1e-6)
|
||||
{
|
||||
int count = qSeries.Count;
|
||||
int start = count - skip;
|
||||
int validCount = outRange.End.Value - outRange.Start.Value;
|
||||
int start = Math.Max(0, count - skip);
|
||||
var (_, length) = outRange.GetOffsetAndLength(tOutput.Length);
|
||||
int validCount = length;
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -144,8 +145,9 @@ public static class ValidationHelper
|
||||
public static void VerifyData(List<double> qResults, double[] tOutput, Range outRange, int lookback, int skip = 100, double tolerance = 1e-6)
|
||||
{
|
||||
int count = qResults.Count;
|
||||
int start = count - skip;
|
||||
int validCount = outRange.End.Value - outRange.Start.Value;
|
||||
int start = Math.Max(0, count - skip);
|
||||
var (_, length) = outRange.GetOffsetAndLength(tOutput.Length);
|
||||
int validCount = length;
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
@@ -165,8 +167,9 @@ public static class ValidationHelper
|
||||
public static void VerifyData(double[] qOutput, double[] tOutput, Range outRange, int lookback, int skip = 100, double tolerance = 1e-6)
|
||||
{
|
||||
int count = qOutput.Length;
|
||||
int start = count - skip;
|
||||
int validCount = outRange.End.Value - outRange.Start.Value;
|
||||
int start = Math.Max(0, count - skip);
|
||||
var (_, length) = outRange.GetOffsetAndLength(tOutput.Length);
|
||||
int validCount = length;
|
||||
|
||||
for (int i = start; i < count; i++)
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CfbTests
|
||||
[Fact]
|
||||
public void ZigZag_ReturnsOne()
|
||||
{
|
||||
var cfb = new Cfb(new int[] { 4, 8 });
|
||||
var cfb = new Cfb([4, 8]);
|
||||
// 100, 101, 100, 101...
|
||||
// NetMove(4) = Abs(100 - 100) = 0. Ratio = 0.
|
||||
// NetMove(8) = 0. Ratio = 0.
|
||||
@@ -93,7 +93,7 @@ public class CfbTests
|
||||
}
|
||||
|
||||
// Update with 100th point (isNew=true)
|
||||
var val1 = cfb.Update(data[99], true);
|
||||
cfb.Update(data[99], true);
|
||||
|
||||
// Update with modified 100th point (isNew=false)
|
||||
var modified = new TValue(data[99].Time, data[99].Value + 1.0);
|
||||
|
||||
@@ -235,7 +235,6 @@ public sealed class Cfb : ITValuePublisher
|
||||
Update(new TValue(source.Times[i], source.Values[i]), true);
|
||||
}
|
||||
|
||||
Last = new TValue(tSpan[len - 1], vSpan[len - 1]);
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
|
||||
|
||||
-151
@@ -1,151 +0,0 @@
|
||||
# To do
|
||||
|
||||
| **Indicator Name** | **Libraries** |
|
||||
| ---------------------------------------------------------------------------- | --------------------------------------------- |
|
||||
| **Aroon** – measures trend strength (Aroon Up/Down) | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Average True Range (ATR)** – volatility measure | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Balance of Power (BOP)** – momentum indicator | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Bollinger Bands** – volatility bands around moving average | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Chaikin Oscillator** (Accumulation/Distribution Osc) – volume momentum | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Chande Momentum Oscillator (CMO)** – momentum indicator | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Commodity Channel Index (CCI)** – deviation from mean price | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Double Exponential Moving Average (DEMA)** – a smoother EMA | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Exponential Moving Average (EMA)** – weighted moving average | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Linear Regression** (Line of Best Fit) – trend line value | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Momentum** (Rate of Change) – price change over period | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Money Flow Index (MFI)** – volume-weighted RSI | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Moving Average Convergence Divergence (MACD)** – trend/momentum oscillator | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Normalized ATR (NATR)** – ATR normalized to price | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Parabolic SAR** – stop-and-reverse trend indicator | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Relative Strength Index (RSI)** – momentum oscillator | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Simple Moving Average (SMA)** – arithmetic moving average | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Stochastic Oscillator** (Stoch) – %K and %D oscillators | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Stochastic RSI** – RSI applied to stochastic formula | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Triple Exponential Moving Average (T3)** – Tillson’s T3 MA | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **TRIX** (Triple EMA Oscillator) – triple EMA rate-of-change | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **True Range (TR)** – high/low range measure | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Ultimate Oscillator** – multi-period oscillator | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Weighted Moving Average (WMA)** – volume/point-weighted MA | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
| **Williams %R** – Larry Williams overbought/oversold oscillator | TA-Lib, Tulip, Skender, PineScript, Pandas-TA |
|
||||
|
||||
| **Indicator Name** | **Libraries** |
|
||||
| --------------------------------------------------------------------- | ------------------------------------------------------- |
|
||||
| **Arnaud Legoux Moving Average (ALMA)** – smoothing MA | Skender, PineScript, Pandas-TA (not in TA-Lib or Tulip) |
|
||||
| **Average Directional Index (ADX)** – smoothed DMI oscillator | TA-Lib, Skender, PineScript (not in Tulip or Pandas-TA) |
|
||||
| **Average Directional Movement Index Rating (ADXR)** – lagged ADX | TA-Lib, Tulip, PineScript (not in Skender or Pandas-TA) |
|
||||
| **Beta Coefficient** – Beta (relative volatility vs market) | TA-Lib, Skender, PineScript (not in Tulip or Pandas-TA) |
|
||||
| **Chaikin Money Flow (CMF)** – volume flow oscillator | Skender, PineScript, Pandas-TA (not in TA-Lib or Tulip) |
|
||||
| **Choppiness Index** – market choppiness (trend/no-trend) | Skender, PineScript, Pandas-TA (not in TA-Lib or Tulip) |
|
||||
| **Ease of Movement (EMV)** – price/volume change oscillator | Tulip, PineScript, Pandas-TA (not in TA-Lib or Skender) |
|
||||
| **Hull Moving Average (HMA)** – fast smoothing MA | Tulip, PineScript, Pandas-TA (not in TA-Lib or Skender) |
|
||||
| **Kaufman’s Adaptive Moving Average (KAMA)** – volatility-adaptive MA | TA-Lib, PineScript, Pandas-TA (not in Tulip or Skender) |
|
||||
| **Klinger Volume Oscillator (KVO)** – volume force oscillator | Tulip, Skender, PineScript (not in TA-Lib or Pandas-TA) |
|
||||
| **Mass Index** – price range compression index | Tulip, PineScript, Pandas-TA (not in TA-Lib or Skender) |
|
||||
| **Negative Volume Index (NVI)** – volume-based index | Tulip, PineScript, Pandas-TA (not in TA-Lib or Skender) |
|
||||
| **On-Balance Volume (OBV)** – cumulative volume | TA-Lib, Skender, Pandas-TA (not in Tulip or PineScript) |
|
||||
| **Positive Volume Index (PVI)** – volume-based index | Tulip, PineScript, Pandas-TA (not in TA-Lib or Skender) |
|
||||
| **Qstick** – price change oscillator (candlestick average) | Tulip, PineScript, Skender (not in TA-Lib or Pandas-TA) |
|
||||
| **Schaff Trend Cycle** – cycle oscillator by Schaff | Skender, PineScript, Pandas-TA (not in TA-Lib or Tulip) |
|
||||
| **Smoothed Moving Average (SMMA)** – Wilder’s smoothing (RMA) | Skender, PineScript, Pandas-TA (not in TA-Lib or Tulip) |
|
||||
| **SuperTrend** – ATR-based trend indicator | Skender, PineScript, Pandas-TA (not in TA-Lib or Tulip) |
|
||||
| **Volatility (Historical Volatility)** – statistical volatility | Tulip, PineScript, Pandas-TA (not in TA-Lib or Skender) |
|
||||
| **Volume Oscillator (PVO/VOSC)** – difference in EMAs of volume | Tulip, PineScript, Pandas-TA (not in TA-Lib or Skender) |
|
||||
| **Williams Alligator** – Bill Williams’ Alligator (3 MAs) | Skender, PineScript, Tulip (not in TA-Lib or Pandas-TA) |
|
||||
| **Williams Fractal** – Bill Williams’ fractal pattern | Skender, PineScript, Pandas-TA (not in TA-Lib or Tulip) |
|
||||
|
||||
| **Indicator Name** | **Libraries** |
|
||||
| ------------------------------------------------------------------------------------------------------- | --------------------- |
|
||||
| **ATR Trailing Stop** – ATR-based stop indicator | Skender, PineScript |
|
||||
| **Aberration** – trend-following band indicator | PineScript, Pandas-TA |
|
||||
| **Acceleration Bands** – Bollinger-type bands by Price Headley | PineScript, Pandas-TA |
|
||||
| **Archer Moving Averages Trends (AMAT)** – Archer’s composite trend MA | PineScript, Pandas-TA |
|
||||
| **Archer On-Balance Volume (AOBV)** – Archer’s OBV variation | PineScript, Pandas-TA |
|
||||
| **BRAR** – Bull Ratio & Bear Ratio indicator | PineScript, Pandas-TA |
|
||||
| **Bias (BIAS)** – price bias from MA (percentage) | PineScript, Pandas-TA |
|
||||
| **Bull and Bear Power** – Elder’s bull power and bear power | Skender, PineScript |
|
||||
| **Center of Gravity** – Ehlers’ center-of-gravity oscillator | PineScript, Pandas-TA |
|
||||
| **Chande Forecast Oscillator (CFO)** – deviation from linear regression forecast | PineScript, Pandas-TA |
|
||||
| **Chande Kroll Stop (CKSP)** – volatility stop by Chande & Kroll | Skender, Pandas-TA |
|
||||
| **Chandelier Exit** – ATR-based stop by Chuck LeBeau | Skender, PineScript |
|
||||
| **ConnorsRSI** – Connors’ 3-component RSI | Skender, PineScript |
|
||||
| **Dominant Cycle Periods** – dominant cycle period (Ehlers) | Skender, Pandas-TA |
|
||||
| **Elder-ray Index (ERI)** – measures bull and bear pressure | Skender, Pandas-TA |
|
||||
| **Endpoint Moving Average (EPMA)** – end-point linear regression MA | Skender, PineScript |
|
||||
| **Entropy** – Shannon entropy of returns | PineScript, Pandas-TA |
|
||||
| **Even Better Sinewave (EBSW)** – improved MESA cycle indicator | PineScript, Pandas-TA |
|
||||
| **Fractal Chaos Bands** – price bands using fractal geometry | Skender, PineScript |
|
||||
| **Gator Oscillator** – Bill Williams’ Gator (Alligator derivative) | Skender, PineScript |
|
||||
| **Gann High-Low Activator (HiLo)** – trend indicator by Gann | PineScript, Pandas-TA |
|
||||
| **Heikin-Ashi** (HA candles) – averaged candlestick values | Skender, Pandas-TA |
|
||||
| **Historical Volatility (HV)** – statistical volatility (std dev) | Skender, PineScript |
|
||||
| **Holt-Winter Moving Average (HWMA)** – Holt-Winters double EMA | PineScript, Pandas-TA |
|
||||
| **Inertia** – RSI-based trend inertia indicator | PineScript, Pandas-TA |
|
||||
| **Increasing/Decreasing** – price increase/decrease streak | PineScript, Pandas-TA |
|
||||
| **Ichimoku Cloud** (Ichimoku Kinkō Hyō) – five-line system | Skender, Pandas-TA |
|
||||
| **Least Squares Moving Average (LSMA)** – linear regression line as MA | Skender, PineScript |
|
||||
| **Long Run / Short Run** – long-term and short-term trend lines | PineScript, Pandas-TA |
|
||||
| **Market Facilitation Index (MFI)** – volume-price efficiency (Bill Williams) | Tulip, PineScript |
|
||||
| **McGinley Dynamic** – adaptive moving average by McGinley | Skender, Pandas-TA |
|
||||
| **Median Price** – (High+Low)/2 series | TA-Lib, Tulip |
|
||||
| **Modified Moving Average (MMA)** – arithmetic moving average variant | Skender, PineScript |
|
||||
| **Momentum Oscillator** (alternate term for Momentum) | *See Momentum above* |
|
||||
| **Pretty Good Oscillator (PGO)** – distance from EMA in std dev | PineScript, Pandas-TA |
|
||||
| **Price Channels** – highest high/lowest low channel | Skender, PineScript |
|
||||
| **Price Distance (PDIST)** – distance of price from MA | PineScript, Pandas-TA |
|
||||
| **Price Momentum Oscillator (PMO)** – Tushar Chande’s momentum osc | Skender, PineScript |
|
||||
| **Price Relative Strength (PRS)** – ratio of asset to benchmark | Skender, PineScript |
|
||||
| **Pivot Points** (Floor pivots) – support/resistance levels | Skender, PineScript |
|
||||
| **Rolling Pivot Points** – continuously updated pivots | Skender, PineScript |
|
||||
| **Rescaled Range (R/S) Analysis** – Hurst exponent calculation | Skender, PineScript |
|
||||
| **Relative Vigor Index (RVI)** – oscillator of confirmation | PineScript, Pandas-TA |
|
||||
| **Schaff Trend Cycle** – *(see above in 3-library list)* | |
|
||||
| **Sine Weighted MA (SINWMA)** – sine-weighted moving average | PineScript, Pandas-TA |
|
||||
| **Slope** (Linear Regression Slope) – slope of trendline | TA-Lib, Pandas-TA |
|
||||
| **Standard Error** (of price) – std error over period | Tulip, Pandas-TA |
|
||||
| **Super Smoother Filter (SSF)** – Ehlers’ low-pass filter | PineScript, Pandas-TA |
|
||||
| **Summation (SUM)** – cumulative sum over period | TA-Lib, Tulip |
|
||||
| **TTM Trend** – Trend indicator from TradeTheMarkets | PineScript, Pandas-TA |
|
||||
| **Typical Price** – (H+L+C)/3 series | TA-Lib, Tulip |
|
||||
| **Ulcer Index (UI)** – drawdown volatility measure | Skender, Pandas-TA |
|
||||
| **Vertical Horizontal Filter (VHF)** – trend noise filter | Tulip, PineScript |
|
||||
| **Volatility Stop** – ATR-based stop indicator | Skender, PineScript |
|
||||
| **Volume Weighted Average Price (VWAP)** – price weighted by volume | Skender, Pandas-TA |
|
||||
| **Volume Profile (VP)** – volume distribution by price (histogram) | PineScript, Pandas-TA |
|
||||
| **Williams %R (percent Range)** – *listed above in 5-library list* | |
|
||||
| **Zig Zag** – filtered price swings (visual aid) | Skender, PineScript |
|
||||
|
||||
| **Indicator Name** | **Library** |
|
||||
| ----------------------------------------------------------------------------- | -------------- |
|
||||
| **Hilbert Transform Dominant Cycle Period** – Ehlers’ cycle period | TA-Lib (only) |
|
||||
| **Hilbert Transform Dominant Cycle Phase** – Ehlers’ cycle phase | TA-Lib (only) |
|
||||
| **Hilbert Transform Phasor Components** – In-phase/quadrature components | TA-Lib (only) |
|
||||
| **Hilbert Transform SineWave** – Ehlers’ sine/cosine of cycle | TA-Lib (only) |
|
||||
| **Hilbert Transform Instantaneous Trendline** – Ehlers’ IMAT | TA-Lib (only) |
|
||||
| **Hilbert Transform Trend vs Cycle Mode** – cycle/trend discrimination | TA-Lib (only) |
|
||||
| **Highest/Lowest values over period (MIN/MAX)** – period extrema | TA-Lib (only) |
|
||||
| **Index of Highest/Lowest value (MININDEX/MAXINDEX)** – extrema index | TA-Lib (only) |
|
||||
| **Lowest & Highest values (MINMAX)** – both extrema in one output | TA-Lib (only) |
|
||||
| **Pearson’s Correlation Coefficient (CORREL)** – correlation of two series | TA-Lib (only) |
|
||||
| **Linear Regression Intercept** – intercept of best-fit line | TA-Lib (only) |
|
||||
| **Linear Regression Angle** – angle of best-fit line | TA-Lib (only) |
|
||||
| **Time Series Forecast (TSF)** – forecast of next value via LR | TA-Lib (only) |
|
||||
| **Vector Trigonometric Functions** (SIN, COS, TAN, etc) – elementwise math | Tulip (only) |
|
||||
| **Vector Arithmetic Ops** (ADD, SUB, MUL, DIV, etc) – elementwise math | Tulip (only) |
|
||||
| **Vector Log, Exp, etc** – elementwise transforms (LN, EXP, etc) | Tulip (only) |
|
||||
| **Crossovers** (Crossany/Crossover) – series cross above/below logic | Tulip (only) |
|
||||
| **Mean Deviation (MD)** – mean absolute deviation | Tulip (only) |
|
||||
| **Standard Error (STDERR)** – std error of values | Tulip (only) |
|
||||
| **Decay** (Linear/Exponential) – value decay over time | Tulip (only) |
|
||||
| **Moving Average Envelopes** – percentage envelopes around MA | Skender (only) |
|
||||
| **Donchian Channels** – high/low channel over *n* periods | Skender (only) |
|
||||
| **Fractal Chaos Bands** – *(also listed in 2-library category: Pine)* | |
|
||||
| **Schaff Trend Cycle** – *(also listed in 3-library category)* | |
|
||||
| **ConnorsRSI** – *(if PineScript not included; otherwise 2 libraries)* | |
|
||||
|
||||
## Missing Indicators (Identified Gap Analysis)
|
||||
|
||||
- **Trends:** FWMA, GANN_HILO, MAVP, SSL, SWMA, PARA_WMA.
|
||||
- **Momentum:** COPPOCK, ERI, KST, PSL, QQE, RMI, RVGI, VHF.
|
||||
- **Volume:** BWMFI, VFI.
|
||||
- **Volatility:** THERMO.
|
||||
- **Statistics:** LINREG_ANGLE, LINREG_INT, LINREG_SLOPE, MAD.
|
||||
@@ -220,8 +220,8 @@ public sealed class Tema : ITValuePublisher
|
||||
{
|
||||
if (source.Length != output.Length)
|
||||
throw new ArgumentException("Source and output must have the same length");
|
||||
if (alpha <= 0 || alpha > 1)
|
||||
throw new ArgumentException("Alpha must be between 0 and 1", nameof(alpha));
|
||||
if (alpha <= 0 || alpha >= 1)
|
||||
throw new ArgumentException("Alpha must be strictly between 0 and 1", nameof(alpha));
|
||||
|
||||
if (source.Length == 0) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user