mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 12:08:05 +00:00
normalization of methods
This commit is contained in:
@@ -274,7 +274,7 @@ public class EwmaTests
|
||||
{
|
||||
ts.Add(new TValue(times[i], close[i]));
|
||||
}
|
||||
var batchResult = Ewma.Calculate(ts, 20);
|
||||
var batchResult = Ewma.Batch(ts, 20);
|
||||
|
||||
Assert.Equal(iterativeResult, batchResult[batchResult.Count - 1].Value, 1e-8);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public class EwmaTests
|
||||
ts.Add(new TValue(times[i], close[i]));
|
||||
}
|
||||
|
||||
var result = Ewma.Calculate(ts, 20);
|
||||
var result = Ewma.Batch(ts, 20);
|
||||
|
||||
Assert.Equal(100, result.Count);
|
||||
Assert.True(double.IsFinite(result[result.Count - 1].Value));
|
||||
@@ -307,10 +307,10 @@ public class EwmaTests
|
||||
ts.Add(new TValue(DateTime.UtcNow.AddMinutes(i), 100 + i));
|
||||
}
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Calculate(ts, 0));
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Calculate(ts, -1));
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Calculate(ts, 5, true, 0));
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Calculate(ts, 5, true, -1));
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Batch(ts, 0));
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Batch(ts, -1));
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Batch(ts, 5, true, 0));
|
||||
Assert.Throws<ArgumentException>(() => Ewma.Batch(ts, 5, true, -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -160,7 +160,7 @@ public class EwmaValidationTests
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Ewma.Calculate(ts, DefaultPeriod, DefaultAnnualize, DefaultAnnualPeriods);
|
||||
var batchResult = Ewma.Batch(ts, DefaultPeriod, DefaultAnnualize, DefaultAnnualPeriods);
|
||||
|
||||
Assert.Equal(ewmaStream.Last.Value, batchResult[batchResult.Count - 1].Value, StreamingTolerance);
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class EwmaValidationTests
|
||||
double tseriesValue = tseriesResult[tseriesResult.Count - 1].Value;
|
||||
|
||||
// Mode 3: Static Calculate
|
||||
var batchResult = Ewma.Calculate(ts, DefaultPeriod, DefaultAnnualize, DefaultAnnualPeriods);
|
||||
var batchResult = Ewma.Batch(ts, DefaultPeriod, DefaultAnnualize, DefaultAnnualPeriods);
|
||||
double batchValue = batchResult[batchResult.Count - 1].Value;
|
||||
|
||||
// Mode 4: Span Batch
|
||||
|
||||
@@ -238,7 +238,7 @@ public sealed class Ewma : AbstractBase
|
||||
/// <summary>
|
||||
/// Calculates EWMA Volatility for entire series.
|
||||
/// </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)
|
||||
{
|
||||
@@ -350,4 +350,11 @@ public sealed class Ewma : AbstractBase
|
||||
output[i] = double.IsFinite(result) ? result : 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static (TSeries Results, Ewma Indicator) Calculate(TSeries source, int period = 20, bool annualize = true, int annualPeriods = 252)
|
||||
{
|
||||
var indicator = new Ewma(period, annualize, annualPeriods);
|
||||
TSeries results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user