-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
859 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Xunit; | ||
using System.Security.Cryptography; | ||
|
||
namespace QuanTAlib.Tests; | ||
|
||
public class MomentumUpdateTests | ||
{ | ||
private readonly RandomNumberGenerator rng = RandomNumberGenerator.Create(); | ||
private const int RandomUpdates = 100; | ||
private const double ReferenceValue = 100.0; | ||
private const int precision = 8; | ||
|
||
private double GetRandomDouble() | ||
{ | ||
byte[] bytes = new byte[8]; | ||
rng.GetBytes(bytes); | ||
return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 | ||
} | ||
|
||
private TBar GetRandomBar(bool IsNew) | ||
{ | ||
double open = GetRandomDouble(); | ||
double high = open + Math.Abs(GetRandomDouble()); | ||
double low = open - Math.Abs(GetRandomDouble()); | ||
double close = low + (high - low) * GetRandomDouble(); | ||
return new TBar(DateTime.Now, open, high, low, close, 1000, IsNew); | ||
} | ||
|
||
[Fact] | ||
public void Adx_Update() | ||
{ | ||
var indicator = new Adx(period: 14); | ||
TBar r = GetRandomBar(true); | ||
double initialValue = indicator.Calc(r); | ||
|
||
for (int i = 0; i < RandomUpdates; i++) | ||
{ | ||
indicator.Calc(GetRandomBar(IsNew: false)); | ||
} | ||
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false)); | ||
|
||
Assert.Equal(initialValue, finalValue, precision); | ||
} | ||
|
||
[Fact] | ||
public void Adxr_Update() | ||
{ | ||
var indicator = new Adxr(period: 14); | ||
TBar r = GetRandomBar(true); | ||
double initialValue = indicator.Calc(r); | ||
|
||
for (int i = 0; i < RandomUpdates; i++) | ||
{ | ||
indicator.Calc(GetRandomBar(IsNew: false)); | ||
} | ||
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false)); | ||
|
||
Assert.Equal(initialValue, finalValue, precision); | ||
} | ||
|
||
[Fact] | ||
public void Apo_Update() | ||
{ | ||
var indicator = new Apo(fastPeriod: 12, slowPeriod: 26); | ||
double initialValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: true)); | ||
|
||
for (int i = 0; i < RandomUpdates; i++) | ||
{ | ||
indicator.Calc(new TValue(DateTime.Now, GetRandomDouble(), IsNew: false)); | ||
} | ||
double finalValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: false)); | ||
|
||
Assert.Equal(initialValue, finalValue, precision); | ||
} | ||
|
||
[Fact] | ||
public void Dmi_Update() | ||
{ | ||
var indicator = new Dmi(period: 14); | ||
TBar r = GetRandomBar(true); | ||
double initialValue = indicator.Calc(r); | ||
|
||
for (int i = 0; i < RandomUpdates; i++) | ||
{ | ||
indicator.Calc(GetRandomBar(IsNew: false)); | ||
} | ||
double finalValue = indicator.Calc(new TBar(r.Time, r.Open, r.High, r.Low, r.Close, r.Volume, IsNew: false)); | ||
|
||
Assert.Equal(initialValue, finalValue, precision); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Xunit; | ||
using System.Security.Cryptography; | ||
|
||
namespace QuanTAlib.Tests; | ||
|
||
public class OscillatorsUpdateTests | ||
{ | ||
private readonly RandomNumberGenerator rng = RandomNumberGenerator.Create(); | ||
private const int RandomUpdates = 100; | ||
private const double ReferenceValue = 100.0; | ||
private const int precision = 8; | ||
|
||
private double GetRandomDouble() | ||
{ | ||
byte[] bytes = new byte[8]; | ||
rng.GetBytes(bytes); | ||
return (double)BitConverter.ToUInt64(bytes, 0) / ulong.MaxValue * 200 - 100; // Range: -100 to 100 | ||
} | ||
|
||
[Fact] | ||
public void Rsi_Update() | ||
{ | ||
var indicator = new Rsi(period: 14); | ||
double initialValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: true)); | ||
|
||
for (int i = 0; i < RandomUpdates; i++) | ||
{ | ||
indicator.Calc(new TValue(DateTime.Now, GetRandomDouble(), IsNew: false)); | ||
} | ||
double finalValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: false)); | ||
|
||
Assert.Equal(initialValue, finalValue, precision); | ||
} | ||
|
||
[Fact] | ||
public void Rsx_Update() | ||
{ | ||
var indicator = new Rsx(period: 14); | ||
double initialValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: true)); | ||
|
||
for (int i = 0; i < RandomUpdates; i++) | ||
{ | ||
indicator.Calc(new TValue(DateTime.Now, GetRandomDouble(), IsNew: false)); | ||
} | ||
double finalValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: false)); | ||
|
||
Assert.Equal(initialValue, finalValue, precision); | ||
} | ||
|
||
[Fact] | ||
public void Cmo_Update() | ||
{ | ||
var indicator = new Cmo(period: 14); | ||
double initialValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: true)); | ||
|
||
for (int i = 0; i < RandomUpdates; i++) | ||
{ | ||
indicator.Calc(new TValue(DateTime.Now, GetRandomDouble(), IsNew: false)); | ||
} | ||
double finalValue = indicator.Calc(new TValue(DateTime.Now, ReferenceValue, IsNew: false)); | ||
|
||
Assert.Equal(initialValue, finalValue, precision); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.