Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add inline comments, remove info.xml #1155

Draft
wants to merge 19 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions .github/workflows/deploy-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.x"
dotnet-quality: "ga"

- name: Setup GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
Expand All @@ -51,21 +57,8 @@ jobs:
- name: Compose version
id: compose
run: |
ver=${{ steps.gitversion.outputs.majorMinorPatch }}${{ inputs.preview && '-preview.' || '' }}${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || inputs.preview && github.run_number || '' }}
echo "version=$ver" >> "$GITHUB_OUTPUT"

- name: Update release notes URL
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "<PackageReleaseNotes>https://github.com/DaveSkender/Stock.Indicators/releases</PackageReleaseNotes>"
replace: "<PackageReleaseNotes>https://github.com/DaveSkender/Stock.Indicators/releases/tag/${{ steps.compose.outputs.version }}</PackageReleaseNotes>"
regex: false

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.x"
dotnet-quality: "ga"
composed_version=${{ steps.gitversion.outputs.majorMinorPatch }}${{ inputs.preview && '-preview.' || '' }}${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || inputs.preview && github.run_number || '' }}
echo "version=$composed_version" >> "$GITHUB_OUTPUT"

- name: Build library
run: >
Expand Down Expand Up @@ -100,7 +93,7 @@ jobs:
echo "| Minor | ${{ steps.gitversion.outputs.minor }} |"
echo "| Patch | ${{ steps.gitversion.outputs.patch }} |"
echo "| Base | ${{ steps.gitversion.outputs.majorMinorPatch }} |"
echo "| Composed | ${{ steps.compose.outputs.version }} |"
echo "| Composed | ${{ steps.compose.outputs.version }} |"
} >> $GITHUB_STEP_SUMMARY

deploy:
Expand Down
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"recommendations": [
"codacy-app.codacy",
"adrianwilczynski.user-secrets",
"github.vscode-github-actions",
"github.vscode-pull-request-github",
"mechatroner.rainbow-csv",
"dotjoshjohnson.xml",
"redhat.vscode-yaml",
"vunguyentuan.vscode-css-variables"
]
}
11 changes: 11 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See ROOT for primary .editorconfig
# This is only for minor SRC overrides.
root = false

# Be careful of automatically added values from IDE.
# Add between "# HUMANS markers to differentiate intent.

[*.cs]
#HUMANS
dotnet_diagnostic.CS1591.severity=suggestion
#ENDHUMANS
26 changes: 8 additions & 18 deletions src/Indicators.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;</TargetFrameworks>

<Authors>Dave Skender</Authors>
<Product>Stock Indicators for .NET</Product>
<Copyright>@2020 Dave Skender</Copyright>
<Description>Stock Indicators for .NET. Transform financial market price quotes into technical analysis indicators such as MACD, Stochastic RSI, Average True Range, Parabolic SAR, etc. Nothing more.</Description>
<Description>Transform financial market price data into technical analysis indicators such as MACD, Stochastic RSI, Average true Range, Parabolic SAR, and more.</Description>

<RepositoryUrl>https://github.com/DaveSkender/Stock.Indicators</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -22,19 +22,9 @@
<PackageProjectUrl>https://dotnet.stockindicators.dev</PackageProjectUrl>
<PackageId>Skender.Stock.Indicators</PackageId>
<PackageTags>
Indicators;Stock;Market;Technical;Analysis;Algorithmic;Trading;Trade;Trend;Momentum;Finance;Algorithm;Algo;
AlgoTrading;Financial;Strategy;Chart;Charting;Oscillator;Overlay;Equity;Bitcoin;Crypto;Cryptocurrency;Forex;
Quantitative;Historical;Quotes;Accumulation;Distribution;ADL;Aroon;True;Range;ATR;Bollinger;Bands;Commodity;
CCI;Chandelier;Exit;Chaikin;Money;Flow;CMF;MFI;Kaufman;Adaptive;Simple;Weighted;Exponential;Moving;Average;
Convergence;Divergence;MACD;SMA;EMA;DEMA;TEMA;TRIX;Smoothed;Elder-ray;Bull;Bear;Power;Force;Hurst;Exponent;
Relative;Strength;Index;RSI;ConnorsRSI;Stochastic;Directional;Movement;ADX;Donchian;Keltner;Channel;
Heikin-Ashi;Hilbert;Transform;Instantaneous;Trendline;Hull;HMA;Ichimoku;Cloud;On-balance;Volume;OBV;
Price;PMO;PRS;Parabolic;SAR;Stop;Reverse;PSAR;Pivot;Points;Rate;Change;ROC;Linear;Regression;R-Squared;Renko;
Schaff;Cycle;Slope;Standard;Deviation;Beta;Convexity;Correlation;SuperTrend;Ulcer;Ultimate;Vortex;Williams;%R;
Alligator;Gator;Fractal;Chaos;Choppiness;Endpoint;WMA;ZigZag;.NET;C#;Library;Package;
Stock;Market;Indicators;Technical;Analysis;Algorithmic;Trading;Trade;Finance;
</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>https://github.com/DaveSkender/Stock.Indicators/releases</PackageReleaseNotes>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageIcon>icon.png</PackageIcon>

