Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Apr 8, 2023
2 parents 2509522 + 2fb01af commit 520a454
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/_common/Generics/Sorting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static Collection<TSeries> ToSortedCollection<TSeries>(
this IEnumerable<TSeries> series)
where TSeries : ISeries
=> series
.ToSortedList()
.OrderBy(x => x.Date)
.ToCollection();

internal static List<TSeries> ToSortedList<TSeries>(
Expand Down
8 changes: 2 additions & 6 deletions src/_common/Results/Result.Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ namespace Skender.Stock.Indicators;

// RESULT MODELS

public interface IResult : ISeries
{
}

public interface IReusableResult : IResult
public interface IReusableResult : ISeries
{
public double? Value { get; }
}

[Serializable]
public abstract class ResultBase : IResult
public abstract class ResultBase : ISeries
{
public DateTime Date { get; set; }
}
4 changes: 2 additions & 2 deletions src/_common/Results/Result.Syncing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public static IEnumerable<TResultA> SyncIndex<TResultA, TResultB>(
this IEnumerable<TResultA> syncMe,
IEnumerable<TResultB> toMatch,
SyncType syncType = SyncType.FullMatch)
where TResultA : IResult
where TResultB : IResult
where TResultA : ISeries
where TResultB : ISeries
{
// initialize
List<TResultA> syncMeList = syncMe.ToSortedList();
Expand Down
3 changes: 2 additions & 1 deletion src/a-d/Atr/Atr.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ internal static List<AtrResult> CalcAtr(
// roll through quotes
for (int i = 0; i < qdList.Count; i++)
{
double hmpc, lmpc;
double hmpc;
double lmpc;
QuoteD q = qdList[i];

AtrResult r = new(q.Date);
Expand Down
3 changes: 2 additions & 1 deletion src/e-k/Fcb/Fcb.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ internal static List<FcbResult> CalcFcb<TQuote>(

int length = fractals.Count;
List<FcbResult> results = new(length);
decimal? upperLine = null, lowerLine = null;
decimal? upperLine = null;
decimal? lowerLine = null;

// roll through quotes
for (int i = 0; i < length; i++)
Expand Down
4 changes: 3 additions & 1 deletion src/e-k/ForceIndex/ForceIndex.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ internal static List<ForceIndexResult> CalcForceIndex(
// initialize
int length = qdList.Count;
List<ForceIndexResult> results = new(length);
double? prevClose = null, prevFI = null, sumRawFI = 0;
double? prevClose = null;
double? prevFI = null;
double? sumRawFI = 0;
double k = 2d / (lookbackPeriods + 1);

// roll through quotes
Expand Down
16 changes: 10 additions & 6 deletions src/s-z/Tsi/Tsi.Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,25 @@ internal static List<TsiResult> CalcTsi(
// signal line
if (signalPeriods > 0)
{
if (i >= lookbackPeriods + smoothPeriods + signalPeriods - 1)
int startSignal = lookbackPeriods + smoothPeriods + signalPeriods - 1;

if (i >= startSignal)
{
r.Signal = ((tsi - results[i - 1].Signal) * multS).NaN2Null()
+ results[i - 1].Signal;
}

// initialize signal
else
else if (i == startSignal - 1)
{
sumS += tsi;
r.Signal = sumS / signalPeriods;
}

if (i == lookbackPeriods + smoothPeriods + signalPeriods - 2)
{
r.Signal = sumS / signalPeriods;
}
// warmup signal
else
{
sumS += tsi;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/indicators/_common/Results/Result.Syncing.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,9 @@ public void SyncIndex()

Assert.IsFalse(noBaseResults.Any());
Assert.IsFalse(noEvalResults.Any());

// bad sync type
Assert.ThrowsException<ArgumentOutOfRangeException>(()
=> eval.SyncIndex(baseline, (SyncType)int.MaxValue));
}
}
4 changes: 4 additions & 0 deletions tests/indicators/a-d/Chandelier/Chandelier.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,9 @@ public void Exceptions()
// bad multiplier
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
quotes.GetChandelier(25, 0));

// bad type
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
quotes.GetChandelier(25, 2, (ChandelierType)int.MaxValue));
}
}
10 changes: 8 additions & 2 deletions tests/indicators/m-r/Renko/Renko.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ public void NoQuotes()
Assert.AreEqual(0, r0.Count);
}

// bad arguments
[TestMethod]
public void Exceptions()
=> Assert.ThrowsException<ArgumentOutOfRangeException>(()
{
// bad arguments
Assert.ThrowsException<ArgumentOutOfRangeException>(()
=> quotes.GetRenko(0));

// bad end type
Assert.ThrowsException<ArgumentOutOfRangeException>(()
=> quotes.GetRenko(2, (EndType)int.MaxValue));
}
}
10 changes: 8 additions & 2 deletions tests/indicators/s-z/ZigZag/ZigZag.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,15 @@ public void SchrodingerScenario()
Assert.AreEqual(342, r2.Count);
}

// bad lookback period
[TestMethod]
public void Exceptions()
=> Assert.ThrowsException<ArgumentOutOfRangeException>(()
{
// bad lookback period
Assert.ThrowsException<ArgumentOutOfRangeException>(()
=> quotes.GetZigZag(EndType.Close, 0));

// bad end type
Assert.ThrowsException<ArgumentOutOfRangeException>(()
=> quotes.GetZigZag((EndType)int.MaxValue, 2));
}
}

0 comments on commit 520a454

Please sign in to comment.