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
+7 -7
View File
@@ -439,7 +439,7 @@ public class RvTests
const int dataCount = 50;
var priceSeries = GeneratePriceSeries(dataCount);
var result = Rv.Calculate(priceSeries, period: 5, smoothingPeriod: 10);
var result = Rv.Batch(priceSeries, period: 5, smoothingPeriod: 10);
Assert.Equal(dataCount, result.Count);
}
@@ -617,7 +617,7 @@ public class RvTests
{
var prices = GeneratePriceSeries(100);
var result = Rv.Calculate(prices, period: 5, smoothingPeriod: 14);
var result = Rv.Batch(prices, period: 5, smoothingPeriod: 14);
Assert.Equal(100, result.Count);
Assert.True(double.IsFinite(result[result.Count - 1].Value));
@@ -628,7 +628,7 @@ public class RvTests
{
var bars = GenerateTestData(100);
var result = Rv.Calculate(bars, period: 5, smoothingPeriod: 14);
var result = Rv.Batch(bars, period: 5, smoothingPeriod: 14);
Assert.Equal(100, result.Count);
Assert.True(double.IsFinite(result[result.Count - 1].Value));
@@ -639,10 +639,10 @@ public class RvTests
{
var prices = GeneratePriceSeries(10);
Assert.Throws<ArgumentException>(() => Rv.Calculate(prices, period: 0));
Assert.Throws<ArgumentException>(() => Rv.Calculate(prices, period: -1));
Assert.Throws<ArgumentException>(() => Rv.Calculate(prices, period: 5, smoothingPeriod: 0));
Assert.Throws<ArgumentException>(() => Rv.Calculate(prices, period: 5, smoothingPeriod: 10, annualize: true, annualPeriods: 0));
Assert.Throws<ArgumentException>(() => Rv.Batch(prices, period: 0));
Assert.Throws<ArgumentException>(() => Rv.Batch(prices, period: -1));
Assert.Throws<ArgumentException>(() => Rv.Batch(prices, period: 5, smoothingPeriod: 0));
Assert.Throws<ArgumentException>(() => Rv.Batch(prices, period: 5, smoothingPeriod: 10, annualize: true, annualPeriods: 0));
}
[Fact]
+1 -1
View File
@@ -178,7 +178,7 @@ public class RvValidationTests
}
// Batch calculation
var batchResult = Rv.Calculate(prices, 5, 10);
var batchResult = Rv.Batch(prices, 5, 10);
Assert.Equal(batchResult.Last.Value, streamingRv.Last.Value, 8);
}
+11 -3
View File
@@ -349,7 +349,7 @@ public sealed class Rv : 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(TSeries source, int period = 5, int smoothingPeriod = 20, bool annualize = true, int annualPeriods = 252)
public static TSeries Batch(TSeries source, int period = 5, int smoothingPeriod = 20, bool annualize = true, int annualPeriods = 252)
{
if (period < 1)
{
@@ -382,7 +382,7 @@ public sealed class Rv : AbstractBase
/// <summary>
/// Calculates RV for a bar series (static).
/// </summary>
public static TSeries Calculate(TBarSeries source, int period = 5, int smoothingPeriod = 20, bool annualize = true, int annualPeriods = 252)
public static TSeries Batch(TBarSeries source, int period = 5, int smoothingPeriod = 20, bool annualize = true, int annualPeriods = 252)
{
var rv = new Rv(period, smoothingPeriod, annualize, annualPeriods);
return rv.Update(source);
@@ -524,4 +524,12 @@ public sealed class Rv : AbstractBase
output[i] = result;
}
}
}
public static (TSeries Results, Rv Indicator) Calculate(TSeries source, int period = 5, int smoothingPeriod = 20, bool annualize = true, int annualPeriods = 252)
{
var indicator = new Rv(period, smoothingPeriod, annualize, annualPeriods);
TSeries results = indicator.Update(source);
return (results, indicator);
}
}