mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 19:48:05 +00:00
tests
This commit is contained in:
+13
-6
@@ -1,15 +1,15 @@
|
||||
using Xunit;
|
||||
using Tulip;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
[SuppressMessage("Security", "SCS0005:Weak random number generator.", Justification = "Acceptable for tests")]
|
||||
public class TulipTests
|
||||
{
|
||||
private readonly TBarSeries bars;
|
||||
private readonly GbmFeed feed;
|
||||
private readonly Random rnd;
|
||||
private readonly RandomNumberGenerator rng;
|
||||
private readonly double range;
|
||||
private readonly int iterations;
|
||||
private readonly double[] data;
|
||||
@@ -18,9 +18,8 @@ public class TulipTests
|
||||
|
||||
public TulipTests()
|
||||
{
|
||||
rnd = new((int)DateTime.Now.Ticks);
|
||||
rng = RandomNumberGenerator.Create();
|
||||
feed = new(sigma: 0.5, mu: 0.0);
|
||||
bars = new(feed);
|
||||
range = 1e-9;
|
||||
feed.Add(10000);
|
||||
iterations = 3;
|
||||
@@ -29,12 +28,20 @@ public class TulipTests
|
||||
outdata = new double[data.Count()];
|
||||
}
|
||||
|
||||
private int GetRandomNumber(int minValue, int maxValue)
|
||||
{
|
||||
byte[] randomBytes = new byte[4];
|
||||
rng.GetBytes(randomBytes);
|
||||
int randomInt = BitConverter.ToInt32(randomBytes, 0);
|
||||
return Math.Abs(randomInt % (maxValue - minValue)) + minValue;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SMA()
|
||||
{
|
||||
for (int run = 0; run < iterations; run++)
|
||||
{
|
||||
int period = rnd.Next(50) + 5;
|
||||
int period = GetRandomNumber(5, 55);
|
||||
Sma ma = new(period);
|
||||
TSeries QL = new();
|
||||
foreach (TBar item in feed)
|
||||
@@ -58,7 +65,7 @@ public class TulipTests
|
||||
{
|
||||
for (int run = 0; run < iterations; run++)
|
||||
{
|
||||
int period = rnd.Next(30) + 5;
|
||||
int period = GetRandomNumber(5, 35);
|
||||
Ema ma = new(period, useSma: false);
|
||||
TSeries QL = new();
|
||||
foreach (TBar item in feed)
|
||||
|
||||
Reference in New Issue
Block a user