欢迎光临散文网 会员登陆 & 注册

股票量化软件:赫兹量化中的矩阵和向量操作

2023-08-11 11:05 作者:大牛啊呢  | 我要投稿

矩阵和向量类型

简而言之,向量是一维的双精度型数组,而矩阵是二维的双精度型数组。 向量可以是垂直和水平的,然而,它们在 MQL5 中不分彼此。 矩阵可以表示为水平向量数组,其中第一个索引是行号,第二个索引是列号。

除了包含双精度型数据的“矩阵”和“向量”类型之外,还有四种类型可用于相关数据类型的操作:

  • matrixf — 包含浮点元素的矩阵

  • matrixc — 包含复数元素的矩阵

  • vectorf — 包含浮点元素的向量

  • vectorc — 包含复数元素的向量

在撰写本文时,matrixc 和 vectorc 类型的工作尚未完工,故尚无法在内置方法中使用这些类型。

模板函数支持 matrix<double>、matrix<float>、vector<double>、vector<float> 等表示法,替代对应的类型。

 vectorf       v_f1= {0, 1, 2, 3,};  vector<float> v_f2=v_f1;  Print("v_f2 = ", v_f2);  /*  v_f2 = [0,1,2,3]  */


创建和安装

矩阵和向量方法根据其用途划分为九大类。 有若干种方式能够声明和初始化矩阵和向量。

最简单的创建方法是不指定大小的声明,即不为数据分配内存。 在此,我们只编写数据类型和变量名:

 matrix         matrix_a;   // double type matrix  matrix<double> matrix_a1;  // another way to declare a double matrix, suitable for use in templates  matrix<float>  matrix_a3;  // float type matrix  vector         vector_a;   // double type vector  vector<double> vector_a1;  // another notation to create a double vector  vector<float>  vector_a3;  // float type vector

然后,您可以更改创建对象的大小,并用所需的数值填充它们。 它们还可用在内置矩阵方法中,由此获得计算结果。

矩阵或向量可以按指定的大小声明,同时分配内存,但数据不会初始化。 于此,在变量名称之后,在括号中指定大小:

 matrix         matrix_a(128,128);           // the parameters can be either constants  matrix<double> matrix_a1(InpRows,InpCols);  // or variables  matrix<float>  matrix_a3(InpRows,1);        // analogue of a vertical vector  vector         vector_a(256);  vector<double> vector_a1(InpSize);  vector<float>  vector_a3(InpSize+16);       // expression can be used as a parameter


股票量化软件:赫兹量化中的矩阵和向量操作的评论 (共 条)

分享到微博请遵守国家法律