交易中的机器学习:理论、模型、实践和算法交易 - 页 3281

 
Maxim Dmitrievsky #:

非规范化交叉相关 )

交叉协方差。

那么,你需要皮尔逊。

 
fxsaber #:

你需要皮尔逊

我不知道该怎么做 我困了

差不多吧

>>> a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> b = np.array([1, 2, 3])
>>> a = (a - np.mean(a)) / (np.std(a))
>>> b = (b - np.mean(b)) / (np.std(b))
>>> np.correlate(a, b, 'full')
array([-1.8973666 , -1.42302495,  0.9486833 ,  0.9486833 ,  0.9486833 ,
        0.9486833 ,  0.9486833 ,  0.9486833 ,  0.9486833 , -1.42302495,
       -1.8973666 ])
>>> 
 
Maxim Dmitrievsky #:

我不知道该怎么做,而且我很困。

类似的东西

对,不是这样的

 
fxsaber #:

对,错。

差不多了,查查吧,我走了。

 
fxsaber #:

试图在长字符串中快速找到相似的短字符串。

通过 Alglib 实现的这种方法需要六秒多才能在第一百万个字符串中搜索到相似的短字符串(300)。

我加快了速度。

#include <fxsaber\Math\Math.mqh> // https://www.mql5.com/ru/code/17982

const vector<double> GetCorr( const double &Array[], const double &Pattern[], const int Step = 1 )
{
  double Corr[];  
  MathCorrelationPearson(Array, Pattern, Corr, Step);
  
  ArrayRemove(Corr, 0, ArraySize(Pattern) - 1);  
  
  vector<double> Res;
  Res.Swap(Corr);
  
  return(Res);
}

#property script_show_inputs

input int inRows = 300; // Длина короткой строки
input int inCols = 1000000; // Длина длинной строки

// Поиск похожей строки в длинной строке.
void OnStart()
{  
  if (inRows < inCols)
  {
    PrintCPU(); // https://www.mql5.com/ru/forum/86386/page3256#comment_49538685
    
    double Array[]; // Длинная строка, где будет искать.
    double Pattern[]; // Короткая строка, с которой будем сравнивать.
    CMatrixDouble Matrix;
    
    FillData(Array, Pattern, Matrix, inRows, inCols); // https://www.mql5.com/ru/forum/86386/page3278#comment_49725614
            
    Print(TOSTRING(inRows) + TOSTRING(inCols));

    vector<double> vPattern;  
    vPattern.Assign(Pattern);

    ulong StartTime, StartMemory; // https://www.mql5.com/ru/forum/86386/page3256#comment_49538685

    BENCH(vector<double> Vector1 = GetCorr(Matrix, vPattern)) // https://www.mql5.com/ru/forum/86386/page3278#comment_4972561 4
    BENCH(vector<double> Vector2 = GetCorr(Array, Pattern))
    BENCH(vector<double> Vector3 = GetCorr(Array, Pattern, -1))
    
    Print(TOSTRING(IsEqual(Vector1, Vector2)));
    Print(TOSTRING(IsEqual(Vector3, Vector2)));
  }      
}


结果。

EX5: 4000 AVX Release.
TerminalInfoString(TERMINAL_CPU_NAME) = Intel Core i7-2700 K  @ 3.50 GHz 
TerminalInfoInteger(TERMINAL_CPU_CORES) = 8 
TerminalInfoString(TERMINAL_CPU_ARCHITECTURE) = AVX 
inRows = 300 inCols = 1000000 
vector<double> Vector1 = GetCorr(Matrix, vPattern) - 7158396 mcs, 8 MB
vector<double> Vector2 = GetCorr(Array, Pattern) - 364131 mcs, 8 MB
vector<double> Vector3 = GetCorr(Array, Pattern, -1) - 323935 mcs, 7 MB
IsEqual(Vector1, Vector2) = true 
IsEqual(Vector3, Vector2) = true 

现在只需 300 毫秒。

 
fxsaber #:

现在是 300 毫秒后。

当没有矩阵能做到这一点时。

inRows = 30000 inCols = 10000000 
vector<double> Vector2 = GetCorr(Array, Pattern) - 10567928 mcs, 76 MB
vector<double> Vector3 = GetCorr(Array, Pattern, -1) - 3006838 mcs, 77 MB

在一个 10M 的字符串中找到相似的 30K 字符串需要 3 秒钟。

 
fxsaber #:

当没有矩阵可以处理它时。

在一个 10M 的字符串中找到相似的 30K 字符串需要三秒钟。

非常酷,但同样没用。
这是 fft() 的例子吗?
 
mytarmailS #:
这是一个使用 fft() 的示例吗?

300/1M 不是 fft,30K/10M 才是 fft。

 
fxsaber #:

当没有矩阵可以处理它时。

在一个 10M 的字符串中找到长度为 30K 的相似字符串需要 3 秒钟。

令人印象深刻的结果

 

我从 2010 年到 2023 年抽取了一个样本(4.7 万行),按时间顺序分成 3 部分,并决定看看如果我们交换这些部分会发生什么。

子样本的大小为:培训 - 60%,测试 - 20%,考试 - 20%。

我做了这些组合(-1)--这是标准顺序--时间顺序。每个子样本都有自己的颜色。


对每组样本使用不同的 Seed 训练了 101 个模型,结果如下


所有指标都是标准的,可以看出,很难确定模型的平均利润(AVR 利润),以及在未参与训练的最后一个样本上利润超过 3000 点的模型的百分比。

也许应该减少训练样本中 -1 和 0 变体的相对成功率?总的来说,Recall 似乎对此有所反应。

您认为,在我们的案例中,这种组合的结果是否应该具有可比性?还是说数据已经无法挽回地过时了?