mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-13 08:08:05 +00:00
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat> Co-authored-by: Warp <agent@warp.dev>
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
|
|
namespace QuanTAlib.Tests;
|
|
|
|
public class JmaValidationTests
|
|
{
|
|
[Fact]
|
|
public void Jma_FollowsPriceTrend()
|
|
{
|
|
// JMA should generally follow the price.
|
|
// If price goes up, JMA should eventually go up.
|
|
|
|
var jma = new Jma(10);
|
|
double previousJma = 0;
|
|
|
|
// Uptrend
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
var result = jma.Update(new TValue(DateTime.UtcNow, i));
|
|
if (i > 20) // Allow warmup
|
|
{
|
|
Assert.True(result.Value > previousJma, $"JMA should be increasing in uptrend at step {i}");
|
|
}
|
|
previousJma = result.Value;
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Jma_WithinBounds()
|
|
{
|
|
// JMA should stay within the range of recent prices (roughly)
|
|
// It's a moving average, so it shouldn't overshoot wildly unless phase is negative and high volatility?
|
|
// With default phase 0, it should be well behaved.
|
|
|
|
var jma = new Jma(10);
|
|
var gbm = new GBM(startPrice: 100, mu: 0, sigma: 0.5);
|
|
|
|
for (int i = 0; i < 1000; i++)
|
|
{
|
|
var bar = gbm.Next(isNew: true);
|
|
var result = jma.Update(new TValue(bar.Time, bar.Close));
|
|
|
|
if (i > 20)
|
|
{
|
|
// Update bounds of recent price history (simplified)
|
|
// This is a loose check.
|
|
// Just check it's finite and positive for this GBM
|
|
Assert.True(double.IsFinite(result.Value));
|
|
Assert.True(result.Value > 0);
|
|
}
|
|
}
|
|
}
|
|
}
|