Expand All @@ -53,24 +43,24 @@
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<SignAssembly>True</SignAssembly>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
<Pack>true</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\LICENSE">
<Pack>True</Pack>
<Pack>true</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\NOTICE">
<Pack>True</Pack>
<Pack>true</Pack>
<PackagePath></PackagePath>
</None>
<None Include="icon.png">
<Pack>True</Pack>
<Pack>true</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
Expand Down
18 changes: 16 additions & 2 deletions src/_common/BinarySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ public readonly struct BinarySettings(
byte settings,
byte mask = 0b11111111) : IEquatable<BinarySettings>
{
/// <summary>
/// Gets the binary settings.
/// </summary>
public byte Settings { get; } = settings;

/// <summary>
/// Gets the mask for settings inheritance.
/// </summary>
public byte Mask { get; } = mask;

// use default settings (none) and mask
// important: this explicit parameterless ctor required for struct
/// <summary>
/// Initializes a new instance of the <see cref="BinarySettings"/> struct
/// with default settings (0b00000000) and mask (0b11111111).
/// </summary>
public BinarySettings() : this(settings: 0b00000000) { }

/// <summary>
Expand Down Expand Up @@ -93,18 +102,23 @@ public BinarySettings Combine(BinarySettings parentSettings)
return new BinarySettings((byte)(Settings | maskedParentSettings), parentSettings.Mask);
}

/// <inheritdoc/>
public override bool Equals(object? obj)
=> obj is BinarySettings other && Equals(other);

/// <inheritdoc/>
public bool Equals(BinarySettings other)
=> Settings == other.Settings && Mask == other.Mask;

/// <inheritdoc/>
public override int GetHashCode()
=> HashCode.Combine(Settings, Mask);

/// <inheritdoc/>
public static bool operator ==(BinarySettings left, BinarySettings right)
=> left.Equals(right);

/// <inheritdoc/>
public static bool operator !=(BinarySettings left, BinarySettings right)
=> !(left == right);
}
Expand Down
77 changes: 74 additions & 3 deletions src/_common/Candles/Candles.Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ namespace Skender.Stock.Indicators;

// CANDLESTICK MODELS

/// <summary>
/// Represents the properties of a candlestick.
/// </summary>
/// <param name="Timestamp">The timestamp of the candlestick.</param>
/// <param name="Open">The opening price of the candlestick.</param>
/// <param name="High">The highest price of the candlestick.</param>
/// <param name="Low">The lowest price of the candlestick.</param>
/// <param name="Close">The closing price of the candlestick.</param>
/// <param name="Volume">The volume of the candlestick.</param>
[Serializable]
public record CandleProperties
(
Expand All @@ -13,25 +22,65 @@ public record CandleProperties
decimal Volume
) : Quote(Timestamp, Open, High, Low, Close, Volume)
{
// raw sizes
/// <summary>
/// Gets the size of the candlestick.
/// </summary>
public decimal? Size => High - Low;

/// <summary>
/// Gets the body size of the candlestick.
/// </summary>
public decimal? Body => Open > Close ? Open - Close : Close - Open;

/// <summary>
/// Gets the size of the upper wick of the candlestick.
/// </summary>
public decimal? UpperWick => High - (Open > Close ? Open : Close);

/// <summary>
/// Gets the size of the lower wick of the candlestick.
/// </summary>
public decimal? LowerWick => (Open > Close ? Close : Open) - Low;

// percent sizes
/// <summary>
/// Gets the body size as a percentage of the total size.
/// </summary>
public double? BodyPct => Size != 0 ? (double?)(Body / Size) : 1;

/// <summary>
/// Gets the upper wick size as a percentage of the total size.
/// </summary>
public double? UpperWickPct => Size != 0 ? (double?)(UpperWick / Size) : 1;

/// <summary>
/// Gets the lower wick size as a percentage of the total size.
/// </summary>
public double? LowerWickPct => Size != 0 ? (double?)(LowerWick / Size) : 1;

// directional info
/// <summary>
/// Gets a value indicating whether the candlestick is bullish.
/// </summary>
public bool IsBullish => Close > Open;

/// <summary>
/// Gets a value indicating whether the candlestick is bearish.
/// </summary>
public bool IsBearish => Close < Open;
}

