Skip to content

Commit

Permalink
Jvolty
Browse files Browse the repository at this point in the history
  • Loading branch information
mihakralj committed Oct 14, 2024
1 parent ffed649 commit ee015e6
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 96 deletions.
109 changes: 16 additions & 93 deletions .github/workflows/Publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,6 @@ permissions:
security-events: write # Required for CodeQL analysis and uploading SARIF results

jobs:
SonarCloud:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'

- name: Install JDK11 for Sonar Scanner
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'zulu'

- name: Install dotnet-sonarscanner
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install JetBrains.dotCover.GlobalTool --global
dotnet tool install dotnet-coverage --global
dotnet restore
- name: SonarCloud Scanner Start
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
PR_PARAMS="/d:sonar.pullrequest.key=${{ github.event.pull_request.number }} \
/d:sonar.pullrequest.branch=${{ github.head_ref }} \
/d:sonar.pullrequest.base=${{ github.base_ref }}"
elif [[ ${{ github.event_name }} == 'push' ]]; then
BRANCH_PARAMS="/d:sonar.branch.name=${{ github.ref_name }}"
else
BRANCH_PARAMS="/d:sonar.branch.name=${{ github.ref_name }}"
fi
dotnet sonarscanner begin \
/k:"mihakralj_QuanTAlib" \
/o:"mihakralj" \
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.cs.dotcover.reportsPaths=dotcover* \
/d:sonar.scanner.scanAll=false \
/d:sonar.scm.provider=git \
$PR_PARAMS $BRANCH_PARAMS
- name: Build
run: |
dotnet build --no-restore --configuration Debug
dotnet build ./lib/quantalib.csproj --configuration Release --nologo
dotnet build ./quantower/Averages/_Averages.csproj --configuration Release --nologo
dotnet build ./quantower/Statistics/_Statistics.csproj --configuration Release --nologo
dotnet build ./quantower/Volatility/_Volatility.csproj --configuration Release --nologo
dotnet build ./SyntheticVendor/SyntheticVendor.csproj --configuration Release --nologo
dotnet dotcover test Tests/Tests.csproj --dcReportType=HTML --dcoutput=./dotcover.html
- name: SonarCloud Scanner End
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

Code_Coverage:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -160,9 +94,24 @@ jobs:
- name: Build
run: dotnet build --no-restore --configuration Debug

- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@v4
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
gh-code-scanning-compat: true
max-allowed-issues: 2147483647

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif


SecurityCodeScan:
runs-on: windows-latest
Expand Down Expand Up @@ -200,35 +149,9 @@ jobs:
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3

Codacy_Scan:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@v4
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
gh-code-scanning-compat: true
max-allowed-issues: 2147483647

- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif

build_publish:
needs: [SonarCloud, Code_Coverage, CodeQL, Codacy_Scan, SecurityCodeScan]
needs: [Code_Coverage, CodeQL, SecurityCodeScan]
if: |
success() &&
(github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')) ||
Expand Down
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<InvariantGlobalization>true</InvariantGlobalization>
<MetadataUpdaterSupport>false</MetadataUpdaterSupport>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
</PropertyGroup>
<PropertyGroup>
<NoWarn>S1944,S2053,S2222,S2259,S2583,S2589,S3329,S3655,S3900,S3949,S3966,S4158,S4347,S5773,S6781</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
Expand Down
3 changes: 1 addition & 2 deletions Tests/test_iTBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;

#pragma warning disable S1944, S2053, S2222, S2259, S2583, S2589, S3329, S3655, S3900, S3949, S3966, S4158, S4347, S5773, S6781

namespace QuanTAlib;

/// <summary>
Expand All @@ -27,6 +25,7 @@ public BarIndicatorTests()
private static readonly ITValue[] indicators = new ITValue[]
{
new Atr(period: 14),
new Jvolty(period: 14)
// Add other TBar-based indicators here
};

Expand Down
2 changes: 2 additions & 0 deletions Tests/test_quantower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class QuantowerTests

// Volatility Indicators
[Fact] public void Atr() => TestIndicator<AtrIndicator>("atr");
[Fact] public void Jvolty() => TestIndicator<JvoltyIndicator>("jvolty");

[Fact] public void Historical() => TestIndicator<HistoricalIndicator>("historical");
[Fact] public void Realized() => TestIndicator<RealizedIndicator>("realized");
[Fact] public void Rvi() => TestIndicator<RviIndicator>("rvi");
Expand Down
104 changes: 104 additions & 0 deletions Tests/test_updates_volatility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Xunit;
using System.Security.Cryptography;

namespace QuanTAlib.Tests;

public class VolatilityUpdateTests
{
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 Atr_Update()
{
var indicator = new Atr(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 Historical_Update()
{
var indicator = new Historical(period: 14);
double initialValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: true));

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(false));
}
double finalValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Jvolty_Update()
{
var indicator = new Jvolty(period: 14);
double initialValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: true));

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(false));
}
double finalValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Realized_Update()
{
var indicator = new Realized(period: 14);
double initialValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: true));

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(false));
}
double finalValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}

[Fact]
public void Rvi_Update()
{
var indicator = new Rvi(period: 14);
double initialValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: true));

for (int i = 0; i < RandomUpdates; i++)
{
indicator.Calc(GetRandomBar(false));
}
double finalValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: false));

Assert.Equal(initialValue, finalValue, precision);
}
}
Loading

0 comments on commit ee015e6

Please sign in to comment.