style patterns

This commit is contained in:
Miha Kralj
2026-01-25 16:01:45 -08:00
parent 2836f253c4
commit e59665c8f0
399 changed files with 6892 additions and 1323 deletions
+2
View File
@@ -48,7 +48,9 @@ public sealed class UsfIndicator : Indicator, IWatchlistIndicator
protected override void OnUpdate(UpdateArgs args)
{
if (args.Reason != UpdateReason.NewBar && args.Reason != UpdateReason.HistoricalBar)
{
return;
}
var item = HistoricalData[Count - 1, SeekOriginHistory.Begin];
TValue result = _ma.Update(new TValue(item.TimeLeft.Ticks, _priceSelector(item)), args.IsNewBar());
+4
View File
@@ -413,7 +413,9 @@ public class UsfTests
var gbm = new GBM(startPrice: 100, mu: 0.05, sigma: 0.2, seed: 42);
for (int i = 0; i < source.Length; i++)
{
source[i] = gbm.Next().Close;
}
// Warm up
Usf.Calculate(source.AsSpan(), output.AsSpan(), 100);
@@ -509,7 +511,9 @@ public class UsfTests
{
var series = new TSeries();
for (int i = 1; i <= 10; i++)
{
series.Add(DateTime.UtcNow, i * 10);
}
var (results, indicator) = Usf.Calculate(series, 5);
+5 -1
View File
@@ -209,7 +209,11 @@ public sealed class UsfValidationTests : IDisposable
private static double CalculateVariance(List<double> values)
{
if (values.Count == 0) return 0;
if (values.Count == 0)
{
return 0;
}
double mean = values.Average();
return values.Sum(v => (v - mean) * (v - mean)) / values.Count;
}
+37 -4
View File
@@ -42,7 +42,9 @@ public sealed class Usf : AbstractBase
public Usf(int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
double sqrt2_pi = Math.Sqrt(2) * Math.PI;
double arg = sqrt2_pi / period;
@@ -90,7 +92,10 @@ public sealed class Usf : AbstractBase
public override void Prime(ReadOnlySpan<double> source, TimeSpan? step = null)
{
if (source.Length == 0) return;
if (source.Length == 0)
{
return;
}
Reset();
@@ -117,9 +122,13 @@ public sealed class Usf : AbstractBase
{
double val = source[i];
if (double.IsFinite(val))
{
_state.LastValidValue = val;
}
else
{
val = _state.LastValidValue;
}
double usf = (_state.Count < 4)
? val
@@ -136,7 +145,9 @@ public sealed class Usf : AbstractBase
}
if (_state.Count >= WarmupPeriod)
{
_state.IsHot = true;
}
Last = new TValue(DateTime.MinValue, _state.Usf1);
@@ -191,9 +202,15 @@ public sealed class Usf : AbstractBase
_state.PrevInput2 = _state.PrevInput1;
_state.PrevInput1 = val;
if (isNew && !initialized) _state.Count++;
if (isNew && !initialized)
{
_state.Count++;
}
if (!_state.IsHot && _state.Count >= WarmupPeriod)
{
_state.IsHot = true;
}
Last = new TValue(input.Time, usf);
PubEvent(Last, isNew);
@@ -202,7 +219,10 @@ public sealed class Usf : AbstractBase
public override TSeries Update(TSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
int len = source.Count;
var t = new List<long>(len);
@@ -266,9 +286,13 @@ public sealed class Usf : AbstractBase
{
double val = source[i];
if (double.IsFinite(val))
{
state.LastValidValue = val;
}
else
{
val = state.LastValidValue;
}
double usf = (state.Count < 4)
? val
@@ -286,7 +310,9 @@ public sealed class Usf : AbstractBase
}
if (!state.IsHot && state.Count >= warmupPeriod)
{
state.IsHot = true;
}
}
public static (TSeries Results, Usf Indicator) Calculate(TSeries source, int period)
@@ -300,7 +326,9 @@ public sealed class Usf : AbstractBase
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
double sqrt2_pi = Math.Sqrt(2) * Math.PI;
double arg = sqrt2_pi / period;
@@ -311,9 +339,14 @@ public sealed class Usf : AbstractBase
double c1 = (1.0 + c2 - c3) / 4.0;
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output must have the same length", nameof(output));
}
if (source.Length == 0) return;
if (source.Length == 0)
{
return;
}
var state = State.New();