简体   繁体   English

确定字符串组合MQL4频率的算法

[英]Algorith that determinates frequency of string combinations MQL4

I have csv file like this: 我有这样的csv文件:

1392249600;EUR;CHF;USD;JPY;GBP
1392163200;GBP;JPY;USD;CHF;EUR
1392076800;GBP;CHF;EUR;JPY;USD
1391990400;JPY;USD;EUR;CHF;GBP
1391904000;GBP;EUR;CHF;USD;JPY
1391731200;GBP;EUR;CHF;JPY;USD
1391644800;EUR;CHF;USD;JPY;GBP
1391558400;JPY;USD;EUR;CHF;GBP

There can be over 15 000 rows in that file. 该文件中可能有超过15000行。 I am trying to write code that could do such thing: 我正在尝试编写可以执行此操作的代码:

1.Takes first row saves it as parent. 1.将第一行保存为父行。 Then takes next 3 days as that childs. 然后需要接下来的3天作为那个孩子。

2.Counts how often and which combination off childs with that parent are inside this file. 2.计算文件中与该父级的子级关联的频率和组合。

3.It creates something like summary for that so I could read todays combination and script shows the only the most frequent child combinations for next 3 days. 3.它为此创建了类似摘要的内容,因此我可以阅读今天的组合,并且脚本显示接下来三天内唯一最频繁的子组合。

I don't have mathematical thinking so I have big problems to find solution myself. 我没有数学思维,所以我自己遇到很多难题。

What I think first I need script that generates all posible combinations of these colums made of EUR,CHF,USD,JPY,GBP so there is posible 5*4*3*2*1 = 120 combinations. 我首先想到的是我需要生成由EUR,CHF,USD,JPY,GBP构成的所有列的所有可能组合的脚本,所以可能的5 * 4 * 3 * 2 * 1 = 120个组合。 Because they cant repeat in single row. 因为它们不能在单行中重复。

It will be like this. 会是这样。

First parent will be combination from first row like this: EUR;CHF;USD;JPY;GBP 第一父级将是第一行的组合,例如:EUR; CHF; USD; JPY; GBP

Then 3 childs would be
  GBP;JPY;USD;CHF;EUR 
  GBP;CHF;EUR;JPY;USD
  JPY;USD;EUR;CHF;GBP

It saves this combination off parent and child elements. 它将这种组合保存在父元素和子元素之外。 Then again it starts from begining of the file, but moves one row below(like iteration +1). 然后,它再次从文件开头开始,但向下移动了一行(如迭代+1)。 then next all childs would be 然后所有的孩子

 GBP;CHF;EUR;JPY;USD
   JPY;USD;EUR;CHF;GBP
   GBP;EUR;CHF;USD;JPY

And again it saves these combinations for counting and make some frequency results. 再一次将这些组合保存起来进行计数并得出一些频率结果。 And this cycle repeats for all rows on csv file. 并且此循环对csv文件中的所有行重复。

Is there maybe some tips I should consider how to create this type of programm ? 我是否应该考虑一些技巧来创建这种类型的程序?

Any tip would be great ! 任何提示都很棒!

Thank You Very Much! 非常感谢你! BB BB

Can you please clarify whether first value in a row in your file is date/time? 您能否说明文件中一行的第一个值是日期/时间? 1392249600;EUR;CHF;USD;JPY;GBP 1392249600; EUR; CHF; USD; JPY; GBP

If yes, are you expecting that there will total 4 rows with the same date/time? 如果是,您是否希望总共4行具有相同的日期/时间?

Or else you just need to go sequentially and use Line-1 as parent and then Line-2, Line-3, Line-4 as child and goes on... so that Line-5 becomes parent again? 否则,您只需要按顺序进行操作,并以Line-1作为父级,然后将Line-2,Line-3,Line-4用作子级,然后继续...以便Line-5再次成为父级?

To check whether country code is equivalent or not, you can use below kind of code. 要检查国家代码是否等效,可以使用以下代码。 I am not 100% sure about your requirement, please correct me if you think this is not what you are looking for and I will try to answer you in other way: 我不确定您的要求100%,如果您认为这不是您要找的内容,请更正我,我将尝试通过其他方式回答您:

package com.collections;

public class CountryCodeComparison {
    public static void main(String[] args) {
        //Read every row and sequentially insert value in CountryCode object.
        //For ex. your row is: 1392163200;GBP;JPY;USD;CHF;EUR
        String s1 = "1392163200;GBP;JPY;USD;CHF;EUR";
        String [] array1 = s1.split(";");
        CountryCode  cc1 = new CountryCode(array1[1], array1[2], array1[1], array1[4], array1[5]);

        //For ex. your row is: 1392076800;GBP;CHF;EUR;JPY;USD
        String s2 = "1392076800;GBP;CHF;EUR;JPY;USD";
        String [] array2 = s2.split(";");
        CountryCode  cc2 = new CountryCode(array2[1], array2[2], array2[1], array2[4], array2[5]);

        if(cc1.equals(cc2)) {
            System.out.println("Both CountryCode objects are equal.");
        } else {
            System.out.println("Both CountryCode objects are NOT equal.");
        }
    }
}

class CountryCode {
    private String countryCode1;
    private String countryCode2;
    private String countryCode3;
    private String countryCode4;
    private String countryCode5;
    public CountryCode(String countryCode1, String countryCode2,
            String countryCode3, String countryCode4, String countryCode5) {
        this.countryCode1 = countryCode1;
        this.countryCode2 = countryCode2;
        this.countryCode3 = countryCode3;
        this.countryCode4 = countryCode4;
        this.countryCode5 = countryCode5;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((countryCode1 == null) ? 0 : countryCode1.hashCode());
        result = prime * result
                + ((countryCode2 == null) ? 0 : countryCode2.hashCode());
        result = prime * result
                + ((countryCode3 == null) ? 0 : countryCode3.hashCode());
        result = prime * result
                + ((countryCode4 == null) ? 0 : countryCode4.hashCode());
        result = prime * result
                + ((countryCode5 == null) ? 0 : countryCode5.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        CountryCode other = (CountryCode) obj;
        if (countryCode1 == null) {
            if (other.countryCode1 != null)
                return false;
        } else if (!countryCode1.equals(other.countryCode1))
            return false;
        if (countryCode2 == null) {
            if (other.countryCode2 != null)
                return false;
        } else if (!countryCode2.equals(other.countryCode2))
            return false;
        if (countryCode3 == null) {
            if (other.countryCode3 != null)
                return false;
        } else if (!countryCode3.equals(other.countryCode3))
            return false;
        if (countryCode4 == null) {
            if (other.countryCode4 != null)
                return false;
        } else if (!countryCode4.equals(other.countryCode4))
            return false;
        if (countryCode5 == null) {
            if (other.countryCode5 != null)
                return false;
        } else if (!countryCode5.equals(other.countryCode5))
            return false;
        return true;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM