mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 13:38:05 +00:00
validation and profiles
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using OoplesFinance.StockIndicators;
|
||||
using OoplesFinance.StockIndicators.Models;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public sealed class PivotfibValidationTests
|
||||
@@ -245,4 +248,24 @@ public sealed class PivotfibValidationTests
|
||||
Assert.Equal(ind.R3 - ind.PP, ind.PP - ind.S3, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(Skip = "Ooples pivot indicators group by calendar day — 500×1-min bars yields ~3 daily pivots. Requires daily OHLCV input; not comparable with intraday GBM data.")]
|
||||
public void Pivotfib_MatchesOoples_Structural()
|
||||
{
|
||||
var gbm = new GBM(startPrice: 100.0, mu: 0.02, sigma: 0.15, seed: 42);
|
||||
var bars = gbm.Fetch(500, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
var ooplesData = bars.Select(b => new TickerData
|
||||
{
|
||||
Date = new DateTime(b.Time, DateTimeKind.Utc),
|
||||
Open = b.Open,
|
||||
High = b.High,
|
||||
Low = b.Low,
|
||||
Close = b.Close,
|
||||
Volume = b.Volume
|
||||
}).ToList();
|
||||
var result = new StockData(ooplesData).CalculateFibonacciPivotPoints();
|
||||
var values = result.OutputValues.Values.First();
|
||||
int finiteCount = values.Count(v => double.IsFinite(v));
|
||||
Assert.True(finiteCount > 100, $"Expected >100 finite values, got {finiteCount}");
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,37 @@ Pivotfib.BatchAll(high, low, close, ppOut, r1Out, s1Out, r2Out, s2Out, r3Out, s3
|
||||
| **PIVOTEXT** (Extended) | Arithmetic extended | 11 | 1×–4× range |
|
||||
| **PIVOTDEM** (DeMark) | Conditional X/4 | 3 | Direction-based |
|
||||
|
||||
|
||||
## Performance Profile
|
||||
|
||||
### Operation Count (Streaming Mode)
|
||||
|
||||
PivotFib computes PP and 6 Fibonacci S/R levels from previous bar's HLC — O(1) pure arithmetic.
|
||||
|
||||
| Operation | Count | Cost (cycles) | Subtotal |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Store prev bar HLC | 3 | 1 cy | ~3 cy |
|
||||
| PP = (H + L + C) / 3 | 1 | 2 cy | ~2 cy |
|
||||
| range = H - L | 1 | 1 cy | ~1 cy |
|
||||
| R1/S1 via FMA (0.382 * range) | 2 | 1 cy | ~2 cy |
|
||||
| R2/S2 via FMA (0.618 * range) | 2 | 1 cy | ~2 cy |
|
||||
| R3/S3 = PP +/- range | 2 | 1 cy | ~2 cy |
|
||||
| NaN guard + state update | 1 | 2 cy | ~2 cy |
|
||||
| **Total** | **O(1)** | — | **~14 cy** |
|
||||
|
||||
Pure O(1) arithmetic on previous-bar data. Fibonacci multipliers 0.382 and 0.618 are precomputed constants; FMA fuses multiply-add into a single instruction.
|
||||
|
||||
### Batch Mode (SIMD Analysis)
|
||||
|
||||
| Operation | Vectorizable? | Notes |
|
||||
| :--- | :---: | :--- |
|
||||
| PP computation | Yes | Vector<double> (H+L+C)/3 across all bars |
|
||||
| Range calculation | Yes | Vector subtract H-L |
|
||||
| Fibonacci level projection | Yes | FMA with broadcast constants 0.382, 0.618 |
|
||||
| All 7 output spans | Yes | Full SIMD pass — no data dependencies |
|
||||
|
||||
Excellent SIMD candidate — all 7 output levels are independent. BatchAll span overload processes 4 bars per AVX2 cycle. Expected 4× throughput vs scalar.
|
||||
|
||||
## Implementation Details
|
||||
- **WarmupPeriod**: 2 bars (need previous bar's HLC)
|
||||
- **Parameters**: None
|
||||
|
||||
Reference in New Issue
Block a user