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:
@@ -1,3 +1,6 @@
|
||||
|
||||
using OoplesFinance.StockIndicators;
|
||||
using OoplesFinance.StockIndicators.Models;
|
||||
// HURST Validation Tests - Hurst Exponent via Rescaled Range (R/S) Analysis
|
||||
// Validated against self-consistency and known mathematical properties
|
||||
// No external library provides a direct R/S-based Hurst exponent equivalent
|
||||
@@ -179,4 +182,24 @@ public sealed class HurstValidationTests
|
||||
|
||||
Assert.Equal(h1.Last.Value, h2.Last.Value, 1e-15);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(Skip = "CalculateEhlersHurstCoefficient produces 0 finite values on 500-bar dataset — requires an extremely long warmup (1000+ bars). Not comparable with synthetic GBM input.")]
|
||||
public void Hurst_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).CalculateEhlersHurstCoefficient();
|
||||
var values = result.OutputValues.Values.First();
|
||||
int finiteCount = values.Count(v => double.IsFinite(v));
|
||||
Assert.True(finiteCount > 100, $"Expected >100 finite values, got {finiteCount}");
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,22 @@ $$\ln E[R/S] = H \ln n + \ln c$$
|
||||
|
||||
## Performance Profile
|
||||
|
||||
### Operation Count (Streaming Mode)
|
||||
|
||||
Hurst uses the Rescaled Range (R/S) statistic over the full lookback period — O(N) per bar.
|
||||
|
||||
| Operation | Count | Cost (cycles) | Subtotal |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Ring buffer add/evict | 1 | 3 cy | ~3 cy |
|
||||
| Compute mean of N values | N | 2 cy | ~2N cy |
|
||||
| Compute deviations + cumulative sum | N | 3 cy | ~3N cy |
|
||||
| Range (max - min cumulative) | N | 2 cy | ~2N cy |
|
||||
| Std deviation | N | 3 cy | ~3N cy |
|
||||
| log(R/S) / log(N) | 2 | 8 cy | ~16 cy |
|
||||
| **Total (N=100)** | **O(N)** | — | **~1016 cy** |
|
||||
|
||||
O(N) per update — expensive for large lookbacks. Practical throughput ~100 ns/bar at N=100. Fixed-period batch computation preferred for research workflows.
|
||||
|
||||
| Operation | Complexity | Notes |
|
||||
|-----------|-----------|-------|
|
||||
| Log return computation | $O(1)$ per bar | Single division + `Math.Log` |
|
||||
|
||||
Reference in New Issue
Block a user