mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-19 11:08:05 +00:00
- Implemented the Standardize class for calculating Z-Score normalization over a specified lookback period. - Updated NDepend badge SVG files to reflect new metrics. - Modified NDepend project files to reference the updated solution file name. - Removed outdated documentation files related to indicator proposals and channel documentation remediation. - Updated workspace configuration to point to the new solution file.
109 lines
3.0 KiB
C#
109 lines
3.0 KiB
C#
using TradingPlatform.BusinessLayer;
|
|
using Xunit;
|
|
|
|
namespace QuanTAlib.Tests;
|
|
|
|
public class TsiIndicatorTests
|
|
{
|
|
[Fact]
|
|
public void Indicator_DefaultConstruction()
|
|
{
|
|
var indicator = new TsiIndicator();
|
|
Assert.NotNull(indicator);
|
|
Assert.Equal("TSI - True Strength Index", indicator.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_DefaultParameters()
|
|
{
|
|
var indicator = new TsiIndicator();
|
|
Assert.Equal(25, indicator.LongPeriod);
|
|
Assert.Equal(13, indicator.ShortPeriod);
|
|
Assert.Equal(13, indicator.SignalPeriod);
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_MinHistoryDepths()
|
|
{
|
|
// MinHistoryDepths is static
|
|
Assert.Equal(0, TsiIndicator.MinHistoryDepths);
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_CustomParameters()
|
|
{
|
|
var indicator = new TsiIndicator { LongPeriod = 20, ShortPeriod = 10, SignalPeriod = 7 };
|
|
Assert.Equal(20, indicator.LongPeriod);
|
|
Assert.Equal(10, indicator.ShortPeriod);
|
|
Assert.Equal(7, indicator.SignalPeriod);
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_UsesTsiCore()
|
|
{
|
|
var indicator = new TsiIndicator();
|
|
Assert.Equal(25, indicator.LongPeriod);
|
|
Assert.Equal(13, indicator.ShortPeriod);
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_CalculatesCorrectly()
|
|
{
|
|
var core = new Tsi(5, 3, 3);
|
|
|
|
// Feed rising prices
|
|
var prices = new double[] { 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
|
|
111, 112, 113, 114, 115, 116, 117, 118, 119, 120 };
|
|
|
|
foreach (var price in prices)
|
|
{
|
|
core.Update(new TValue(DateTime.Now, price));
|
|
}
|
|
|
|
// TSI should be positive for rising prices
|
|
Assert.True(core.Last.Value > 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_ShortName_ContainsParameters()
|
|
{
|
|
var indicator = new TsiIndicator { LongPeriod = 20, ShortPeriod = 10, SignalPeriod = 7 };
|
|
|
|
// ShortName is computed property, just verify it returns non-empty
|
|
Assert.NotNull(indicator.ShortName);
|
|
Assert.NotEmpty(indicator.ShortName);
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_HasSignalLine()
|
|
{
|
|
var core = new Tsi(5, 3, 3);
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
core.Update(new TValue(DateTime.Now.AddMinutes(i), 100.0 + i * 0.5));
|
|
}
|
|
|
|
// Signal property should return signal line value
|
|
Assert.True(!double.IsNaN(core.Signal));
|
|
}
|
|
|
|
[Fact]
|
|
public void Indicator_OutputBounded()
|
|
{
|
|
var core = new Tsi(5, 3, 3);
|
|
var random = new Random(42);
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
double price = 100.0 + random.NextDouble() * 50;
|
|
core.Update(new TValue(DateTime.Now.AddMinutes(i), price));
|
|
|
|
// TSI must be bounded [-100, 100]
|
|
Assert.True(core.Last.Value >= -100.0 && core.Last.Value <= 100.0);
|
|
// Signal must be bounded too
|
|
Assert.True(core.Signal >= -100.0 && core.Signal <= 100.0);
|
|
}
|
|
}
|
|
}
|