From f4fb12407aed1aabc391fcb6e0d8fcc6ad0a2ae0 Mon Sep 17 00:00:00 2001 From: vlad zverzhkhovskiy Date: Wed, 8 Oct 2025 15:45:33 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Declisions/Dtos/ConvolutionResult.cs | 12 +++--------- .../Declisions/Dtos/HistItem.cs | 8 +------- .../Declisions/Utils/Statistics.cs | 16 ++++++++-------- KLHZ.Trader.Core.Tests/StatisticTests.cs | 8 ++++---- KLHZ.Trader.Core/Exchange/Services/Trader.cs | 4 ++-- .../Controllers/PlayController.cs | 2 -- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/KLHZ.Trader.Core.Math/Declisions/Dtos/ConvolutionResult.cs b/KLHZ.Trader.Core.Math/Declisions/Dtos/ConvolutionResult.cs index 176b3d4..2b37aae 100644 --- a/KLHZ.Trader.Core.Math/Declisions/Dtos/ConvolutionResult.cs +++ b/KLHZ.Trader.Core.Math/Declisions/Dtos/ConvolutionResult.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace KLHZ.Trader.Core.Math.Declisions.Dtos +namespace KLHZ.Trader.Core.Math.Declisions.Dtos { public class ConvolutionResult { public decimal Sum { get; set; } - public decimal Value { get;set; } + public decimal Value { get; set; } public int Shift { get; set; } - public decimal Leverage { get; set; } + public decimal Leverage { get; set; } } } diff --git a/KLHZ.Trader.Core.Math/Declisions/Dtos/HistItem.cs b/KLHZ.Trader.Core.Math/Declisions/Dtos/HistItem.cs index db2289b..dc4eb69 100644 --- a/KLHZ.Trader.Core.Math/Declisions/Dtos/HistItem.cs +++ b/KLHZ.Trader.Core.Math/Declisions/Dtos/HistItem.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace KLHZ.Trader.Core.Math.Declisions.Dtos +namespace KLHZ.Trader.Core.Math.Declisions.Dtos { public class HistItem { diff --git a/KLHZ.Trader.Core.Math/Declisions/Utils/Statistics.cs b/KLHZ.Trader.Core.Math/Declisions/Utils/Statistics.cs index f0068df..333dc3e 100644 --- a/KLHZ.Trader.Core.Math/Declisions/Utils/Statistics.cs +++ b/KLHZ.Trader.Core.Math/Declisions/Utils/Statistics.cs @@ -133,15 +133,15 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils public static HistItem[] CalcHistogram(ITradeDataItem[] values) { var result = new Dictionary(); - foreach(var item in values) + foreach (var item in values) { - if (!result.TryGetValue(item.Price,out var val)) + if (!result.TryGetValue(item.Price, out var val)) { result[item.Price] = 0; } result[item.Price] = val + 1; } - return result.Select(r => new HistItem() { Value = r.Key, Count = r.Value }).OrderBy(i=>i.Value).ToArray(); + return result.Select(r => new HistItem() { Value = r.Key, Count = r.Value }).OrderBy(i => i.Value).ToArray(); } public static decimal[] GetParabolaCore(int leverageSize, decimal maxValue = 1) @@ -163,7 +163,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils public static ConvolutionResult[] CalcConvolution(HistItem[] hist, int leverageSize) { - if (hist.Length>2* leverageSize+1) + if (hist.Length > 2 * leverageSize + 1) { var results = new List(); var coreSize = 2 * leverageSize + 1; @@ -174,15 +174,15 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils for (int i = 0; i < 2 * leverageSize + 1; i++) { var core = GetParabolaCore(leverageSize, hist[i + shift].Count); - s += (hist[i + shift].Count - core[i])*(hist[i + shift].Count - core[i]); - if (i== leverageSize) + s += (hist[i + shift].Count - core[i]) * (hist[i + shift].Count - core[i]); + if (i == leverageSize) { k = i + shift; } } s = s / coreSize; s = (decimal)System.Math.Pow((double)s, 0.5d); - //s /= coreSum; + //s /= coreSum; results.Add(new ConvolutionResult() { Leverage = leverageSize, @@ -191,7 +191,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils Shift = k, }); } - return results.OrderByDescending(r=>r.Value).ToArray(); + return results.OrderByDescending(r => r.Value).ToArray(); } return Array.Empty(); } diff --git a/KLHZ.Trader.Core.Tests/StatisticTests.cs b/KLHZ.Trader.Core.Tests/StatisticTests.cs index 6f32e4d..b5013ba 100644 --- a/KLHZ.Trader.Core.Tests/StatisticTests.cs +++ b/KLHZ.Trader.Core.Tests/StatisticTests.cs @@ -33,12 +33,12 @@ namespace KLHZ.Trader.Core.Tests } - var res = Statistics.CalcHistogram(data.Select(d=>new CachedValue() + var res = Statistics.CalcHistogram(data.Select(d => new CachedValue() { - Figi ="", + Figi = "", Ticker = "", - Direction =1, - Price = d/2, + Direction = 1, + Price = d / 2, Time = DateTime.UtcNow, }).ToArray()); diff --git a/KLHZ.Trader.Core/Exchange/Services/Trader.cs b/KLHZ.Trader.Core/Exchange/Services/Trader.cs index aace132..1791ab1 100644 --- a/KLHZ.Trader.Core/Exchange/Services/Trader.cs +++ b/KLHZ.Trader.Core/Exchange/Services/Trader.cs @@ -165,7 +165,7 @@ namespace KLHZ.Trader.Core.Exchange.Services if (DPricesValues.TryGetValue(message.Figi, out var olddPrice)) { - if (olddPrice < 0m && pricesDiff >0) + if (olddPrice < 0m && pricesDiff > 0) { //await _tradeDataProvider.LogPrice(message, "diffs_pirson_diff_point_long_in", message.Price); } @@ -189,7 +189,7 @@ namespace KLHZ.Trader.Core.Exchange.Services }); if (DPirsonValues.TryGetValue(message.Figi, out var olddpirs)) { - if (olddpirs < -0.3m && res > -0.3m && pricesDiff>0 && (tradesDiff > 0)) + if (olddpirs < -0.3m && res > -0.3m && pricesDiff > 0 && (tradesDiff > 0)) { await _tradeDataProvider.LogPrice(message, "diffs_pirson_diff_point_long_in", message.Price); } diff --git a/KLHZ.Trader.Service/Controllers/PlayController.cs b/KLHZ.Trader.Service/Controllers/PlayController.cs index 4ce204c..3602481 100644 --- a/KLHZ.Trader.Service/Controllers/PlayController.cs +++ b/KLHZ.Trader.Service/Controllers/PlayController.cs @@ -2,12 +2,10 @@ using KLHZ.Trader.Core.Contracts.Messaging.Dtos; using KLHZ.Trader.Core.Contracts.Messaging.Interfaces; using KLHZ.Trader.Core.DataLayer; using KLHZ.Trader.Core.DataLayer.Entities.Orders; -using KLHZ.Trader.Core.Math.Declisions.Dtos; using KLHZ.Trader.Core.Math.Declisions.Utils; using KLHZ.Trader.Service.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using System.Linq; namespace KLHZ.Trader.Service.Controllers {