mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
docs: remove C# Implementation Considerations sections, clean up temp scripts, reorganize test files
- Remove 'C# Implementation Considerations' sections from 34 indicator .md files - Delete 29 temp PowerShell scripts (_fix_mojibake.ps1, _hex_scan.ps1, etc.) - Move test files into tests/ subdirectories for consistent project structure - Add trader-focused bullet points to indicator documentation
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class PvrIndicatorTests
|
||||
{
|
||||
[Fact]
|
||||
public void PvrIndicator_Constructor_SetsDefaults()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
|
||||
Assert.Equal("PVR - Price Volume Rank", indicator.Name);
|
||||
Assert.True(indicator.SeparateWindow);
|
||||
Assert.True(indicator.OnBackGround);
|
||||
Assert.Equal(1, indicator.MinHistoryDepths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_ShortName_ReturnsPVR()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
Assert.Equal("PVR", indicator.ShortName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_MinHistoryDepths_EqualsOne()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
|
||||
Assert.Equal(1, indicator.MinHistoryDepths);
|
||||
Assert.Equal(1, ((IWatchlistIndicator)indicator).MinHistoryDepths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_Initialize_CreatesInternalPvr()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
|
||||
// Initialize should not throw
|
||||
indicator.Initialize();
|
||||
|
||||
Assert.Single(indicator.LinesSeries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
indicator.Initialize();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i, 1000 + (i * 100));
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
}
|
||||
|
||||
double val = indicator.LinesSeries[0].GetValue(0);
|
||||
Assert.True(val >= 0 && val <= 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_ProcessUpdate_NewBar_ComputesValue()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
indicator.Initialize();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i, 1000 + (i * 100));
|
||||
}
|
||||
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(5), 110, 120, 100, 115, 1800);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
|
||||
|
||||
Assert.Equal(2, indicator.LinesSeries[0].Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_Value_IsInValidRange()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
indicator.Initialize();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + (i % 5), 110 + (i % 5), 90 + (i % 5), 105 + (i % 5), 1000 + (i * 50));
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
}
|
||||
|
||||
double val = indicator.LinesSeries[0].GetValue(0);
|
||||
Assert.True(val >= 0 && val <= 4, $"PVR value {val} should be in range [0,4]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_PriceUpVolumeUp_ReturnsOne()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
indicator.Initialize();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
// First bar
|
||||
indicator.HistoricalData.AddBar(now, 100, 105, 95, 100, 1000);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
|
||||
// Second bar - price up, volume up
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(1), 102, 107, 97, 105, 1500);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
|
||||
|
||||
double val = indicator.LinesSeries[0].GetValue(0);
|
||||
Assert.Equal(1.0, val);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PvrIndicator_PriceDownVolumeUp_ReturnsFour()
|
||||
{
|
||||
var indicator = new PvrIndicator();
|
||||
indicator.Initialize();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
// First bar
|
||||
indicator.HistoricalData.AddBar(now, 100, 105, 95, 100, 1000);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
|
||||
// Second bar - price down, volume up
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(1), 98, 103, 93, 95, 1500);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
|
||||
|
||||
double val = indicator.LinesSeries[0].GetValue(0);
|
||||
Assert.Equal(4.0, val);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
using Xunit;
|
||||
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class PvrTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_CreatesValidIndicator()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
Assert.Equal("Pvr", pvr.Name);
|
||||
Assert.Equal(1, pvr.WarmupPeriod);
|
||||
Assert.False(pvr.IsHot);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_WithTBar_ReturnsValidValue()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var bar = new TBar(DateTime.UtcNow, 100, 110, 90, 105, 1000000);
|
||||
var result = pvr.Update(bar);
|
||||
Assert.True(result.Value >= 0 && result.Value <= 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_FirstBar_ReturnsZero()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var bar = new TBar(DateTime.UtcNow, 100, 110, 90, 105, 1000000);
|
||||
var result = pvr.Update(bar);
|
||||
Assert.Equal(0.0, result.Value);
|
||||
Assert.False(pvr.IsHot);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_PriceUpVolumeUp_ReturnsOne()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1000));
|
||||
var result = pvr.Update(new TBar(time.AddMinutes(1), 102, 107, 97, 102, 1500));
|
||||
|
||||
Assert.Equal(1.0, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_PriceUpVolumeDown_ReturnsTwo()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1500));
|
||||
var result = pvr.Update(new TBar(time.AddMinutes(1), 102, 107, 97, 102, 1000));
|
||||
|
||||
Assert.Equal(2.0, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_PriceDownVolumeDown_ReturnsThree()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1500));
|
||||
var result = pvr.Update(new TBar(time.AddMinutes(1), 98, 103, 93, 98, 1000));
|
||||
|
||||
Assert.Equal(3.0, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_PriceDownVolumeUp_ReturnsFour()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1000));
|
||||
var result = pvr.Update(new TBar(time.AddMinutes(1), 98, 103, 93, 98, 1500));
|
||||
|
||||
Assert.Equal(4.0, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_PriceUnchanged_ReturnsZero()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1000));
|
||||
var result = pvr.Update(new TBar(time.AddMinutes(1), 100, 108, 92, 100, 1500));
|
||||
|
||||
Assert.Equal(0.0, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_IsNewTrue_AdvancesState()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var bar1 = new TBar(DateTime.UtcNow, 100, 110, 90, 105, 1000000);
|
||||
var result1 = pvr.Update(bar1, isNew: true);
|
||||
|
||||
var bar2 = new TBar(DateTime.UtcNow.AddMinutes(1), 105, 115, 95, 110, 1100000);
|
||||
var result2 = pvr.Update(bar2, isNew: true);
|
||||
|
||||
Assert.NotEqual(result1.Time, result2.Time);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_IsNewFalse_UpdatesCurrentBar()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
// First bar
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1000), isNew: true);
|
||||
|
||||
// Second bar - price up, volume up -> 1
|
||||
var result1 = pvr.Update(new TBar(time.AddMinutes(1), 102, 107, 97, 102, 1500), isNew: true);
|
||||
Assert.Equal(1.0, result1.Value);
|
||||
|
||||
// Correction - price up, volume down -> 2
|
||||
var result2 = pvr.Update(new TBar(time.AddMinutes(1), 102, 107, 97, 102, 800), isNew: false);
|
||||
Assert.Equal(2.0, result2.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_IterativeCorrections_RestoresState()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
// Build up state
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
pvr.Update(new TBar(time.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i, 100000 + i * 10000), isNew: true);
|
||||
}
|
||||
|
||||
// New bar
|
||||
var originalBar = new TBar(time.AddMinutes(10), 120, 130, 110, 125, 250000);
|
||||
var originalResult = pvr.Update(originalBar, isNew: true);
|
||||
|
||||
// Correction
|
||||
var correctionBar = new TBar(time.AddMinutes(10), 110, 120, 100, 105, 50000);
|
||||
var correctedResult = pvr.Update(correctionBar, isNew: false);
|
||||
|
||||
Assert.NotEqual(originalResult.Value, correctedResult.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_WarmupPeriod_IsHotBecomesTrueAfterFirstBar()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
Assert.False(pvr.IsHot);
|
||||
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1000), isNew: true);
|
||||
Assert.False(pvr.IsHot);
|
||||
|
||||
pvr.Update(new TBar(time.AddMinutes(1), 102, 107, 97, 102, 1500), isNew: true);
|
||||
Assert.True(pvr.IsHot);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_WithNaN_UsesLastValidValue()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
pvr.Update(new TBar(time, 100, 105, 95, 100, 1000));
|
||||
pvr.Update(new TBar(time.AddMinutes(1), 102, 107, 97, 102, 1500));
|
||||
|
||||
// NaN values
|
||||
var result = pvr.Update(new TBar(time.AddMinutes(2), double.NaN, double.NaN, double.NaN, double.NaN, double.NaN));
|
||||
|
||||
Assert.True(result.Value >= 0 && result.Value <= 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reset_ClearsState()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
pvr.Update(new TBar(time.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i, 100000), isNew: true);
|
||||
}
|
||||
|
||||
Assert.True(pvr.IsHot);
|
||||
|
||||
pvr.Reset();
|
||||
|
||||
Assert.False(pvr.IsHot);
|
||||
Assert.Equal(default, pvr.Last);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BatchCalculate_MatchesStreaming()
|
||||
{
|
||||
var bars = new TBarSeries();
|
||||
var gbm = new GBM(seed: 42);
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
bars.Add(gbm.Next());
|
||||
}
|
||||
|
||||
// Streaming
|
||||
var pvr = new Pvr();
|
||||
var streamingValues = new List<double>();
|
||||
foreach (var bar in bars)
|
||||
{
|
||||
streamingValues.Add(pvr.Update(bar).Value);
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Pvr.Batch(bars);
|
||||
|
||||
Assert.Equal(bars.Count, batchResult.Count);
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
Assert.Equal(streamingValues[i], batchResult[i].Value, 10);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SpanCalculate_MatchesStreaming()
|
||||
{
|
||||
var bars = new TBarSeries();
|
||||
var gbm = new GBM(seed: 42);
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
bars.Add(gbm.Next());
|
||||
}
|
||||
|
||||
// Streaming
|
||||
var pvr = new Pvr();
|
||||
var streamingValues = new List<double>();
|
||||
foreach (var bar in bars)
|
||||
{
|
||||
streamingValues.Add(pvr.Update(bar).Value);
|
||||
}
|
||||
|
||||
// Span
|
||||
var price = bars.Close.Values.ToArray();
|
||||
var volume = bars.Volume.Values.ToArray();
|
||||
var spanOutput = new double[bars.Count];
|
||||
|
||||
Pvr.Batch(price, volume, spanOutput);
|
||||
|
||||
for (int i = 0; i < bars.Count; i++)
|
||||
{
|
||||
Assert.Equal(streamingValues[i], spanOutput[i], 10);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SpanCalculate_InvalidLengths_ThrowsArgumentException()
|
||||
{
|
||||
var price = new double[100];
|
||||
var volume = new double[100];
|
||||
var output = new double[99]; // Different length
|
||||
|
||||
Assert.Throws<ArgumentException>(() => Pvr.Batch(price, volume, output));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SpanCalculate_EmptyInput_HandlesGracefully()
|
||||
{
|
||||
var price = Array.Empty<double>();
|
||||
var volume = Array.Empty<double>();
|
||||
var output = Array.Empty<double>();
|
||||
|
||||
// Should not throw
|
||||
Pvr.Batch(price, volume, output);
|
||||
|
||||
Assert.Empty(output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Event_PubFiresOnUpdate()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
TValue? receivedValue = null;
|
||||
bool receivedIsNew = false;
|
||||
|
||||
pvr.Pub += (object? sender, in TValueEventArgs args) =>
|
||||
{
|
||||
receivedValue = args.Value;
|
||||
receivedIsNew = args.IsNew;
|
||||
};
|
||||
|
||||
var bar = new TBar(DateTime.UtcNow, 100, 110, 90, 105, 1000000);
|
||||
pvr.Update(bar, isNew: true);
|
||||
|
||||
Assert.NotNull(receivedValue);
|
||||
Assert.True(receivedIsNew);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_AllPossibleOutputs_AreValid()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
var time = DateTime.UtcNow;
|
||||
|
||||
// Collect all unique PVR values
|
||||
var values = new HashSet<double>();
|
||||
|
||||
// Generate various scenarios
|
||||
var scenarios = new[]
|
||||
{
|
||||
(100.0, 1000.0, 105.0, 1500.0), // price up, volume up -> 1
|
||||
(100.0, 1500.0, 105.0, 1000.0), // price up, volume down -> 2
|
||||
(100.0, 1500.0, 95.0, 1000.0), // price down, volume down -> 3
|
||||
(100.0, 1000.0, 95.0, 1500.0), // price down, volume up -> 4
|
||||
(100.0, 1000.0, 100.0, 1500.0), // price unchanged -> 0
|
||||
};
|
||||
|
||||
foreach (var (p1, v1, p2, v2) in scenarios)
|
||||
{
|
||||
pvr.Reset();
|
||||
pvr.Update(new TBar(time, p1, p1 + 5, p1 - 5, p1, v1));
|
||||
var result = pvr.Update(new TBar(time.AddMinutes(1), p2, p2 + 5, p2 - 5, p2, v2));
|
||||
values.Add(result.Value);
|
||||
}
|
||||
|
||||
// Should have all 5 possible values
|
||||
Assert.Contains(0.0, values);
|
||||
Assert.Contains(1.0, values);
|
||||
Assert.Contains(2.0, values);
|
||||
Assert.Contains(3.0, values);
|
||||
Assert.Contains(4.0, values);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LargeDataset_HandlesWithoutError()
|
||||
{
|
||||
var bars = new TBarSeries();
|
||||
var gbm = new GBM(seed: 42);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
bars.Add(gbm.Next());
|
||||
}
|
||||
|
||||
var pvr = new Pvr();
|
||||
foreach (var bar in bars)
|
||||
{
|
||||
var result = pvr.Update(bar);
|
||||
Assert.True(result.Value >= 0 && result.Value <= 4);
|
||||
}
|
||||
|
||||
Assert.True(pvr.IsHot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
namespace QuanTAlib.Tests;
|
||||
|
||||
public class PvrValidationTests
|
||||
{
|
||||
private readonly ValidationTestData _data;
|
||||
|
||||
public PvrValidationTests()
|
||||
{
|
||||
_data = new ValidationTestData();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_Matches_Skender()
|
||||
{
|
||||
// Skender does not have PVR implementation
|
||||
Assert.True(true, "Skender does not have a Price Volume Rank implementation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_Matches_Talib()
|
||||
{
|
||||
// TA-Lib does not have PVR
|
||||
Assert.True(true, "TA-Lib does not have a Price Volume Rank implementation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_Matches_Tulip()
|
||||
{
|
||||
// Tulip does not have PVR
|
||||
Assert.True(true, "Tulip does not have a Price Volume Rank implementation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_Matches_Ooples()
|
||||
{
|
||||
// Ooples does not have PVR
|
||||
Assert.True(true, "Ooples does not have a Price Volume Rank implementation");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_Streaming_Matches_Batch()
|
||||
{
|
||||
// Streaming
|
||||
var pvr = new Pvr();
|
||||
var streamingValues = new List<double>();
|
||||
foreach (var bar in _data.Bars)
|
||||
{
|
||||
streamingValues.Add(pvr.Update(bar).Value);
|
||||
}
|
||||
|
||||
// Batch
|
||||
var batchResult = Pvr.Batch(_data.Bars);
|
||||
var batchValues = batchResult.Values.ToArray();
|
||||
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), batchValues, 0, 100, 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_Span_Matches_Streaming()
|
||||
{
|
||||
// Streaming
|
||||
var pvr = new Pvr();
|
||||
var streamingValues = new List<double>();
|
||||
foreach (var bar in _data.Bars)
|
||||
{
|
||||
streamingValues.Add(pvr.Update(bar).Value);
|
||||
}
|
||||
|
||||
// Span
|
||||
var price = _data.Bars.Close.Values.ToArray();
|
||||
var volume = _data.Bars.Volume.Values.ToArray();
|
||||
var spanOutput = new double[price.Length];
|
||||
|
||||
Pvr.Batch(price, volume, spanOutput);
|
||||
|
||||
ValidationHelper.VerifyData(streamingValues.ToArray(), spanOutput, 0, 100, 1e-9);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_OutputRange_Valid()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
|
||||
foreach (var bar in _data.Bars)
|
||||
{
|
||||
var result = pvr.Update(bar);
|
||||
Assert.True(result.Value >= 0 && result.Value <= 4,
|
||||
$"PVR value {result.Value} is outside valid range [0,4]");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_OutputValues_AreIntegral()
|
||||
{
|
||||
var pvr = new Pvr();
|
||||
|
||||
foreach (var bar in _data.Bars)
|
||||
{
|
||||
var result = pvr.Update(bar);
|
||||
Assert.True(result.Value == Math.Floor(result.Value),
|
||||
$"PVR value {result.Value} should be an integer");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pvr_ConsistentAcrossAllModes()
|
||||
{
|
||||
// Mode 1: Streaming with TBar
|
||||
var pvr1 = new Pvr();
|
||||
var mode1Values = new List<double>();
|
||||
foreach (var bar in _data.Bars)
|
||||
{
|
||||
mode1Values.Add(pvr1.Update(bar).Value);
|
||||
}
|
||||
|
||||
// Mode 2: Streaming with parameters
|
||||
var pvr2 = new Pvr();
|
||||
var mode2Values = new List<double>();
|
||||
foreach (var bar in _data.Bars)
|
||||
{
|
||||
mode2Values.Add(pvr2.Update(bar.Close, bar.Volume, bar.Time).Value);
|
||||
}
|
||||
|
||||
// Mode 3: Batch
|
||||
var mode3Result = Pvr.Batch(_data.Bars);
|
||||
var mode3Values = mode3Result.Values.ToArray();
|
||||
|
||||
// Mode 4: Span
|
||||
var price = _data.Bars.Close.Values.ToArray();
|
||||
var volume = _data.Bars.Volume.Values.ToArray();
|
||||
var mode4Values = new double[price.Length];
|
||||
Pvr.Batch(price, volume, mode4Values);
|
||||
|
||||
// All modes should match
|
||||
ValidationHelper.VerifyData(mode1Values.ToArray(), mode2Values.ToArray(), 0, 100, 1e-9);
|
||||
ValidationHelper.VerifyData(mode1Values.ToArray(), mode3Values, 0, 100, 1e-9);
|
||||
ValidationHelper.VerifyData(mode1Values.ToArray(), mode4Values, 0, 100, 1e-9);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user