feat: Enhance volume indicators with ADOSC and SSF implementation and validation

This commit is contained in:
Miha Kralj
2025-12-20 15:08:07 -08:00
parent 5549c7329a
commit d21fea3c18
85 changed files with 5144 additions and 3954 deletions
+44 -1
View File
@@ -147,7 +147,7 @@ public class CsvFeedTests
// Fetch from start
var startTime = new DateTime(2025, 7, 1, 0, 0, 0, DateTimeKind.Utc).Ticks;
var series = feed.Fetch(5, startTime, TimeSpan.FromDays(1));
feed.Fetch(5, startTime, TimeSpan.FromDays(1));
// Next should now stream from fetched position
var bar = feed.Next(isNew: true);
@@ -250,4 +250,47 @@ public class CsvFeedTests
// Should return empty or minimal data
Assert.True(series.Count == 0);
}
[Fact]
public void Fetch_HandlesGapsCorrectly()
{
string tempCsv = Path.GetTempFileName() + ".csv";
try
{
// Create CSV with gaps
// Date, Open, High, Low, Close, Volume
// 2023-01-01 (Sunday)
// 2023-01-02 (Monday)
// 2023-01-04 (Wednesday) - Gap of Tuesday
// 2023-01-05 (Thursday)
var lines = new[]
{
"Date,Open,High,Low,Close,Volume",
"2023-01-05,103,104,102,103,1000",
"2023-01-04,102,103,101,102,1000",
"2023-01-02,101,102,100,101,1000",
"2023-01-01,100,101,99,100,1000"
};
File.WriteAllLines(tempCsv, lines);
var feed = new CsvFeed(tempCsv);
var startTime = new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks;
var interval = TimeSpan.FromDays(1);
// Fetch 5 bars. Should get 4 bars (Jan 1, 2, 4, 5).
var series = feed.Fetch(10, startTime, interval);
Assert.Equal(4, series.Count);
Assert.Equal(startTime, series[0].Time); // Jan 1
Assert.Equal(startTime + interval.Ticks, series[1].Time); // Jan 2
// Gap here
Assert.Equal(startTime + 3 * interval.Ticks, series[2].Time); // Jan 4
Assert.Equal(startTime + 4 * interval.Ticks, series[3].Time); // Jan 5
}
finally
{
if (File.Exists(tempCsv))
File.Delete(tempCsv);
}
}
}
+2 -3
View File
@@ -140,7 +140,6 @@ public class CsvFeed : IFeed
{
return Next(ref isNew);
}
/// <summary>
/// Returns a filtered subset of data matching the criteria.
/// Resets streaming position to start of returned data.
@@ -188,9 +187,9 @@ public class CsvFeed : IFeed
{
// Gap in data - skip forward
long gaps = (bar.Time - expectedTime) / interval.Ticks;
expectedTime += (gaps + 1) * interval.Ticks;
expectedTime += gaps * interval.Ticks;
if (Math.Abs(bar.Time - expectedTime + interval.Ticks) <= tolerance)
if (Math.Abs(bar.Time - expectedTime) <= tolerance)
{
result.Add(bar, isNew: true);
collected++;