Skip to content

Commit

Permalink
feature: support .net exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
phmatray committed Nov 27, 2023
1 parent 767f1d9 commit 265d92d
Show file tree
Hide file tree
Showing 63 changed files with 447 additions and 858 deletions.
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@ To get started with TaLibStandard, you can clone the repository and explore the

## 📌 Features

* [x] Support for Double, Float, and Decimal data types, with the help of .NET's Generic Math
* [x] With some basic tests (coverage: >= 80%)
* [x] Support for Double, Float, and Decimal data types, with the help of .NET's Generic Math
* [x] With some basic tests (coverage: >= 80%)
* [x] .NET Exception handling (BREAKING CHANGE)

### Roadmap (next features)

* [ ] Comprehensive API documentation that is easy to understand
* [ ] High-Level API for common use cases
* [ ] Support for more data types
* [ ] Support for more functions
* [ ] .NET Exception handling (BREAKING CHANGE)
* [ ] More tests
* [ ] More examples
* [ ] Comprehensive API documentation that is easy to understand
* [ ] High-Level API for common use cases
* [ ] Support for more data types
* [ ] Support for more functions
* [ ] More tests
* [ ] More examples
* [ ] Add a Benchmark project
* [ ] Create a gRPC server to expose the library as a service

## 📄 Documentation

Expand Down Expand Up @@ -100,11 +102,11 @@ learn more about these features.

### 📦 NuGet Packages

| Package Name | NuGet Version Badge | NuGet Downloads Badge |
|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| Atypical.TechnicalAnalysis.Candles | [![NuGet](https://img.shields.io/nuget/v/Atypical.TechnicalAnalysis.Candles.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Candles) | [![NuGet](https://img.shields.io/nuget/dt/Atypical.TechnicalAnalysis.Candles.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Candles) |
| Atypical.TechnicalAnalysis.Functions | [![NuGet](https://img.shields.io/nuget/v/Atypical.TechnicalAnalysis.Functions.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Functions) | [![NuGet](https://img.shields.io/nuget/dt/Atypical.TechnicalAnalysis.Functions.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Functions) |
| Atypical.TechnicalAnalysis.Core | [![NuGet](https://img.shields.io/nuget/v/Atypical.TechnicalAnalysis.Common.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Common) | [![NuGet](https://img.shields.io/nuget/dt/Atypical.TechnicalAnalysis.Common.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Common) |
| Package Name | NuGet Version Badge | NuGet Downloads Badge | Package Explorer |
|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| Atypical.TechnicalAnalysis.Candles | [![NuGet](https://img.shields.io/nuget/v/Atypical.TechnicalAnalysis.Candles.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Candles) | [![NuGet](https://img.shields.io/nuget/dt/Atypical.TechnicalAnalysis.Candles.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Candles) | [Explore](https://nuget.info/packages/Atypical.TechnicalAnalysis.Candles) |
| Atypical.TechnicalAnalysis.Functions | [![NuGet](https://img.shields.io/nuget/v/Atypical.TechnicalAnalysis.Functions.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Functions) | [![NuGet](https://img.shields.io/nuget/dt/Atypical.TechnicalAnalysis.Functions.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Functions) | [Explore](https://nuget.info/packages/Atypical.TechnicalAnalysis.Functions) |
| Atypical.TechnicalAnalysis.Core | [![NuGet](https://img.shields.io/nuget/v/Atypical.TechnicalAnalysis.Common.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Common) | [![NuGet](https://img.shields.io/nuget/dt/Atypical.TechnicalAnalysis.Common.svg)](https://www.nuget.org/packages/Atypical.TechnicalAnalysis.Common) | [Explore](https://nuget.info/packages/Atypical.TechnicalAnalysis.Common) |

This table is automatically updated regularly the latest developments and releases in the Atypical Technical Analysis suite.

Expand Down Expand Up @@ -147,7 +149,12 @@ You can contact us by opening an issue on this repository.

## 📝 Release notes

(Add details of the version history, bug fixes, and new feature additions in each release here)
Here is a list of recent notable changes to TaLibStandard.

- dotnet 8.0 support
- Generic Math support
- .NET Exception handling
- NuGet packages

## 📜 License

Expand Down
32 changes: 19 additions & 13 deletions src/TechnicalAnalysis.Candles/Candle2Crows/Candle2Crows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ public class Candle2Crows<T>(in T[] open, in T[] high, in T[] low, in T[] close)
where T : IFloatingPoint<T>
{
private T _bodyLongPeriodTotal = T.Zero;

private void ValidateIndices(ref int startIdx, ref int endIdx)

Check warning on line 23 in src/TechnicalAnalysis.Candles/Candle2Crows/Candle2Crows.cs

View workflow job for this annotation

GitHub Actions / create_nuget

Private member 'Candle2Crows.ValidateIndices' is unused (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0051)
{
// Validate the requested output range.
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);
}

/// <summary>
/// Computes the <see cref="Candle2Crows{T}"/> indicator.
/// </summary>
Expand All @@ -34,21 +47,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
19 changes: 6 additions & 13 deletions src/TechnicalAnalysis.Candles/Candle3Inside/Candle3Inside.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
19 changes: 6 additions & 13 deletions src/TechnicalAnalysis.Candles/Candle3Outside/Candle3Outside.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,17 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx, in T optInPenetra
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}

if (optInPenetration < T.Zero)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Verify parameters
ArgumentOutOfRangeException.ThrowIfNegative(optInPenetration);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
19 changes: 6 additions & 13 deletions src/TechnicalAnalysis.Candles/CandleBeltHold/CandleBeltHold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,14 @@ public CandleIndicatorResult Compute(int startIdx, int endIdx)
int[] outInteger = new int[int.Max(0, endIdx - startIdx + 1)];

// Validate the requested output range.
if (startIdx < 0)
{
return new CandleIndicatorResult(OutOfRangeStartIndex, outBegIdx, outNBElement, outInteger);
}

if (endIdx < 0 || endIdx < startIdx)
{
return new CandleIndicatorResult(OutOfRangeEndIndex, outBegIdx, outNBElement, outInteger);
}
ArgumentOutOfRangeException.ThrowIfNegative(startIdx);
ArgumentOutOfRangeException.ThrowIfNegative(endIdx - startIdx);

// Verify required price component.
if (Open == null! || High == null! || Low == null! || Close == null!)
{
return new CandleIndicatorResult(BadParam, outBegIdx, outNBElement, outInteger);
}
ArgumentNullException.ThrowIfNull(Open);
ArgumentNullException.ThrowIfNull(High);
ArgumentNullException.ThrowIfNull(Low);
ArgumentNullException.ThrowIfNull(Close);

// Identify the minimum number of price bar needed to calculate at least one output.
int lookbackTotal = GetLookback();
Expand Down
Loading

0 comments on commit 265d92d

Please sign in to comment.