mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-18 02:28:05 +00:00
Refactor tests and improve random number generation handling; update Dema, Ema, Sma, Tema, Wma, and GBM classes for consistency and clarity
This commit is contained in:
@@ -212,7 +212,7 @@ public class GBMTests
|
||||
var gbm = new GBM(startPrice: 100.0);
|
||||
|
||||
// Start with streaming
|
||||
var bar1 = gbm.Next();
|
||||
_ = gbm.Next();
|
||||
var bar2 = gbm.Next();
|
||||
|
||||
// Batch generation with explicit time
|
||||
@@ -253,11 +253,11 @@ public class GBMTests
|
||||
{
|
||||
var gbm = new GBM(startPrice: 100.0);
|
||||
|
||||
var bar1 = gbm.Next();
|
||||
var bar2 = gbm.Next();
|
||||
var previousBar = gbm.Next();
|
||||
var currentBar = gbm.Next();
|
||||
|
||||
// bar2.Open should equal bar1.Close (continuity)
|
||||
Assert.Equal(bar1.Close, bar2.Open);
|
||||
// currentBar.Open should equal previousBar.Close (continuity)
|
||||
Assert.Equal(previousBar.Close, currentBar.Open);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -268,7 +268,7 @@ public class GBMTests
|
||||
// Generate multiple bars
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
gbm.Next();
|
||||
_ = gbm.Next();
|
||||
}
|
||||
|
||||
// GBM should not expose any history storage
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace QuanTAlib;
|
||||
/// </summary>
|
||||
[SkipLocalsInit]
|
||||
#pragma warning disable S101 // Rename class 'GBM' to match pascal case naming rules
|
||||
#pragma warning disable S2245 // Random is acceptable for simulation/testing purposes
|
||||
public class GBM : IFeed
|
||||
#pragma warning restore S101
|
||||
{
|
||||
@@ -82,10 +83,8 @@ public class GBM : IFeed
|
||||
return _cachedZ;
|
||||
}
|
||||
|
||||
#pragma warning disable S2245 // Random is acceptable for simulation/testing purposes
|
||||
double u1 = 1.0 - _rnd.NextDouble();
|
||||
double u2 = 1.0 - _rnd.NextDouble();
|
||||
#pragma warning restore S2245
|
||||
double u1 = 1.0 - _rnd.NextDouble(); // nosemgrep
|
||||
double u2 = 1.0 - _rnd.NextDouble(); // nosemgrep
|
||||
double mag = Math.Sqrt(-2.0 * Math.Log(u1));
|
||||
double angle = 2.0 * Math.PI * u2;
|
||||
|
||||
@@ -190,11 +189,9 @@ public class GBM : IFeed
|
||||
double open = currentPrice;
|
||||
double close = price;
|
||||
|
||||
#pragma warning disable S2245 // Random is acceptable for simulation/testing purposes
|
||||
double rnd1 = _rnd.NextDouble();
|
||||
double rnd2 = _rnd.NextDouble();
|
||||
double rnd3 = _rnd.NextDouble();
|
||||
#pragma warning restore S2245
|
||||
|
||||
t[i] = currentTime;
|
||||
o[i] = open;
|
||||
|
||||
Reference in New Issue
Block a user