Skip to content

Commit

Permalink
Update references due to recent refactoring in TALib
Browse files Browse the repository at this point in the history
  • Loading branch information
hmG3 committed Mar 14, 2024
1 parent 4fd99c2 commit 5ce3fb3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 38 deletions.
47 changes: 19 additions & 28 deletions src/TaTooIne.Benchmark/IndicatorsBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void TulipIterationSetup()
_tulipPeriodOption++;

var currentIndicator =
(Indicator) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(this)!;
(Indicator) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentIndicatorIndex =
(int) GetType().GetField("__argField1", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentIndicatorOptions = _tulipOptions[currentIndicatorIndex];
Expand Down Expand Up @@ -106,8 +105,7 @@ public void Tulip(Indicator Indicator, int order)
}
}

public static IEnumerable<object[]> TulipSource() =>
Indicators.All.Select((indicator, index) => new object[] { indicator, index });
public static IEnumerable<object[]> TulipSource() => Indicators.All.Select((indicator, index) => new object[] { indicator, index });

[GlobalCleanup(Target = "Tulip")]
public void GlobalTulipCleanup() => _inputsMemoryPool.Dispose();
Expand All @@ -126,8 +124,7 @@ public void TALibIterationSetup()
_talibPeriodOption++;

var currentFunction =
(Function) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(this)!;
(Function) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentFunctionIndex =
(int) GetType().GetField("__argField1", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentFunctionOptions = _talibOptions[currentFunctionIndex];
Expand Down Expand Up @@ -207,8 +204,7 @@ public void TALib(Function Indicator, int order)
}
}

public static IEnumerable<object[]> TALibSource() =>
Functions.All.Select((function, index) => new object[] { function, index });
public static IEnumerable<object[]> TALibSource() => Abstract.All.Select((function, index) => new object[] { function, index });

[GlobalCleanup(Target = "TALib")]
public void GlobalTALibCleanup() => _inputsMemoryPool.Dispose();
Expand Down Expand Up @@ -309,42 +305,36 @@ private void SetupTALib()
Near = 0.3
};

Core.SetCandleSettings(
Core.CandleSettingType.BodyDoji, Core.RangeType.HighLow, candleDefaultConfig.Period,
candleDefaultConfig.BodyNone);
Core.CandleSettings.Set(Core.CandleSettingType.BodyDoji,
new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.BodyNone));

Core.SetCandleSettings(
Core.CandleSettingType.BodyShort, Core.RangeType.RealBody, candleDefaultConfig.Period,
candleDefaultConfig.BodyShort);
Core.CandleSettings.Set(Core.CandleSettingType.BodyShort,
new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.BodyShort));

Core.SetCandleSettings(
Core.CandleSettingType.BodyLong, Core.RangeType.RealBody, candleDefaultConfig.Period,
candleDefaultConfig.BodyLong);
Core.CandleSettings.Set(Core.CandleSettingType.BodyLong,
new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.BodyLong));

Core.SetCandleSettings(
Core.CandleSettingType.ShadowVeryShort, Core.RangeType.HighLow, candleDefaultConfig.Period,
candleDefaultConfig.WickNone);
Core.CandleSettings.Set(Core.CandleSettingType.ShadowVeryShort,
new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.WickNone));

Core.SetCandleSettings(
Core.CandleSettingType.ShadowLong, Core.RangeType.RealBody, candleDefaultConfig.Period,
candleDefaultConfig.WickLong);
Core.CandleSettings.Set(Core.CandleSettingType.ShadowLong,
new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.WickLong));

Core.SetCandleSettings(
Core.CandleSettingType.Near, Core.RangeType.HighLow, candleDefaultConfig.Period,
candleDefaultConfig.Near);
Core.CandleSettings.Set(Core.CandleSettingType.Near,
new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.Near));
}

private void SetupTALibInputs()
{
var functionsCount = Functions.All.Count();
var functionsCount = Abstract.All.Count();

_talibInputs = new Dictionary<int, double[][]>(functionsCount);
_talibOptions = new Dictionary<int, double[]>(functionsCount);
_talibOutputs = new Dictionary<int, double[][]>(functionsCount);

for (var i = 0; i < functionsCount; i++)
{
var function = Functions.All.ElementAt(i);
var function = Abstract.All.ElementAt(i);

var (inputs, options, outputs) = PrepareParams(function);
_talibInputs.Add(i, inputs);
Expand Down Expand Up @@ -419,6 +409,7 @@ private void SetupTALibInputs()
{
inputData[i] = random.Next(30);
}

inputs[j] = inputData;
break;
}
Expand Down
13 changes: 11 additions & 2 deletions src/TaTooIne.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Globalization;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
Expand All @@ -14,11 +16,18 @@
.AddDiagnoser(MemoryDiagnoser.Default)
.AddLogicalGroupRules(BenchmarkLogicalGroupRule.ByParams)
.WithOrderer(BenchmarkOrderer.Instance)
.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond))
.WithSummaryStyle(new SummaryStyle(
cultureInfo: CultureInfo.CurrentCulture,
printUnitsInHeader: true,
printUnitsInContent: false,
timeUnit: TimeUnit.Millisecond,
sizeUnit: SizeUnit.KB
))
.WithUnionRule(ConfigUnionRule.Union);
#if DEBUG
config = ManualConfig.Union(new DebugInProcessConfig(), config);
#else

config = ManualConfig.Union(config, ManualConfig.CreateEmpty()
.AddLogger(ConsoleLogger.Default)
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80))
Expand All @@ -29,7 +38,7 @@
BenchmarkParamsColumnProvider.Instance,
DefaultColumnProviders.Metrics
])
.AddExporter(HtmlExporter.Default));
.AddExporter(HtmlExporter.Default, CsvExporter.Default, MarkdownExporter.Console));
#endif

BenchmarkRunner.Run<IndicatorsBenchmark>(config);
2 changes: 1 addition & 1 deletion src/TaTooIne.Demo/DemoIndicators/IndicatorsIndex.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class IndicatorsIndex

protected override void OnInitialized()
{
_groups = Functions.All.Where(g => g.Group != "Math Transform").GroupBy(f => f.Group).ToList();
_groups = Abstract.All.Where(g => g.Group != "Math Transform").GroupBy(f => f.Group).ToList();

Check failure on line 19 in src/TaTooIne.Demo/DemoIndicators/IndicatorsIndex.razor.cs

View workflow job for this annotation

GitHub Actions / build

The name 'Abstract' does not exist in the current context
}

private string? NavMenuCssClass(int groupId) => ActiveGroupId == groupId ? "active" : null;
Expand Down
7 changes: 1 addition & 6 deletions src/TaTooIne.Demo/Models/Line.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
namespace TaTooIne.Demo.Models;

public sealed record Line
{
public required DateTime Time { get; init; }

public required double Value { get; init; }
}
public sealed record Line(DateTime Time, double Value);
2 changes: 1 addition & 1 deletion src/TaTooIne.Demo/Pages/Demo.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private async Task CalculateExample(Function function)
},
"Volume Indicators" => new
{
Volume = _sampleData.Select(c => new Line { Time = c.Time, Value = c.Volume }).ToList(),
Volume = _sampleData.Select(c => new Line(c.Time, c.Volume)).ToList(),
OverlayLines = outputLines
},
_ => new
Expand Down

0 comments on commit 5ce3fb3

Please sign in to comment.