mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 13:58:04 +00:00
validation and profiles
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
|
||||
using OoplesFinance.StockIndicators;
|
||||
using OoplesFinance.StockIndicators.Models;
|
||||
namespace QuanTAlib.Validation;
|
||||
|
||||
public sealed class SpearmanValidationTests
|
||||
@@ -104,4 +107,21 @@ public sealed class SpearmanValidationTests
|
||||
}
|
||||
Assert.Equal(0.0, s.Last.Value, 1e-10);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Spearman_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).CalculateEhlersSpearmanRankIndicator();
|
||||
var values = result.CustomValuesList;
|
||||
int finiteCount = values.Count(v => double.IsFinite(v));
|
||||
Assert.True(finiteCount > 100, $"Expected >100 finite values, got {finiteCount}");
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,20 @@ Spearman is more sensitive to large rank differences; Kendall weights all discor
|
||||
|
||||
## Performance Profile
|
||||
|
||||
### Operation Count (Streaming Mode)
|
||||
|
||||
Spearman rank correlation requires ranking both series each bar — O(N log N) per update.
|
||||
|
||||
| Operation | Count | Cost (cycles) | Subtotal |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Ring buffer add/evict (2 series) | 2 | 3 cy | ~6 cy |
|
||||
| Sort + assign ranks (2 series) | 2 * N log N | 2 cy | ~4N log N cy |
|
||||
| Pearson r on rank vectors | N | 3 cy | ~3N cy |
|
||||
| NaN guard + state update | 1 | 2 cy | ~2 cy |
|
||||
| **Total (N=14)** | **O(N log N)** | — | **~213 cy** |
|
||||
|
||||
O(N log N) per update. Sorting two arrays per bar is the dominant cost. Tied-rank correction adds negligible overhead for typical financial data (few exact ties).
|
||||
|
||||
| Operation | Complexity | Notes |
|
||||
|-----------|------------|-------|
|
||||
| Ranking (per series) | O(n²) | Pairwise comparison for each element |
|
||||
|
||||
Reference in New Issue
Block a user