From 931bbdb6a0e0694d8c57cd8e82ab48c600dda59c Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Tue, 8 Oct 2024 09:49:28 -0700 Subject: [PATCH] pull request changes --- .github/workflows/Publish.yml | 15 +++++------ Tests/Tests.csproj | 2 +- Tests/test_eventing.cs | 2 ++ Tests/test_skender.stock.cs | 9 +++---- lib/averages/Rma.cs | 51 +++++++++++++++++------------------ 5 files changed, 38 insertions(+), 41 deletions(-) diff --git a/.github/workflows/Publish.yml b/.github/workflows/Publish.yml index 094cd6e0..c6cc6d3d 100644 --- a/.github/workflows/Publish.yml +++ b/.github/workflows/Publish.yml @@ -26,8 +26,7 @@ jobs: - name: Setup .NET SDK uses: actions/setup-dotnet@v3 with: - dotnet-version: '9.x' - dotnet-quality: 'preview' + dotnet-version: '8.x' - name: Install JDK11 for Sonar Scanner uses: actions/setup-java@v3 @@ -80,8 +79,7 @@ jobs: - name: Setup .NET SDK uses: actions/setup-dotnet@v3 with: - dotnet-version: '9.x' - dotnet-quality: 'preview' + dotnet-version: '8.x' - name: Install dotnet tools run: | @@ -136,8 +134,7 @@ jobs: - name: Setup .NET SDK uses: actions/setup-dotnet@v3 with: - dotnet-version: '9.x' - dotnet-quality: 'preview' + dotnet-version: '8.x' - name: Initialize CodeQL uses: github/codeql-action/init@v3 @@ -153,6 +150,7 @@ jobs: - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 +# converting SARIF action not working yet. #SecurityCodeScan: # runs-on: windows-latest # steps: @@ -171,7 +169,7 @@ jobs: # uses: actions/setup-dotnet@v3 # with: # dotnet-version: | - # 9.x + # 8.x # 3.1.x # dotnet-quality: 'preview' # @@ -229,8 +227,7 @@ jobs: - name: Setup .NET SDK uses: actions/setup-dotnet@v3 with: - dotnet-version: '9.x' - dotnet-quality: 'preview' + dotnet-version: '8.x' - name: Install GitVersion uses: gittools/actions/gitversion/setup@v0 diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index dee01cd9..44158e8a 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -33,7 +33,7 @@ - + diff --git a/Tests/test_eventing.cs b/Tests/test_eventing.cs index 832d990c..3c0e8aa6 100644 --- a/Tests/test_eventing.cs +++ b/Tests/test_eventing.cs @@ -1,3 +1,5 @@ +using Xunit; + namespace QuanTAlib; public class EventingTests diff --git a/Tests/test_skender.stock.cs b/Tests/test_skender.stock.cs index 09ef7ad7..2b8a2659 100644 --- a/Tests/test_skender.stock.cs +++ b/Tests/test_skender.stock.cs @@ -289,7 +289,6 @@ public class SkenderTests { for (int run = 0; run < iterations; run++) { - //period = rnd.Next(50) + 5; Mama ma = new(fastLimit: 0.5, slowLimit: 0.05); TSeries QL = new(); foreach (TBar item in feed) @@ -336,12 +335,12 @@ public class SkenderTests TSeries QL = new(); foreach (TBar item in bars) { QL.Add(ma.Calc(item)); } - var SK = quotes.GetAtr(lookbackPeriods: period).Select(i => i.Atr.Null2NaN()!); - Assert.Equal(QL.Length, QL.Length); + var atrValues = quotes.GetAtr(lookbackPeriods: period).Select(i => i.Atr.Null2NaN()!); + const int AdditionalPeriods = 500; - for (int i = QL.Length - 1; i > period + 500; i--) + for (int i = QL.Length - 1; i > period + AdditionalPeriods; i--) { - Assert.InRange(SK.ElementAt(i) - QL[i].Value, -range, range); + Assert.InRange(atrValues.ElementAt(i) - QL[i].Value, -range, range); } } } diff --git a/lib/averages/Rma.cs b/lib/averages/Rma.cs index b6255690..28bad44b 100644 --- a/lib/averages/Rma.cs +++ b/lib/averages/Rma.cs @@ -22,54 +22,53 @@ public class Rma : AbstractBase _alpha = 1.0 / _period; // Wilder's smoothing factor Name = $"Rma({_period})"; Init(); - } + } - public Rma(object source, int period) : this(period) - { + public Rma(object source, int period) : this(period) + { var pubEvent = source.GetType().GetEvent("Pub"); pubEvent?.AddEventHandler(source, new ValueSignal(Sub)); - } + } - public override void Init() - { + public override void Init() + { base.Init(); _lastRMA = 0; _savedLastRMA = 0; - } - - protected override void ManageState(bool isNew) - { - if (isNew) - { - _savedLastRMA = _lastRMA; - _lastValidValue = Input.Value; - _index++; } - else + + protected override void ManageState(bool isNew) + { + if (!isNew) { _lastRMA = _savedLastRMA; + return; } - } - protected override double Calculation() - { + _savedLastRMA = _lastRMA; + _lastValidValue = Input.Value; + _index++; + } + + protected override double Calculation() + { ManageState(Input.IsNew); double rma; if (_index == 1) { - rma = Input.Value; + return Input.Value; } - else if (_index <= _period) + + if (_index <= _period) { // Simple average during initial period - rma = (_lastRMA * (_index - 1) + Input.Value) / _index; + return (_lastRMA * (_index - 1) + Input.Value) / _index; } - else - { - // Wilder's smoothing method - rma = _alpha * (Input.Value - _lastRMA) + _lastRMA; + + // Wilder's smoothing method + return _alpha * (Input.Value - _lastRMA) + _lastRMA; } _lastRMA = rma;