корректная обработка истории.
parent
fbd3da2b8d
commit
d0786cfe19
|
@ -13,7 +13,7 @@
|
|||
public static bool IsLinesCrossing(DateTime time1, DateTime time2, decimal val1_1, decimal val1_2, decimal val2_1, decimal val2_2)
|
||||
{
|
||||
var dtime = (decimal)(time2 - time1).TotalSeconds;
|
||||
|
||||
if (dtime == 0) return false;
|
||||
var dval1 = val1_2 - val1_1;
|
||||
var k1 = dval1 / dtime;
|
||||
var b1 = val1_1;
|
||||
|
@ -25,9 +25,12 @@
|
|||
if (k1 != k2)
|
||||
{
|
||||
var cross = LinesCrossing(k1, b1, k2, b2);
|
||||
if (cross.x>=0 && cross.x <= dtime)
|
||||
{
|
||||
var crossingTimestamp = time1.AddSeconds((double)cross.x);
|
||||
return crossingTimestamp >= time1 && crossingTimestamp <= time2;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
using KLHZ.Trader.Core.DataLayer.Entities.Prices;
|
||||
using KLHZ.Trader.Core.Math.Common;
|
||||
using KLHZ.Trader.Core.Math.Declisions.Services.Cache;
|
||||
using KLHZ.Trader.Core.Math.Declisions.Utils;
|
||||
|
||||
namespace KLHZ.Trader.Core.Tests
|
||||
{
|
||||
public class MovingAverageTests
|
||||
{
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
var cacheUnit = new PriceHistoryCacheUnit2("");
|
||||
for (int i = 0; i < 5 * PriceHistoryCacheUnit2.CacheMaxLength; i++)
|
||||
{
|
||||
cacheUnit.AddData(new PriceChange() { Figi = "", Ticker = "", Value = i, Time = DateTime.UtcNow });
|
||||
if (i >= 500)
|
||||
{
|
||||
var data = cacheUnit.GetData().Result;
|
||||
Assert.IsTrue(data.prices.Length == PriceHistoryCacheUnit2.CacheMaxLength);
|
||||
Assert.IsTrue(data.prices.Last() == i);
|
||||
var res = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue