diff --git a/KLHZ.Trader.Core.Math/Declisions/Dtos/FFT/FFTAnalyzeResult.cs b/KLHZ.Trader.Core.Math/Declisions/Dtos/FFT/FFTAnalyzeResult.cs index ff40b51..9ff6bcc 100644 --- a/KLHZ.Trader.Core.Math/Declisions/Dtos/FFT/FFTAnalyzeResult.cs +++ b/KLHZ.Trader.Core.Math/Declisions/Dtos/FFT/FFTAnalyzeResult.cs @@ -9,6 +9,7 @@ public decimal Mediana { get; init; } public decimal Upper30Decil { get; init; } public decimal Lower20Decil { get; init; } + public int Length { get; init; } public DateTime LastTime { get; init; } public DateTime StartTime { get; init; } public bool IsEmpty => this == Empty; diff --git a/KLHZ.Trader.Core.Math/Declisions/Utils/FFT.cs b/KLHZ.Trader.Core.Math/Declisions/Utils/FFT.cs index 842f049..d2f3237 100644 --- a/KLHZ.Trader.Core.Math/Declisions/Utils/FFT.cs +++ b/KLHZ.Trader.Core.Math/Declisions/Utils/FFT.cs @@ -2,6 +2,7 @@ using KLHZ.Trader.Core.Math.Declisions.Dtos.FFT.Enums; using MathNet.Numerics; using MathNet.Numerics.IntegralTransforms; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace KLHZ.Trader.Core.Math.Declisions.Utils { @@ -51,6 +52,48 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils Lower20Decil = newValues[(int)(newValues.Length * 0.2)], Max = newValues.Max(), Min = newValues.Min(), + Length = values.Length, + }; + } + + public static FFTAnalyzeResult ReAnalyze(FFTAnalyzeResult result, string key, TimeSpan minPeriod, TimeSpan maxPeriod) + { + var tmp = new List(); + for (int i = 0; i < result.Harmonics.Length; i++) + { + var per = CaclHarmonycPeriod(result.LastTime - result.StartTime, result.Length, i); + if (per >= minPeriod && per <= maxPeriod) + { + tmp.Add(result.Harmonics[i]); + } + } + + var harms = tmp.ToArray(); + var newValues = new decimal[result.Length]; + var newValues2 = new decimal[result.Length]; + var time = result.StartTime; + var dt = (result.LastTime - result.StartTime).TotalSeconds / result.Length; + for (int i = 0; i < result.Length; i++) + { + var currentTime = time.AddSeconds(i* dt); + newValues[i] = (decimal)CalcAmplitude(harms, result.StartTime, currentTime); + newValues2[i] = (decimal)CalcExtremum(harms, result.StartTime, currentTime); + } + + newValues = newValues.Order().ToArray(); + var ma = newValues2.Max(); + var mi = newValues2.Min(); + return new FFTAnalyzeResult() + { + Key = key, + Harmonics = harms, + LastTime = result.LastTime, + StartTime = result.StartTime, + Mediana = newValues[newValues.Length / 2], + Upper30Decil = newValues[(int)(newValues.Length * 0.7)], + Lower20Decil = newValues[(int)(newValues.Length * 0.2)], + Max = newValues.Max(), + Min = newValues.Min(), }; } diff --git a/KLHZ.Trader.Core/Exchange/Services/Trader.cs b/KLHZ.Trader.Core/Exchange/Services/Trader.cs index 0fafdfc..bbd01b8 100644 --- a/KLHZ.Trader.Core/Exchange/Services/Trader.cs +++ b/KLHZ.Trader.Core/Exchange/Services/Trader.cs @@ -117,8 +117,10 @@ namespace KLHZ.Trader.Core.Exchange.Services if (data.isFullIntervalExists) { var interpolatedData = SignalProcessing.InterpolateData(data.timestamps, data.prices, TimeSpan.FromSeconds(5)); - fft = FFT.Analyze(interpolatedData.timestamps, interpolatedData.values, message.Figi, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(40)); + var fftFull = FFT.Analyze(interpolatedData.timestamps, interpolatedData.values, message.Figi+"_full", TimeSpan.FromSeconds(15), TimeSpan.FromHours(24)); + fft = FFT.ReAnalyze(fftFull, message.Figi, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(40)); await _tradeDataProvider.SetFFtResult(fft); + await _tradeDataProvider.SetFFtResult(fftFull); } } else