mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08:05 +00:00
feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
This commit is contained in:
@@ -664,6 +664,36 @@ public class GBMTests
|
||||
Assert.False(gbm.HasCurrentBar);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GBM_FetchThenNext_PriceContinuity()
|
||||
{
|
||||
var gbm = new GBM(startPrice: 100.0, seed: 42);
|
||||
long startTime = new DateTime(2024, 1, 1, 9, 30, 0, DateTimeKind.Utc).Ticks;
|
||||
var interval = TimeSpan.FromMinutes(1);
|
||||
|
||||
var series = gbm.Fetch(5, startTime, interval);
|
||||
double lastBatchClose = series[4].Close;
|
||||
|
||||
// Next bar after Fetch must open at the last batch close (price continuity)
|
||||
var nextBar = gbm.Next(isNew: true);
|
||||
Assert.Equal(lastBatchClose, nextBar.Open, 1e-10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GBM_NextThenFetch_PriceContinuity()
|
||||
{
|
||||
var gbm = new GBM(startPrice: 100.0, seed: 42);
|
||||
|
||||
_ = gbm.Next(isNew: true);
|
||||
var bar2 = gbm.Next(isNew: true); // _lastPrice = bar2.Close
|
||||
|
||||
long startTime = bar2.Time + TimeSpan.FromMinutes(1).Ticks;
|
||||
var series = gbm.Fetch(3, startTime, TimeSpan.FromMinutes(1));
|
||||
|
||||
// First bar of Fetch must open at bar2.Close
|
||||
Assert.Equal(bar2.Close, series[0].Open, 1e-10);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IFeed Interface Tests
|
||||
|
||||
@@ -120,6 +120,10 @@ public sealed class GBM : IFeed
|
||||
/// <summary>
|
||||
/// Resets the generator to its initial state.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sets the internal time anchor to <see cref="DateTime.UtcNow"/>. For deterministic
|
||||
/// time sequences use <see cref="Reset(long)"/> with an explicit start time.
|
||||
/// </remarks>
|
||||
public void Reset()
|
||||
{
|
||||
_lastPrice = StartPrice;
|
||||
@@ -284,6 +288,15 @@ public sealed class GBM : IFeed
|
||||
/// <returns>A TBarSeries containing the generated bars</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when count is not positive</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when interval is not positive</exception>
|
||||
/// <remarks>
|
||||
/// Price continuity: <c>batch[0].Open</c> equals <c>_lastPrice</c> at call time, so the
|
||||
/// batch begins exactly where the previous <see cref="Next(bool)"/> call left off.
|
||||
/// After the call, <c>_lastPrice</c> and <c>_lastTime</c> are updated to the end of the
|
||||
/// generated batch, enabling seamless continuation via subsequent <see cref="Next(bool)"/>
|
||||
/// calls. <paramref name="startTime"/> need not follow the previous <c>_lastTime</c> —
|
||||
/// this allows replaying a window or generating a non-contiguous batch while preserving
|
||||
/// price continuity.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public TBarSeries Fetch(int count, long startTime, TimeSpan interval)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user