mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 19:48:05 +00:00
- Implemented Aroon Indicator with constructor, initialization, and update methods. - Added unit tests for AroonIndicator to verify default settings, historical depth, short name, source code link, and processing of historical bars. - Created Aroon class for core calculations, including methods for updating with TBar and TBarSeries. - Added validation tests to ensure Aroon calculations match results from Skender and TA-Lib. - Updated documentation for Aroon Indicator with calculation methods and usage examples. - Refactored Dema and Wma classes to use Batch methods for calculations. - Enhanced performance benchmarks by increasing bar count and integrating OoplesFinance indicators. - Updated project dependencies to include OoplesFinance.StockIndicators.
95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Skender.Stock.Indicators;
|
|
using TALib;
|
|
using Xunit;
|
|
using QuanTAlib.Tests;
|
|
|
|
namespace QuanTAlib;
|
|
|
|
public sealed class AroonValidationTests : IDisposable
|
|
{
|
|
private readonly ValidationTestData _data;
|
|
|
|
public AroonValidationTests()
|
|
{
|
|
_data = new ValidationTestData();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_data.Dispose();
|
|
}
|
|
|
|
[Fact]
|
|
public void MatchesSkender()
|
|
{
|
|
var aroon = new Aroon(14);
|
|
var results = new List<double>();
|
|
var upResults = new List<double>();
|
|
var downResults = new List<double>();
|
|
|
|
for (int i = 0; i < _data.Bars.Count; i++)
|
|
{
|
|
var res = aroon.Update(_data.Bars[i]);
|
|
results.Add(res.Value);
|
|
upResults.Add(aroon.Up.Value);
|
|
downResults.Add(aroon.Down.Value);
|
|
}
|
|
|
|
var skenderResults = _data.SkenderQuotes.GetAroon(14).ToList();
|
|
|
|
// Verify Oscillator
|
|
ValidationHelper.VerifyData(results, skenderResults, x => x.Oscillator);
|
|
|
|
// Verify Up
|
|
ValidationHelper.VerifyData(upResults, skenderResults, x => x.AroonUp);
|
|
|
|
// Verify Down
|
|
ValidationHelper.VerifyData(downResults, skenderResults, x => x.AroonDown);
|
|
}
|
|
|
|
[Fact]
|
|
public void MatchesTalib()
|
|
{
|
|
var aroon = new Aroon(14);
|
|
var results = new List<double>();
|
|
var upResults = new List<double>();
|
|
var downResults = new List<double>();
|
|
|
|
for (int i = 0; i < _data.Bars.Count; i++)
|
|
{
|
|
var res = aroon.Update(_data.Bars[i]);
|
|
results.Add(res.Value);
|
|
upResults.Add(aroon.Up.Value);
|
|
downResults.Add(aroon.Down.Value);
|
|
}
|
|
|
|
double[] hData = _data.Bars.High.Select(x => x.Value).ToArray();
|
|
double[] lData = _data.Bars.Low.Select(x => x.Value).ToArray();
|
|
double[] outAroonUp = new double[_data.Bars.Count];
|
|
double[] outAroonDown = new double[_data.Bars.Count];
|
|
double[] outAroonOsc = new double[_data.Bars.Count];
|
|
|
|
// TA-Lib Aroon (Up/Down)
|
|
var retCode = TALib.Functions.Aroon(hData, lData, 0..^0, outAroonDown, outAroonUp, out var outRange, 14);
|
|
Assert.Equal(Core.RetCode.Success, retCode);
|
|
|
|
// TA-Lib AroonOsc
|
|
var retCodeOsc = TALib.Functions.AroonOsc(hData, lData, 0..^0, outAroonOsc, out var outRangeOsc, 14);
|
|
Assert.Equal(Core.RetCode.Success, retCodeOsc);
|
|
|
|
int lookback = TALib.Functions.AroonLookback(14);
|
|
|
|
// Verify Up
|
|
ValidationHelper.VerifyData(upResults, outAroonUp, outRange, lookback);
|
|
|
|
// Verify Down
|
|
ValidationHelper.VerifyData(downResults, outAroonDown, outRange, lookback);
|
|
|
|
// Verify Oscillator
|
|
ValidationHelper.VerifyData(results, outAroonOsc, outRangeOsc, lookback);
|
|
}
|
|
}
|