mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-02 19:37:43 +00:00
chore: Update various indicators to improve null handling and code readability
This commit is contained in:
+3
-1
@@ -3,6 +3,8 @@ version = 1
|
||||
[[analyzers]]
|
||||
name = "csharp"
|
||||
enabled = true
|
||||
[analyzers.meta]
|
||||
skip_rules = ["CS-R1131"]
|
||||
|
||||
[[analyzers]]
|
||||
name = "test-coverage"
|
||||
@@ -14,4 +16,4 @@ enabled = true
|
||||
|
||||
[[transformers]]
|
||||
name = "dotnet-format"
|
||||
enabled = true
|
||||
enabled = true
|
||||
|
||||
@@ -147,6 +147,7 @@ QuanTAlib/
|
||||
```
|
||||
|
||||
Each indicator follows a consistent file pattern:
|
||||
|
||||
- `Indicator.cs` - Core implementation
|
||||
- `Indicator.Tests.cs` - Unit tests
|
||||
- `Indicator.Validation.Tests.cs` - Cross-validation with other libraries
|
||||
@@ -174,6 +175,7 @@ Apache License 2.0 - See [LICENSE](LICENSE) for details.
|
||||
## Contributing
|
||||
|
||||
Contributions welcome! Each indicator should include:
|
||||
|
||||
1. Core implementation with streaming support
|
||||
2. Unit tests covering edge cases
|
||||
3. Validation tests against reference libraries
|
||||
|
||||
@@ -118,7 +118,7 @@ public sealed class Alma : ITValuePublisher
|
||||
|
||||
public TSeries Update(TSeries source)
|
||||
{
|
||||
if (source.Count == 0) return new TSeries(new List<long>(), new List<double>());
|
||||
if (source.Count == 0) return new TSeries([], []);
|
||||
|
||||
int len = source.Count;
|
||||
var t = new List<long>(len);
|
||||
|
||||
@@ -75,7 +75,7 @@ public sealed class Hma : ITValuePublisher
|
||||
|
||||
public TSeries Update(TSeries source)
|
||||
{
|
||||
if (source.Count == 0) return new TSeries([], new List<double>());
|
||||
if (source.Count == 0) return new TSeries([], []);
|
||||
|
||||
int len = source.Count;
|
||||
var t = new List<long>(len);
|
||||
|
||||
@@ -157,7 +157,7 @@ public sealed class Kama : ITValuePublisher
|
||||
if (er > 1.0) er = 1.0;
|
||||
|
||||
double sc = er * (_fastAlpha - _slowAlpha) + _slowAlpha;
|
||||
sc = sc * sc;
|
||||
sc *= sc;
|
||||
|
||||
_kama = _p_kama + sc * (val - _p_kama);
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public sealed class Kama : ITValuePublisher
|
||||
|
||||
public TSeries Update(TSeries source)
|
||||
{
|
||||
if (source.Count == 0) return new TSeries(new List<long>(), new List<double>());
|
||||
if (source.Count == 0) return new TSeries([], []);
|
||||
|
||||
int len = source.Count;
|
||||
var t = new List<long>(len);
|
||||
|
||||
+2
-2
@@ -172,7 +172,7 @@ public sealed class T3 : ITValuePublisher
|
||||
|
||||
public TSeries Update(TSeries source)
|
||||
{
|
||||
if (source.Count == 0) return new TSeries(new List<long>(), new List<double>());
|
||||
if (source.Count == 0) return new TSeries();
|
||||
|
||||
int len = source.Count;
|
||||
var t = new List<long>(len);
|
||||
@@ -269,7 +269,7 @@ public sealed class T3 : ITValuePublisher
|
||||
double c4 = 1.0 + 3.0 * v + 3.0 * v2 + v3;
|
||||
|
||||
var p = new Parameters(alpha, c1, c2, c3, c4);
|
||||
State state = State.New();
|
||||
var state = State.New();
|
||||
double lastValidValue = 0;
|
||||
|
||||
CalculateCore(source, output, p, ref state, ref lastValidValue);
|
||||
|
||||
@@ -119,8 +119,8 @@ public static class IndicatorExtensions
|
||||
|
||||
public static List<Point> GetSmoothCurvePoints(Indicator indicator, IChartWindowCoordinatesConverter converter, Rectangle clientRect, LineSeries series)
|
||||
{
|
||||
if (indicator == null) throw new ArgumentNullException(nameof(indicator));
|
||||
if (converter == null) throw new ArgumentNullException(nameof(converter));
|
||||
ArgumentNullException.ThrowIfNull(indicator);
|
||||
ArgumentNullException.ThrowIfNull(converter);
|
||||
var data = indicator.HistoricalData;
|
||||
if (data == null) return new List<Point>();
|
||||
|
||||
@@ -193,8 +193,8 @@ public static class IndicatorExtensions
|
||||
|
||||
public static List<(Rectangle Rect, Color Color)> GetHistogramRectangles(Indicator indicator, IChartWindowCoordinatesConverter converter, Rectangle clientRect, LineSeries series)
|
||||
{
|
||||
if (indicator == null) throw new ArgumentNullException(nameof(indicator));
|
||||
if (converter == null) throw new ArgumentNullException(nameof(converter));
|
||||
ArgumentNullException.ThrowIfNull(indicator);
|
||||
ArgumentNullException.ThrowIfNull(converter);
|
||||
var data = indicator.HistoricalData;
|
||||
if (data == null) return new List<(Rectangle, Color)>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user