Skip to content

Commit 520a454

Browse files
committed
Merge remote-tracking branch 'origin/main' into v3
2 parents 2509522 + 2fb01af commit 520a454

File tree

11 files changed

+46
-22
lines changed

11 files changed

+46
-22
lines changed

src/_common/Generics/Sorting.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static Collection<TSeries> ToSortedCollection<TSeries>(
1010
this IEnumerable<TSeries> series)
1111
where TSeries : ISeries
1212
=> series
13-
.ToSortedList()
13+
.OrderBy(x => x.Date)
1414
.ToCollection();
1515

1616
internal static List<TSeries> ToSortedList<TSeries>(

src/_common/Results/Result.Models.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ namespace Skender.Stock.Indicators;
22

33
// RESULT MODELS
44

5-
public interface IResult : ISeries
6-
{
7-
}
8-
9-
public interface IReusableResult : IResult
5+
public interface IReusableResult : ISeries
106
{
117
public double? Value { get; }
128
}
139

1410
[Serializable]
15-
public abstract class ResultBase : IResult
11+
public abstract class ResultBase : ISeries
1612
{
1713
public DateTime Date { get; set; }
1814
}

src/_common/Results/Result.Syncing.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public static IEnumerable<TResultA> SyncIndex<TResultA, TResultB>(
1111
this IEnumerable<TResultA> syncMe,
1212
IEnumerable<TResultB> toMatch,
1313
SyncType syncType = SyncType.FullMatch)
14-
where TResultA : IResult
15-
where TResultB : IResult
14+
where TResultA : ISeries
15+
where TResultB : ISeries
1616
{
1717
// initialize
1818
List<TResultA> syncMeList = syncMe.ToSortedList();

src/a-d/Atr/Atr.Series.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ internal static List<AtrResult> CalcAtr(
2020
// roll through quotes
2121
for (int i = 0; i < qdList.Count; i++)
2222
{
23-
double hmpc, lmpc;
23+
double hmpc;
24+
double lmpc;
2425
QuoteD q = qdList[i];
2526

2627
AtrResult r = new(q.Date);

src/e-k/Fcb/Fcb.Series.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ internal static List<FcbResult> CalcFcb<TQuote>(
1818

1919
int length = fractals.Count;
2020
List<FcbResult> results = new(length);
21-
decimal? upperLine = null, lowerLine = null;
21+
decimal? upperLine = null;
22+
decimal? lowerLine = null;
2223

2324
// roll through quotes
2425
for (int i = 0; i < length; i++)

src/e-k/ForceIndex/ForceIndex.Series.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ internal static List<ForceIndexResult> CalcForceIndex(
1313
// initialize
1414
int length = qdList.Count;
1515
List<ForceIndexResult> results = new(length);
16-
double? prevClose = null, prevFI = null, sumRawFI = 0;
16+
double? prevClose = null;
17+
double? prevFI = null;
18+
double? sumRawFI = 0;
1719
double k = 2d / (lookbackPeriods + 1);
1820

1921
// roll through quotes

src/s-z/Tsi/Tsi.Series.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,25 @@ internal static List<TsiResult> CalcTsi(
7070
// signal line
7171
if (signalPeriods > 0)
7272
{
73-
if (i >= lookbackPeriods + smoothPeriods + signalPeriods - 1)
73+
int startSignal = lookbackPeriods + smoothPeriods + signalPeriods - 1;
74+
75+
if (i >= startSignal)
7476
{
7577
r.Signal = ((tsi - results[i - 1].Signal) * multS).NaN2Null()
7678
+ results[i - 1].Signal;
7779
}
7880

7981
// initialize signal
80-
else
82+
else if (i == startSignal - 1)
8183
{
8284
sumS += tsi;
85+
r.Signal = sumS / signalPeriods;
86+
}
8387

84-
if (i == lookbackPeriods + smoothPeriods + signalPeriods - 2)
85-
{
86-
r.Signal = sumS / signalPeriods;
87-
}
88+
// warmup signal
89+
else
90+
{
91+
sumS += tsi;
8892
}
8993
}
9094
}

tests/indicators/_common/Results/Result.Syncing.Tests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,9 @@ public void SyncIndex()
9696

9797
Assert.IsFalse(noBaseResults.Any());
9898
Assert.IsFalse(noEvalResults.Any());
99+
100+
// bad sync type
101+
Assert.ThrowsException<ArgumentOutOfRangeException>(()
102+
=> eval.SyncIndex(baseline, (SyncType)int.MaxValue));
99103
}
100104
}

tests/indicators/a-d/Chandelier/Chandelier.Tests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,9 @@ public void Exceptions()
100100
// bad multiplier
101101
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
102102
quotes.GetChandelier(25, 0));
103+
104+
// bad type
105+
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
106+
quotes.GetChandelier(25, 2, (ChandelierType)int.MaxValue));
103107
}
104108
}

tests/indicators/m-r/Renko/Renko.Tests.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,15 @@ public void NoQuotes()
139139
Assert.AreEqual(0, r0.Count);
140140
}
141141

142-
// bad arguments
143142
[TestMethod]
144143
public void Exceptions()
145-
=> Assert.ThrowsException<ArgumentOutOfRangeException>(()
144+
{
145+
// bad arguments
146+
Assert.ThrowsException<ArgumentOutOfRangeException>(()
146147
=> quotes.GetRenko(0));
148+
149+
// bad end type
150+
Assert.ThrowsException<ArgumentOutOfRangeException>(()
151+
=> quotes.GetRenko(2, (EndType)int.MaxValue));
152+
}
147153
}

tests/indicators/s-z/ZigZag/ZigZag.Tests.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,15 @@ public void SchrodingerScenario()
220220
Assert.AreEqual(342, r2.Count);
221221
}
222222

223-
// bad lookback period
224223
[TestMethod]
225224
public void Exceptions()
226-
=> Assert.ThrowsException<ArgumentOutOfRangeException>(()
225+
{
226+
// bad lookback period
227+
Assert.ThrowsException<ArgumentOutOfRangeException>(()
227228
=> quotes.GetZigZag(EndType.Close, 0));
229+
230+
// bad end type
231+
Assert.ThrowsException<ArgumentOutOfRangeException>(()
232+
=> quotes.GetZigZag((EndType)int.MaxValue, 2));
233+
}
228234
}

0 commit comments

Comments
 (0)