Skip to content

Commit

Permalink
refactor: use readonly list input e-k
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Oct 14, 2024
1 parent 6b4c81c commit 43efa96
Show file tree
Hide file tree
Showing 137 changed files with 638 additions and 980 deletions.
15 changes: 0 additions & 15 deletions src/e-k/ElderRay/ElderRay.Api.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/e-k/ElderRay/ElderRay.Common.cs

This file was deleted.

11 changes: 9 additions & 2 deletions src/e-k/ElderRay/ElderRay.StaticSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ namespace Skender.Stock.Indicators;

// ELDER-RAY (SERIES)

public static partial class Indicator
public static partial class ElderRay
{
public static IReadOnlyList<ElderRayResult> ToElderRay<TQuote>(
this IReadOnlyList<TQuote> quotes,
int lookbackPeriods = 13)
where TQuote : IQuote => quotes
.ToQuoteDList()
.CalcElderRay(lookbackPeriods);

private static List<ElderRayResult> CalcElderRay(
this List<QuoteD> source,
int lookbackPeriods)
{
// check parameter arguments
ElderRay.Validate(lookbackPeriods);
Validate(lookbackPeriods);

// initialize
int length = source.Count;
Expand Down
18 changes: 16 additions & 2 deletions src/e-k/ElderRay/ElderRay.Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Skender.Stock.Indicators;

public static partial class Indicator
// ELDER-RAY (UTILITIES)

public static partial class ElderRay
{
// remove recommended periods
/// <inheritdoc cref="Utility.RemoveWarmupPeriods{T}(IReadOnlyList{T})"/>
/// <inheritdoc cref="Reusable.RemoveWarmupPeriods{T}(IReadOnlyList{T})"/>
public static IReadOnlyList<ElderRayResult> RemoveWarmupPeriods(
this IReadOnlyList<ElderRayResult> results)
{
Expand All @@ -13,4 +15,16 @@ public static IReadOnlyList<ElderRayResult> RemoveWarmupPeriods(

return results.Remove(n + 100);
}

// parameter validation
internal static void Validate(
int lookbackPeriods)
{
// check parameter arguments
if (lookbackPeriods <= 0)
{
throw new ArgumentOutOfRangeException(nameof(lookbackPeriods), lookbackPeriods,
"Lookback periods must be greater than 0 for Elder-ray Index.");
}
}
}
19 changes: 0 additions & 19 deletions src/e-k/Ema/Ema.Api.cs

This file was deleted.

19 changes: 19 additions & 0 deletions src/e-k/Ema/Ema.StreamHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ namespace Skender.Stock.Indicators;

// EXPONENTIAL MOVING AVERAGE (STREAM HUB)

#region hub interface and initializer

public interface IEma
{
int LookbackPeriods { get; }
double K { get; }
}

public static partial class Ema
{
// HUB, from Chain Provider
public static EmaHub<T> ToEma<T>(
this IChainProvider<T> chainProvider,
int lookbackPeriods)
where T : IReusable
=> new(chainProvider, lookbackPeriods);
}
#endregion

public class EmaHub<TIn>
: ChainProvider<TIn, EmaResult>, IEma
where TIn : IReusable
Expand Down
14 changes: 0 additions & 14 deletions src/e-k/Epma/Epma.Api.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/e-k/Epma/Epma.Common.cs

This file was deleted.

12 changes: 6 additions & 6 deletions src/e-k/Epma/Epma.StaticSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ namespace Skender.Stock.Indicators;

// ENDPOINT MOVING AVERAGE (SERIES)

public static partial class Indicator
public static partial class Epma
{
// calculate series
private static List<EpmaResult> CalcEpma<T>(
this List<T> source,
public static IReadOnlyList<EpmaResult> ToEpma<T>(
this IReadOnlyList<T> source,
int lookbackPeriods)
where T : IReusable
{
// check parameter arguments
Epma.Validate(lookbackPeriods);
ArgumentNullException.ThrowIfNull(source);
Validate(lookbackPeriods);

// initialize
int length = source.Count;
List<EpmaResult> results = new(length);

IReadOnlyList<SlopeResult> slope
= source.CalcSlope(lookbackPeriods);
= source.ToSlope(lookbackPeriods);

// roll through source values
for (int i = 0; i < length; i++)
Expand Down
18 changes: 16 additions & 2 deletions src/e-k/Epma/Epma.Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Skender.Stock.Indicators;

public static partial class Indicator
// ENDPOINT MOVING AVERAGE (UTILITIES)

public static partial class Epma
{
// remove recommended periods
/// <inheritdoc cref="Utility.RemoveWarmupPeriods{T}(IReadOnlyList{T})"/>
/// <inheritdoc cref="Reusable.RemoveWarmupPeriods{T}(IReadOnlyList{T})"/>
public static IReadOnlyList<EpmaResult> RemoveWarmupPeriods(
this IReadOnlyList<EpmaResult> results)
{
Expand All @@ -13,4 +15,16 @@ public static IReadOnlyList<EpmaResult> RemoveWarmupPeriods(

return results.Remove(removePeriods);
}

// parameter validation
internal static void Validate(
int lookbackPeriods)
{
// check parameter arguments
if (lookbackPeriods <= 0)
{
throw new ArgumentOutOfRangeException(nameof(lookbackPeriods), lookbackPeriods,
"Lookback periods must be greater than 0 for Epma.");
}
}
}
15 changes: 0 additions & 15 deletions src/e-k/Fcb/Fcb.Api.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/e-k/Fcb/Fcb.Common.cs

This file was deleted.

17 changes: 9 additions & 8 deletions src/e-k/Fcb/Fcb.StaticSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ namespace Skender.Stock.Indicators;

// FRACTAL CHAOS BANDS (SERIES)

public static partial class Indicator
public static partial class Fcb
{
private static List<FcbResult> CalcFcb<TQuote>(
this List<TQuote> quotesList,
int windowSpan)
public static IReadOnlyList<FcbResult> ToFcb<TQuote>(
this IReadOnlyList<TQuote> quotes,
int windowSpan = 2)
where TQuote : IQuote
{
// check parameter arguments
Fcb.Validate(windowSpan);
ArgumentNullException.ThrowIfNull(quotes);
Validate(windowSpan);

// initialize
int length = quotesList.Count;
int length = quotes.Count;
List<FcbResult> results = new(length);

List<FractalResult> fractals = quotesList
.CalcFractal(windowSpan, windowSpan, EndType.HighLow);
IReadOnlyList<FractalResult> fractals = quotes
.ToFractal(windowSpan, windowSpan, EndType.HighLow);

decimal? upperLine = null;
decimal? lowerLine = null;
Expand Down
22 changes: 17 additions & 5 deletions src/e-k/Fcb/Fcb.Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Skender.Stock.Indicators;

public static partial class Indicator
// FRACTAL CHAOS BANDS (UTILITIES)

public static partial class Fcb
{
// CONDENSE (REMOVE null results)
/// <inheritdoc cref="Utility.Condense{T}(IReadOnlyList{T})"/>
/// <inheritdoc cref="Reusable.Condense{T}(IReadOnlyList{T})"/>
public static IReadOnlyList<FcbResult> Condense(
this IReadOnlyList<FcbResult> results)
{
Expand All @@ -17,8 +18,7 @@ public static IReadOnlyList<FcbResult> Condense(
return resultsList.ToSortedList();
}

// remove recommended periods
/// <inheritdoc cref="Utility.RemoveWarmupPeriods{T}(IReadOnlyList{T})"/>
/// <inheritdoc cref="Reusable.RemoveWarmupPeriods{T}(IReadOnlyList{T})"/>
public static IReadOnlyList<FcbResult> RemoveWarmupPeriods(
this IReadOnlyList<FcbResult> results)
{
Expand All @@ -28,4 +28,16 @@ public static IReadOnlyList<FcbResult> RemoveWarmupPeriods(

return results.Remove(removePeriods);
}

// parameter validation
internal static void Validate(
int windowSpan)
{
// check parameter arguments
if (windowSpan < 2)
{
throw new ArgumentOutOfRangeException(nameof(windowSpan), windowSpan,
"Window span must be at least 2 for FCB.");
}
}
}
14 changes: 0 additions & 14 deletions src/e-k/FisherTransform/FisherTransform.Api.cs

This file was deleted.

10 changes: 9 additions & 1 deletion src/e-k/FisherTransform/FisherTransform.StaticSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ namespace Skender.Stock.Indicators;

// FISHER TRANSFORM (SERIES)

public static partial class Indicator
public static partial class FisherTransform
{
public static IReadOnlyList<FisherTransformResult> ToFisherTransform<T>(
this IReadOnlyList<T> results,
int lookbackPeriods = 10)
where T : IReusable
=> results
.ToSortedList(CandlePart.HL2)
.CalcFisherTransform(lookbackPeriods);

private static List<FisherTransformResult> CalcFisherTransform<T>(
this List<T> source,
int lookbackPeriods)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Skender.Stock.Indicators;

// FISHER TRANSFORM (COMMON)
// FISHER TRANSFORM (UTILITIES)

public static class FisherTransform
public static partial class FisherTransform
{
// parameter validation
internal static void Validate(
Expand All @@ -15,5 +15,4 @@ internal static void Validate(
"Lookback periods must be greater than 0 for Fisher Transform.");
}
}

}
Loading

0 comments on commit 43efa96

Please sign in to comment.