normalization of methods

This commit is contained in:
Miha Kralj
2026-02-10 21:33:16 -08:00
parent 915d7a007b
commit 6d6259a47d
527 changed files with 10525 additions and 2123 deletions
+5 -5
View File
@@ -419,7 +419,7 @@ public class RsvTests
const int dataCount = 50;
var barSeries = GenerateTestData(dataCount);
var result = Rsv.Calculate(barSeries, period: 10);
var result = Rsv.Batch(barSeries, period: 10);
Assert.Equal(dataCount, result.Count);
}
@@ -685,7 +685,7 @@ public class RsvTests
{
var bars = GenerateTestData(100);
var result = Rsv.Calculate(bars, period: 14);
var result = Rsv.Batch(bars, period: 14);
Assert.Equal(100, result.Count);
Assert.True(double.IsFinite(result[result.Count - 1].Value));
@@ -696,9 +696,9 @@ public class RsvTests
{
var bars = GenerateTestData(10);
Assert.Throws<ArgumentException>(() => Rsv.Calculate(bars, period: 0));
Assert.Throws<ArgumentException>(() => Rsv.Calculate(bars, period: -1));
Assert.Throws<ArgumentException>(() => Rsv.Calculate(bars, period: 10, annualize: true, annualPeriods: 0));
Assert.Throws<ArgumentException>(() => Rsv.Batch(bars, period: 0));
Assert.Throws<ArgumentException>(() => Rsv.Batch(bars, period: -1));
Assert.Throws<ArgumentException>(() => Rsv.Batch(bars, period: 10, annualize: true, annualPeriods: 0));
}
[Fact]
+1 -1
View File
@@ -184,7 +184,7 @@ public class RsvValidationTests
}
// Batch calculation
var batchResult = Rsv.Calculate(bars, 14);
var batchResult = Rsv.Batch(bars, 14);
// Compare last values
Assert.Equal(batchResult.Last.Value, streamingRsv.Last.Value, 8);
+18 -5
View File
@@ -49,6 +49,7 @@ public sealed class Rsv : AbstractBase
// Event source for disposal
private readonly ITValuePublisher? _source;
private bool _disposed;
[StructLayout(LayoutKind.Auto)]
private record struct State(
@@ -363,9 +364,13 @@ public sealed class Rsv : AbstractBase
/// <param name="disposing">True if disposing managed resources.</param>
protected override void Dispose(bool disposing)
{
if (disposing && _source is not null)
if (!_disposed)
{
_source.Pub -= Handle;
if (disposing && _source is not null)
{
_source.Pub -= Handle;
}
_disposed = true;
}
base.Dispose(disposing);
}
@@ -378,7 +383,7 @@ public sealed class Rsv : AbstractBase
/// <param name="annualize">Whether to annualize.</param>
/// <param name="annualPeriods">Periods per year.</param>
/// <returns>A TSeries containing the volatility values.</returns>
public static TSeries Calculate(TBarSeries source, int period = 20, bool annualize = true, int annualPeriods = 252)
public static TSeries Batch(TBarSeries source, int period = 20, bool annualize = true, int annualPeriods = 252)
{
var rsv = new Rsv(period, annualize, annualPeriods);
return rsv.Update(source);
@@ -387,7 +392,7 @@ public sealed class Rsv : AbstractBase
/// <summary>
/// Calculates RSV for a TSeries (treats values as pre-computed RS variances).
/// </summary>
public static TSeries Calculate(TSeries source, int period = 20, bool annualize = true, int annualPeriods = 252)
public static TSeries Batch(TSeries source, int period = 20, bool annualize = true, int annualPeriods = 252)
{
if (period <= 0)
{
@@ -523,6 +528,14 @@ public sealed class Rsv : AbstractBase
}
}
public static (TSeries Results, Rsv Indicator) Calculate(TBarSeries source, int period = 20, bool annualize = true, int annualPeriods = 252)
{
var indicator = new Rsv(period, annualize, annualPeriods);
TSeries results = indicator.Update(source);
return (results, indicator);
}
/// <summary>
/// Batch calculation from pre-computed RS variances.
/// </summary>
@@ -596,4 +609,4 @@ public sealed class Rsv : AbstractBase
output[i] = volatility;
}
}
}
}