/// <summary>
/// Represents the result of a candlestick analysis.
/// </summary>
[Serializable]
public record CandleResult : ISeries
{
/// <summary>
/// Initializes a new instance of the <see cref="CandleResult"/> record.
/// </summary>
/// <param name="timestamp">The timestamp of the result.</param>
/// <param name="quote">The quote used for the analysis.</param>
/// <param name="match">The match result of the analysis.</param>
/// <param name="price">The price associated with the result.</param>
public CandleResult(
DateTime timestamp,
IQuote quote,
Expand All @@ -44,6 +93,13 @@ public CandleResult(
Candle = quote.ToCandle();
}

/// <summary>
/// Initializes a new instance of the <see cref="CandleResult"/> record.
/// </summary>
/// <param name="timestamp">The timestamp of the result.</param>
/// <param name="candle">The candlestick properties.</param>
/// <param name="match">The match result of the analysis.</param>
/// <param name="price">The price associated with the result.</param>
public CandleResult(
DateTime timestamp,
CandleProperties candle,
Expand All @@ -56,8 +112,23 @@ public CandleResult(
Candle = candle;
}

/// <summary>
/// Gets the timestamp of the result.
/// </summary>
public DateTime Timestamp { get; init; }

/// <summary>
/// Gets the price associated with the result.
/// </summary>
public decimal? Price { get; init; }

/// <summary>
/// Gets the match result of the analysis.
/// </summary>
public Match Match { get; init; }

/// <summary>
/// Gets the candlestick properties.
/// </summary>
public CandleProperties Candle { get; init; }
}
23 changes: 21 additions & 2 deletions src/_common/Candles/Candles.Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
namespace Skender.Stock.Indicators;

public static partial class Utility
/// <summary>
/// Utility for candlestick data.
/// </summary>
public static class Candlesticks
{
/// <summary>
/// Condenses the list of candle results by filtering out those with no match.
/// </summary>
/// <param name="candleResults">The list of candle results to condense.</param>
/// <returns>A condensed list of candle results.</returns>
public static IReadOnlyList<CandleResult> Condense(
this IReadOnlyList<CandleResult> candleResults) => candleResults
.Where(candle => candle.Match != Match.None)
.ToList();

/// <summary>
/// Converts a quote to candle properties.
/// </summary>
/// <typeparam name="TQuote">The type of the quote.</typeparam>
/// <param name="quote">The quote to convert.</param>
/// <returns>The candle properties.</returns>
public static CandleProperties ToCandle<TQuote>(
this TQuote quote)
where TQuote : IQuote => new(
Expand All @@ -17,7 +31,12 @@ public static CandleProperties ToCandle<TQuote>(
Close: quote.Close,
Volume: quote.Volume);

// convert/sort quotes into candles list
/// <summary>
/// Converts and sorts a list of quotes into a list of candle properties.
/// </summary>
/// <typeparam name="TQuote">The type of the quote.</typeparam>
/// <param name="quotes">The list of quotes to convert.</param>
/// <returns>A sorted list of candle properties.</returns>
public static IReadOnlyList<CandleProperties> ToCandles<TQuote>(
this IReadOnlyList<TQuote> quotes)
where TQuote : IQuote => quotes
Expand Down
Loading