From 124cd2d00d47b1870194b6e4f68c8a517b7ab568 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Mon, 7 Nov 2022 21:01:49 -0800 Subject: [PATCH] github nuget publish Update main_automation.yml Update main_automation.yml Update main_automation.yml Update main_automation.yml more tests --- .github/workflows/main_automation.yml | 9 +--- Tests/Validations/Skender_Stock.cs | 72 +++++++++++++++++++++++++++ Tests/Validations/TA_LIB.cs | 58 +++++++++++++++++++-- 3 files changed, 126 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main_automation.yml b/.github/workflows/main_automation.yml index 99070ddc..cf67c903 100644 --- a/.github/workflows/main_automation.yml +++ b/.github/workflows/main_automation.yml @@ -87,16 +87,9 @@ jobs: title: "Latest Build" files: /Quantower/Settings/Scripts/Indicators/QuanTAlib/*.dll - - name: Push package to github - if: ${{ github.ref == 'refs/heads/main' }} - run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' - --api-key ${{ secrets.GITHUB_TOKEN }} - --source https://nuget.pkg.github.com/mihakralj/index.json - --skip-duplicate - - name: Push package to nuget.org if: ${{ github.ref == 'refs/heads/main' }} run: dotnet nuget push '.\Source\bin\Release\QuanTAlib.*.nupkg' --api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }} --source https://api.nuget.org/v3/index.json - --skip-duplicate \ No newline at end of file + --skip-duplicate diff --git a/Tests/Validations/Skender_Stock.cs b/Tests/Validations/Skender_Stock.cs index ad4ab415..7b383598 100644 --- a/Tests/Validations/Skender_Stock.cs +++ b/Tests/Validations/Skender_Stock.cs @@ -136,6 +136,15 @@ public class Skender_Stock } [Fact] + public void HMA() + { + HMA_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetHma(this.period); + + Assert.Equal(Math.Round((double)SK.Last().Hma!, 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] public void SMMA() { SMMA_Series QL = new(this.bars.Close, this.period, useNaN: false); @@ -172,6 +181,15 @@ public class Skender_Stock } [Fact] + public void SDEV() + { + SDEV_Series QL = new(this.bars.Close, this.period, useNaN: false); + var SK = this.quotes.GetStdDev(this.period); + + Assert.Equal(Math.Round((double)SK.Last().StdDev!, 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] public void LINREG() { LINREG_Series QL = new(this.bars.Close, this.period, useNaN: false); @@ -182,4 +200,58 @@ public class Skender_Stock Assert.Equal(Math.Round((double)SK.Last().RSquared!, 8), Math.Round(QL.RSquared.Last().v, 8)); Assert.Equal(Math.Round((double)SK.Last().StdDev!, 8), Math.Round(QL.StdDev.Last().v, 8)); } + + [Fact] + public void TR() + { + TR_Series QL = new(this.bars, useNaN: false); + var SK = this.quotes.GetTr(); + + Assert.Equal(Math.Round((double)SK.Last().Tr!, 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void HL2() + { + TSeries QL = this.bars.HL2; + var SK = this.quotes.GetBaseQuote(CandlePart.HL2); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void OC2() + { + TSeries QL = this.bars.OC2; + var SK = this.quotes.GetBaseQuote(CandlePart.OC2); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void HLC3() + { + TSeries QL = this.bars.HLC3; + var SK = this.quotes.GetBaseQuote(CandlePart.HLC3); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void OHL3() + { + TSeries QL = this.bars.OHL3; + var SK = this.quotes.GetBaseQuote(CandlePart.OHL3); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void OHLC4() + { + TSeries QL = this.bars.OHLC4; + var SK = this.quotes.GetBaseQuote(CandlePart.OHLC4); + + Assert.Equal(Math.Round((double)SK.Last().Value!, 8), Math.Round(QL.Last().v, 8)); + } } diff --git a/Tests/Validations/TA_LIB.cs b/Tests/Validations/TA_LIB.cs index 95372176..7c7ca807 100644 --- a/Tests/Validations/TA_LIB.cs +++ b/Tests/Validations/TA_LIB.cs @@ -10,6 +10,7 @@ public class TA_LIB private readonly Random rnd = new(); private readonly int period; private readonly double[] TALIB; + private readonly double[] inopen; private readonly double[] inhigh; private readonly double[] inlow; private readonly double[] inclose; @@ -20,6 +21,7 @@ public class TA_LIB this.bars = new(1000); this.period = this.rnd.Next(28) + 3; this.TALIB = new double[this.bars.Count]; + this.inopen = this.bars.Open.v.ToArray(); this.inhigh = this.bars.High.v.ToArray(); this.inlow = this.bars.Low.v.ToArray(); this.inclose = this.bars.Close.v.ToArray(); @@ -145,13 +147,59 @@ public class TA_LIB Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); } + [Fact] + public void TR() + { + TR_Series QL = new(this.bars, false); + Core.TRange(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); + } + [Fact] public void MACD() { - double[] macdSignal = new double[this.bars.Count]; - double[] macdHist = new double[this.bars.Count]; -MACD_Series QL = new(this.bars.Close, slow: 26, fast: 12, signal: 9, false); -Core.Macd(this.inclose, 0, this.bars.Count - 1, outMacd: this.TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _); -Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); + double[] macdSignal = new double[this.bars.Count]; + double[] macdHist = new double[this.bars.Count]; + MACD_Series QL = new(this.bars.Close, slow: 26, fast: 12, signal: 9, false); + Core.Macd(this.inclose, 0, this.bars.Count - 1, outMacd: this.TALIB, outMacdSignal: macdSignal, outMacdHist: macdHist, out int outBegIdx, out _); + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); } + + [Fact] + public void HL2() + { + TSeries QL = this.bars.HL2; + Core.MedPrice(this.inhigh, this.inlow, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void HLC3() + { + TSeries QL = this.bars.HLC3; + Core.TypPrice(this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void OHLC4() + { + TSeries QL = this.bars.OHLC4; + Core.AvgPrice(this.inopen, this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); + } + + [Fact] + public void HLCC4() + { + TSeries QL = this.bars.HLCC4; + Core.WclPrice( this.inhigh, this.inlow, this.inclose, 0, this.bars.Count - 1, this.TALIB, out int outBegIdx, out _); + + Assert.Equal(Math.Round(this.TALIB[this.TALIB.Length - outBegIdx - 1], 8), Math.Round(QL.Last().v, 8)); + } + }